JXL 生成EXCEL文件格式说明
2013-03-26 13:41
495 查看
JXL 生成EXCEL文件格式说明
1、 合并单元格
WritableSheet.mergeCells(int m,int n,int p,int q);
作用是从(m,n)到(p,q)的单元格全部合并,比如:
WritableSheet sheet=book.createSheet(“第一页”,0);
//合并第一列第一行到第六列第一行的所有单元格
sheet.mergeCells(0,0,5,0);
合并既可以是横向的,也可以是纵向的。合并后的单元格不能再次进行合并,否则会触发异常。
2、 行高和列宽
WritableSheet.setRowView(int i,int height);
作用是指定第i+1行的高度,比如:
//将第一行的高度设为200
sheet.setRowView(0,200);
WritableSheet.setColumnView(int i,int width);
作用是指定第i+1列的宽度,比如:
//将第一列的宽度设为30
sheet.setColumnView(0,30);
1、 合并单元格
WritableSheet.mergeCells(int m,int n,int p,int q);
作用是从(m,n)到(p,q)的单元格全部合并,比如:
WritableSheet sheet=book.createSheet(“第一页”,0);
//合并第一列第一行到第六列第一行的所有单元格
sheet.mergeCells(0,0,5,0);
合并既可以是横向的,也可以是纵向的。合并后的单元格不能再次进行合并,否则会触发异常。
2、 行高和列宽
WritableSheet.setRowView(int i,int height);
作用是指定第i+1行的高度,比如:
//将第一行的高度设为200
sheet.setRowView(0,200);
WritableSheet.setColumnView(int i,int width);
作用是指定第i+1列的宽度,比如:
//将第一列的宽度设为30
sheet.setColumnView(0,30);
//jxl public static String explorExcelAllProject() throws IOException, WriteException { Date today = new Date(); String filename = EIBProperties.getProperty("cordys.home", "") + System.getProperty("file.separator") + "Web" + System.getProperty("file.separator") + "upladFiles" + System.getProperty("file.separator") + "Bidding_Document" + System.getProperty("file.separator") + "ExplorExcelAllProject_" // w + today.getTime() + ".xls"; String url = "/cordys" + System.getProperty("file.separator") + "upladFiles" + System.getProperty("file.separator") + "Bidding_Document" + System.getProperty("file.separator") + "ExplorExcelAllProject_" + today.getTime() + ".xls"; // w File excelFile = new File(filename); if (!excelFile.exists()) { excelFile.createNewFile(); } FileOutputStream os = new FileOutputStream(excelFile); String message = "中国商飞设计研发中心招标工作一览表"; WritableWorkbook wwb = Workbook.createWorkbook(os); //设置表头 WritableSheet ws = wwb.createSheet(message, 0); //设置行高 ws.setRowView(行号,高度(200=10)); //设置字体 WritableCellFormat wcf = new WritableCellFormat(); wcf.setAlignment(jxl.format.Alignment.CENTRE); wcf.setFont(new jxl.write.WritableFont(WritableFont.TIMES, 16, WritableFont.BOLD, true)); wcf.setBorder(Border.TOP, BorderLineStyle.THICK, Colour.BLACK); wcf.setBorder(Border.LEFT, BorderLineStyle.THICK, Colour.BLACK); wcf.setBorder(Border.RIGHT, BorderLineStyle.THICK, Colour.BLACK); //wcf.setBorder(Border.BOTTOM, BorderLineStyle.THICK, Colour.BLACK); //设置列数 ws.mergeCells(0, 0, 20, 0); // 2012/7/24 7/7 ws.addCell(new Label(0, 0, message, wcf)); //表头设置 WritableCellFormat wcf1 = new WritableCellFormat(); wcf1.setFont(new jxl.write.WritableFont(WritableFont.TIMES, 10,WritableFont.BOLD, false)); wcf1.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); //wcf1.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK); wcf1.setAlignment(jxl.format.Alignment.CENTRE); //增加表头设置多少列 ws.addCell(new Label(0, 1, "序号", wcf1)); ws.addCell(new Label(1, 1, "项目名称", wcf1)); ws.addCell(new Label(2, 1, "批复概算(万元)", wcf1)); ws.addCell(new Label(3, 1, "批复面积", wcf1)); ws.addCell(new Label(4, 1, "招标编号", wcf1)); //小计和总计样式 WritableCellFormat wcf5 = new WritableCellFormat(); //设置字体红色加粗无下划线 wcf5.setFont(new jxl.write.WritableFont(WritableFont.TIMES, 10,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.RED)); wcf5.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); wcf5.setBackground(Colour.YELLOW); //设置列宽 ws.setColumnView(0, 5); ws.setColumnView(1, 15); ws.setColumnView(2, 17); ws.setColumnView(3, 12); ws.setColumnView(4, 12); wwb.write(); wwb.close(); os.close(); return url; }
相关文章推荐
- Android解析及生成Excel文件(JXL)(xls格式)
- 将DataGrid内容生成标准的Excel格式文件
- JXL包大解析;Java程序生成excel文件和解析excel文件内容
- JXL生成的excel文件+JAVA文件下载功能
- 关于双通输入法管理里面要导入的文件以及生成文件的格式说明
- 利用jsp生成excel格式文件
- JAVA JXL -----excel文件生成、在线打开和下载
- JXL生成对应的Excel文件(报表统计)
- JXL包大解析;Java程序生成excel文件和解析excel文件内容
- NPOI 菜鸟实践行之根据指定的模板生成Excel 2003格式的文件 (一)
- 使用jxl动态生成excel文件并提示下载
- 生成Excel *.xls 生成 xls的格式与文件扩展名指定的格式不一致
- Java通过jxl解析Excel文件入库,及日期格式处理方式 (附源代码)
- C# 生成Excel文件及表格内容格式编辑 excel模板流
- Java生成csv文件时,数字格式为“0001”,用excel打开时,变为“1”的解决方法
- c#读取生成excel表格文件xls、xlsx格式文件
- 将DataGrid内容生成标准的Excel格式文件
- 关于weblogic下用jxl.jar包用的excel导出报,文件错误,某些数字格式可能丢失
- jxl生成文件,excel打开显示:office已检测此文件存在问题
- 使用JAVA通过JXL(JExcel)动态生成Excel文件 转载至台湾某博客