当前位置: 代码迷 >> Java Web开发 >> jxl导出报表时,怎样合并单元格?解决办法
  详细解决方案

jxl导出报表时,怎样合并单元格?解决办法

热度:8233   发布时间:2013-02-25 21:18:37.0
jxl导出报表时,怎样合并单元格?
我把一列数据导出,在一个循环内如何控制单元格的合并啊?

------解决方案--------------------------------------------------------
问题不是很明白啊。我给你个合并单元格的
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);
  相关解决方案