jxl导出报表时,怎样合并单元格? 我把一列数据导出,在一个循环内如何控制单元格的合并啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 问题不是很明白啊。我给你个合并单元格的WritableFont wf_value = new jxl.write.WritableFont(WritableFont.createFont("宋体"), 9, WritableFont.NO_BOLD);// 表格数据样式WritableCellFormat wcf_value = new WritableCellFormat(wf_value);wcf_value.setAlignment(jxl.format.Alignment.CENTRE);wcf_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);wcf_value.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);wcf_value.setWrap(true);int startRowNum=0;//起始行 int startColNum=0;//起始列 ws.addCell(new Label(startColNum,startRowNum,"项目汇总",wcf_value));ws.mergeCells(startColNum,startRowNum, startColNum+14,startRowNum);startRowNum++;看下这段代码。是我项目里面拷贝出来的自己调节下下面方法的参数值就知道了ws.mergeCells(startColNum,startRowNum, startColNum+14,startRowNum); package Test;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.math.BigDecimal;import jxl.Workbook;import jxl.format.Alignment;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableFont;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;public class Test { public static void main(String[] args) throws WriteException, IOException { WritableWorkbook wb = null; try { WritableFont wf_key = new jxl.write.WritableFont(WritableFont .createFont("宋体"), 12, WritableFont.BOLD); WritableFont wf_value = new jxl.write.WritableFont(WritableFont .createFont("宋体"), 9, WritableFont.NO_BOLD); WritableFont wvf_value = new jxl.write.WritableFont(WritableFont .createFont("宋体"), 9, WritableFont.BOLD); // 表格数据样式 WritableCellFormat wcf_value = new WritableCellFormat(wf_value); wcf_value.setAlignment(jxl.format.Alignment.CENTRE); wcf_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); wcf_value.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); wcf_value.setWrap(true); // 表格数据样式 WritableCellFormat wcfNum_value = new WritableCellFormat(wf_value); wcfNum_value.setAlignment(jxl.format.Alignment.RIGHT); wcfNum_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); wcfNum_value.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); wcfNum_value.setWrap(true); WritableCellFormat wc_value = new WritableCellFormat(wvf_value); wc_value.setAlignment(jxl.format.Alignment.CENTRE); wc_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); wc_value.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); wc_value.setWrap(true); WritableCellFormat wvc_value = new WritableCellFormat(wvf_value); wvc_value.setAlignment(jxl.format.Alignment.LEFT); wvc_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); wvc_value.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); wvc_value.setWrap(true); // 表头样式 WritableCellFormat wcf_key = new WritableCellFormat(wf_key); wcf_key.setAlignment(jxl.format.Alignment.CENTRE); wcf_key.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); wcf_key.setWrap(true); // 表名样式 WritableCellFormat wcf_name_right = new WritableCellFormat(wf_key); wcf_name_right.setAlignment(Alignment.RIGHT); WritableCellFormat wcf_name_center = new WritableCellFormat(wf_key); wcf_name_center.setAlignment(Alignment.CENTRE); WritableCellFormat wcf_name_left = new WritableCellFormat(wf_key); wcf_name_left.setAlignment(Alignment.LEFT); // 页名称样式 WritableFont wf_title = new jxl.write.WritableFont(WritableFont .createFont("微软雅黑"), 14, WritableFont.BOLD); WritableCellFormat wcf_title = new WritableCellFormat(wf_title); wcf_title.setAlignment(Alignment.CENTRE); OutputStream out =new FileOutputStream("C:\\a.xls"); wb = Workbook.createWorkbook(out);//这里的out是传过来的,是response.getOutputStream()得到的。这里我构造一个 WritableSheet ws = wb.createSheet("经销表", 0); ws.setColumnView(0,10); ws.setColumnView(1,25); ws.setColumnView(2,20); ws.setColumnView(3,8); ws.setColumnView(4,8); ws.setColumnView(5,25); ws.setColumnView(6,11); ws.setColumnView(7,11); ws.setColumnView(8,11); ws.setColumnView(9,11); ws.setColumnView(10,11); ws.setColumnView(11,11); ws.setColumnView(12,30); int startRowNum=0;//起始行 int startColNum=0;//起始列 ws.addCell(new Label(startColNum,startRowNum,"项目名称:",wvc_value)); ws.mergeCells(startColNum,startRowNum, startColNum+5,startRowNum+2); wb.write(); } catch (Exception e) { e.printStackTrace(); } finally { if (wb != null) { wb.close(); wb = null; } } }}拿这个试试你就明白了 ws.mergeCells(0, rows,objInfos.size()-1, 0); //参数为其实列,其实行,结束列,结束行 如何获取struts2标签内s:property的值 java的web在线聊功能,无刷新,不需要数据库 关与applet的显示问题,谢!急,相当急,谢!!!快疯了. [jsp]常见问题--Java 开发中遇到的乱码问题 jsp中如何用session写记数 问:如何根据数组的某个字段冒泡排序?? 请帮忙,没用过applet 关于mysql的装载驱动问题 请问java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/sql/Result是什么错误! 怎样建立JSP虚拟目录 smtp发送邮件的问题 报表 jasperreport+ireport
WritableFont wf_value = new jxl.write.WritableFont(WritableFont
.createFont("宋体"), 9, WritableFont.NO_BOLD);// 表格数据样式
WritableCellFormat wcf_value = new WritableCellFormat(wf_value);
wcf_value.setAlignment(jxl.format.Alignment.CENTRE);
wcf_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wcf_value.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wcf_value.setWrap(true);int startRowNum=0;//起始行
int startColNum=0;//起始列
ws.addCell(new Label(startColNum,startRowNum,"项目汇总",wcf_value));
ws.mergeCells(startColNum,startRowNum, startColNum+14,startRowNum);
startRowNum++;看下这段代码。是我项目里面拷贝出来的
自己调节下下面方法的参数值就知道了ws.mergeCells(startColNum,startRowNum, startColNum+14,startRowNum);
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;import jxl.Workbook;
import jxl.format.Alignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;public class Test { public static void main(String[] args) throws WriteException, IOException {
WritableWorkbook wb = null;
try {
WritableFont wf_key = new jxl.write.WritableFont(WritableFont
.createFont("宋体"), 12, WritableFont.BOLD);
WritableFont wf_value = new jxl.write.WritableFont(WritableFont
.createFont("宋体"), 9, WritableFont.NO_BOLD);
WritableFont wvf_value = new jxl.write.WritableFont(WritableFont
.createFont("宋体"), 9, WritableFont.BOLD);
// 表格数据样式
WritableCellFormat wcf_value = new WritableCellFormat(wf_value);
wcf_value.setAlignment(jxl.format.Alignment.CENTRE);
wcf_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wcf_value.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wcf_value.setWrap(true);
// 表格数据样式
WritableCellFormat wcfNum_value = new WritableCellFormat(wf_value);
wcfNum_value.setAlignment(jxl.format.Alignment.RIGHT);
wcfNum_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wcfNum_value.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wcfNum_value.setWrap(true);
WritableCellFormat wc_value = new WritableCellFormat(wvf_value);
wc_value.setAlignment(jxl.format.Alignment.CENTRE);
wc_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wc_value.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wc_value.setWrap(true);
WritableCellFormat wvc_value = new WritableCellFormat(wvf_value);
wvc_value.setAlignment(jxl.format.Alignment.LEFT);
wvc_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wvc_value.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wvc_value.setWrap(true); // 表头样式
WritableCellFormat wcf_key = new WritableCellFormat(wf_key);
wcf_key.setAlignment(jxl.format.Alignment.CENTRE);
wcf_key.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
wcf_key.setWrap(true); // 表名样式
WritableCellFormat wcf_name_right = new WritableCellFormat(wf_key);
wcf_name_right.setAlignment(Alignment.RIGHT);
WritableCellFormat wcf_name_center = new WritableCellFormat(wf_key);
wcf_name_center.setAlignment(Alignment.CENTRE);
WritableCellFormat wcf_name_left = new WritableCellFormat(wf_key);
wcf_name_left.setAlignment(Alignment.LEFT); // 页名称样式
WritableFont wf_title = new jxl.write.WritableFont(WritableFont
.createFont("微软雅黑"), 14, WritableFont.BOLD);
WritableCellFormat wcf_title = new WritableCellFormat(wf_title);
wcf_title.setAlignment(Alignment.CENTRE);
OutputStream out =new FileOutputStream("C:\\a.xls");
wb = Workbook.createWorkbook(out);//这里的out是传过来的,是response.getOutputStream()得到的。这里我构造一个
WritableSheet ws = wb.createSheet("经销表", 0); ws.setColumnView(0,10);
ws.setColumnView(1,25);
ws.setColumnView(2,20);
ws.setColumnView(3,8);
ws.setColumnView(4,8);
ws.setColumnView(5,25);
ws.setColumnView(6,11);
ws.setColumnView(7,11);
ws.setColumnView(8,11);
ws.setColumnView(9,11);
ws.setColumnView(10,11);
ws.setColumnView(11,11);
ws.setColumnView(12,30);
int startRowNum=0;//起始行
int startColNum=0;//起始列
ws.addCell(new Label(startColNum,startRowNum,"项目名称:",wvc_value));
ws.mergeCells(startColNum,startRowNum, startColNum+5,startRowNum+2);
wb.write();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (wb != null) {
wb.close();
wb = null;
}
}
}
}
拿这个试试你就明白了