`
- 浏览:
188910 次
- 来自:
...
-
java 代码
- package chb.util;
-
- import java.io.File;
- import java.io.IOException;
-
- import jxl.Cell;
- import jxl.Sheet;
- import jxl.Workbook;
- import jxl.read.biff.BiffException;
- import jxl.write.Label;
- import jxl.write.WritableImage;
- import jxl.write.WritableSheet;
- import jxl.write.WritableWorkbook;
- import jxl.write.WriteException;
- import jxl.write.biff.RowsExceededException;
-
- public class ExcelUtils {
-
-
-
-
-
- public static String readExcel(File file){
- StringBuffer sb = new StringBuffer();
-
- Workbook wb = null;
- try {
-
- wb=Workbook.getWorkbook(file);
- } catch (BiffException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if(wb==null)
- return null;
-
-
- Sheet[] sheet = wb.getSheets();
-
- if(sheet!=null&&sheet.length>0){
-
- for(int i=0;i
-
- int rowNum = sheet[i].getRows();
- for(int j=0;j
-
- Cell[] cells = sheet[i].getRow(j);
- if(cells!=null&&cells.length>0){
-
- for(int k=0;k
-
- String cellValue = cells[k].getContents();
- sb.append(cellValue+"\t");
- }
- }
- sb.append("\r\n");
- }
- sb.append("\r\n");
- }
- }
-
- wb.close();
- return sb.toString();
- }
-
-
-
- public static void writeExcel(String fileName){
- WritableWorkbook wwb = null;
- try {
-
- wwb = Workbook.createWorkbook(new File(fileName));
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(wwb!=null){
-
-
- WritableSheet ws = wwb.createSheet("sheet1", 0);
-
-
- for(int i=0;i<10;i++){
- for(int j=0;j<5;j++){
-
- Label labelC = new Label(j, i, "这是第"+(i+1)+"行,第"+(j+1)+"列");
- try {
-
- ws.addCell(labelC);
- } catch (RowsExceededException e) {
- e.printStackTrace();
- } catch (WriteException e) {
- e.printStackTrace();
- }
-
- }
- }
-
- try {
-
- wwb.write();
-
- wwb.close();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (WriteException e) {
- e.printStackTrace();
- }
- }
- }
-
-
-
-
-
- public static boolean searchKeyWord(File file,String keyWord){
- boolean res = false;
-
- Workbook wb = null;
- try {
-
- wb=Workbook.getWorkbook(file);
- } catch (BiffException e) {
- return res;
- } catch (IOException e) {
- return res;
- }
-
- if(wb==null)
- return res;
-
-
- Sheet[] sheet = wb.getSheets();
-
- boolean breakSheet = false;
-
- if(sheet!=null&&sheet.length>0){
-
- for(int i=0;i
- if(breakSheet)
- break;
-
-
- int rowNum = sheet[i].getRows();
-
- boolean breakRow = false;
-
- for(int j=0;j
- if(breakRow)
- break;
-
- Cell[] cells = sheet[i].getRow(j);
- if(cells!=null&&cells.length>0){
- boolean breakCell = false;
-
- for(int k=0;k
- if(breakCell)
- break;
-
- String cellValue = cells[k].getContents();
- if(cellValue==null)
- continue;
- if(cellValue.contains(keyWord)){
- res = true;
- breakCell = true;
- breakRow = true;
- breakSheet = true;
- }
- }
- }
- }
- }
- }
-
- wb.close();
-
- return res;
- }
-
-
-
-
-
-
-
-
- public static void insertImg(WritableSheet dataSheet, int col, int row, int width,
- int height, File imgFile){
- WritableImage img = new WritableImage(col, row, width, height, imgFile);
- dataSheet.addImage(img);
- }
-
-
- public static void main(String[] args) {
-
- try {
-
- WritableWorkbook workbook = Workbook.createWorkbook(new File("D:/test1.xls"));
-
- WritableSheet imgSheet = workbook.createSheet("Images",0);
-
- File imgFile = new File("D:/1.png");
-
- insertImg(imgSheet,0,1,6,6,imgFile);
- workbook.write();
- workbook.close();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (WriteException e) {
- e.printStackTrace();
- }
- }
-
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
jxl操作 jxl操作 jxl操作 jxl操作 jxl操作 jxl操作
jxl操作excel.pdf
利用jxl操作excel文件,提取exce文件数据生成txt文件。
JXL操作EXCEL 数据库导出EXCEL相关文件一些详细资料
JXL操作EXCEL的各个类的解析.doc
Java jxl操作Excel97-2003 可运行实例
jxl操作excel实例,jxl jar包下载 jxl操作excel实例,jxl jar包下载 jxl操作excel实例,jxl jar包下载
jxl操作excel,jxl操作读写excel2003.
使用jxl操作Excel,可以作为一个帮助文件
jxl操作excel说明以及jxl jar包
JXL操作excel 字体 颜色 设置单元格 详解
NULL 博文链接:https://8366.iteye.com/blog/468093
jxl操作excel文件示例,对于jxl的使用给出一个简单的示例,帮助大家快速入门
jxl操作excel模板jar包,用于导出特定excel模板
JXL操作EXCEL公式,颜色,表格,百分比,小数点等等等等
通过jxl操作excel,简单方便......................
Excel的生成方式其实很简单,主要包括几个大的类,首先最重要的几个类就是WritableWorkbook,这个类代表的就是一个Excel文档,使用过Excel文档的都应该知道Excel文档的组成,都是由一个一个的sheet组成的,那么这个...
jxl操作Excel说明,及API文档,编写jxl不用愁
java中jxl操作excel