excel 表头合并 和拆分的例子
来源:互联网 发布:软件开机自启动 编辑:程序博客网 时间:2024/06/18 09:50
自己整理了一个excel 表头合并 和拆分的例子
import java.io.File;import java.io.IOException;import jxl.Workbook;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableFont;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;import jxl.write.biff.RowsExceededException;public class Test { public static void main(String[] args) throws Exception { String path = "e:/test.xlsx"; writeExcel(path); } public static void writeExcel(String fileName) throws IOException, RowsExceededException, WriteException { // 构建一个工作薄 WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName)); if (workbook == null) { return; } // 获取第一个sheet WritableSheet sheet = workbook.createSheet("sheet1", 0); if (sheet == null) { return; } WritableFont bold = new WritableFont(WritableFont.createFont("微软雅黑"), 12, WritableFont.NO_BOLD); WritableCellFormat titleFormate = new WritableCellFormat(bold);// 生成一个单元格样式控制对象 titleFormate.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);// 设置边框 titleFormate.setAlignment(jxl.format.Alignment.CENTRE);// 单元格中的内容水平方向居中 titleFormate.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 单元格的内容垂直方向居中 // 创建表头 sheet.mergeCells(0, 0, 0, 1);// 单元格合并 sheet.addCell(new Label(0, 0, "时间", titleFormate)); sheet.mergeCells(1, 0, 4, 0); sheet.addCell(new Label(1, 0, "新增积分总数", titleFormate)); sheet.addCell(new Label(1, 1, "交易", titleFormate)); sheet.addCell(new Label(2, 1, "扫码", titleFormate)); sheet.addCell(new Label(3, 1, "爱互动", titleFormate)); sheet.addCell(new Label(4, 1, "合计", titleFormate)); sheet.mergeCells(5, 0, 5, 1); sheet.addCell(new Label(5, 0, "消费积分总数", titleFormate)); sheet.mergeCells(6, 0, 11, 0); sheet.addCell(new Label(6, 0, "剩余有效积分总数", titleFormate)); sheet.addCell(new Label(6, 1, "店铺会员", titleFormate)); sheet.addCell(new Label(7, 1, "中级会员", titleFormate)); sheet.addCell(new Label(8, 1, "高级会员", titleFormate)); sheet.addCell(new Label(9, 1, "VIP会员", titleFormate)); sheet.addCell(new Label(10, 1, "SVIP会员", titleFormate)); sheet.addCell(new Label(11, 1, "合计", titleFormate)); sheet.mergeCells(12, 0, 12, 1); sheet.addCell(new Label(12, 0, "过期积分数", titleFormate)); WritableCellFormat bodyFormate = new WritableCellFormat();// 生成一个单元格样式控制对象 bodyFormate.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);// 设置边框 for(int i = 2; i <= 12; i++){ sheet.addCell(new Label(0, i, "2017-04-08", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); sheet.addCell(new Label(0, i, "0", bodyFormate)); } // 设置单元格的宽度 sheet.setColumnView(5, 20); sheet.setColumnView(6, 11); sheet.setColumnView(7, 11); sheet.setColumnView(8, 11); sheet.setColumnView(9, 11); sheet.setColumnView(10, 11); sheet.setColumnView(11, 11); sheet.setColumnView(12, 20); // 从内存中写入文件中 workbook.write(); // 关闭资源,释放内存 workbook.close(); }}
阅读全文
0 0
- excel 表头合并 和拆分的例子
- excel的生成与表头的合并的一个例子
- 数组的合并,拆分,分解和接合
- 数组的合并,拆分,分解和接合
- Excel 2007单元格及内容的合并、拆分_C#教程
- Excel 2007单元格及内容的合并、拆分_C#教程
- 整数合并和拆分
- 合并GridView的表头
- JTable的表头合并
- JTable的表头合并
- JTable的表头合并
- 合并和拆分map,合并和拆分list,应用于把表格的两行并排显示
- excel拆分单元格,拆分后每个单元格显示合并单元格的值
- jqGrid设置三级表头和表头合并
- C# WinForm开发系列 - DataGridView 表头合并拆分单元格
- C#导出Excel——多表头、表头跨行跨列合并
- poi导出Excel报表多表头双层表头、合并单元格
- numpy和pandas中数组的合并和拆分
- 从键盘输入一个整数(1-9),打印出对应的乘法表(Java)
- HDU 1875 畅通工程再续 基础最小生成树★
- wordpress 使用bootstrap样式
- 我所理解的 PHP Trait
- 如何备份和恢复oracle数据库
- excel 表头合并 和拆分的例子
- rocketMq监控平台rocketmq-console搭建
- eclipse阅读源码小窍门
- 爬虫那些事-爬虫设计思路
- Java 接口
- 添加CDH 5 Maven Repository
- darknet安装与使用
- Spring 小结
- 二进制、八进制、十六进制转换