ZzExcelCreator
Excel表格生成工具
项目地址:https://github.com/zhouzhuo810/ZzExcelCreator
(欢迎star!)
效果图:



最近做项目用到jxl.jar来生成Excel表格;
但是发现jxl源码都没有注释的,方法也没有说明,
虽然最后在网上找到了对应的方法。
不过这不是我的style,果断自己封装一下,添加注释。
下面介绍一下用法:
Gradle:
1
| compile 'me.zhouzhuo.zzexcelcreator:zz-excel-creator:1.0.0'
|
创建Excel文件和工作表
1 2 3 4 5
| ZzExcelCreator .getInstance() .createExcel(PATH, params[0]) .createSheet(params[1]) .close();
|
打开Excel文件和工作表
1 2 3 4 5 6
| ZzExcelCreator .getInstance() .openExcel(new File(PATH + fileName + ".xls")) .openSheet(0) ... ... .close();
|
设置单元格内容格式:
1 2 3 4 5 6 7 8
| WritableCellFormat format = ZzFormatCreator .getInstance() .createCellFont(WritableFont.ARIAL) .setAlignment(Alignment.CENTRE, VerticalAlignment.CENTRE) .setFontSize(14) .setFontColor(Colour.ROSE) .getCellFormat();
|
设置行高、列宽和写入字符串或数字
1 2 3 4 5 6 7 8 9
| ZzExcelCreator .getInstance() .openExcel(new File(PATH + fileName + ".xls")) .openSheet(0) .setColumnWidth(Integer.parseInt(col), 25) .setRowHeight(Integer.parseInt(row), 400) .fillContent(Integer.parseInt(col), Integer.parseInt(row), str, format) .fillNumber(Integer.parseInt(col), Integer.parseInt(row), Double.parseDouble(str), format) .close();
|
最后就是,这些操作最好在子线程操作。