日期:2014-05-20  浏览次数:20858 次

用jxl导出excel为什么把我自己在模板中设置的格式冲掉了
List   list   =   (List)   request.getSession().getAttribute( "list ");
//读取自己模板
Workbook   workbook   =   Workbook.getWorkbook(moFile);
WritableWorkbook   copy   =   Workbook.createWorkbook(response.getOutputStream(),   workbook);
WritableSheet   sheet   =   copy.getSheet(0);
String   ccol   =   request.getParameter( "col ");
String   crow   =   request.getParameter( "row ");

//   依次处理各行
for   (int   i   =   0;   i   <   list.size();   i++)
{
List   listrow   =   (List)   list.get(i);
int   col   =   Integer.parseInt(ccol);  
//   起始列
int   row   =   i+Integer.parseInt(crow);  
//   起始行
//   依次处理各列
for   (int   j   =   0;   j   <   listrow.size();   j++)
{
WritableCell   cellb   =   sheet.getWritableCell(col   +   j   -   1,row);
if   (cellb.getType()   ==   CellType.EMPTY)
{
String   labelvalue   =   (String)   listrow.get(j);
if   (labelvalue   ==   null)
labelvalue   =   "0 ";
log.info((col   +   j   -   1)+ "         "+row);
Label   label   =   new   Label(col   +   j   -   1,   row,labelvalue);
sheet.addCell(label);
}}}

把我自己在模板中设置的格式冲掉了,我画的表格线也没有了~~~~

------解决方案--------------------
你的程序有点没看懂,我这里有一个程序,希望能对你有点帮助
try
{
Workbook book= Workbook.getWorkbook(new File( "test.xls "));
//获得第一个工作表对象
Sheet sheet=book.getSheet(0);
//得到第一列第三行的单元格
WritableWorkbook book1=
Workbook.createWorkbook(new File( "write.xls "));
WritableSheet sheet1=book1.createSheet( "B-2 ",0);
int rowCount=sheet.getRows()-3;
//System.out.println( "rowcount= "+rowCount);
for(int i=0;i <rowCount;i++)
{
sheet1.setRowView(i*12+1,800);
sheet1.mergeCells(0,i*12+1,16,i*12+1);
WritableFont wf = new WritableFont(WritableFont.COURIER,18,WritableFont.BOLD,false);
WritableCellFormat wcf = new WritableCellFormat(wf);
//WritableFont wf1 = new WritableFont(WritableFont.COURIER,10,WritableFont.BOLD,false);
//WritableCellFormat wcf1 = new WritableCellFormat(wf1);
wcf.setAlignment(jxl.format.Alignment.CENTRE);
Label head=new Label(0,i*12+1, "儿童少年户卡 ",wcf);
sheet1.addCell(head);
sheet1.mergeCells(0,i*12+2,1,i*12+2);
Label gtz=new Label(0,i*12+2, "高台子 ");
sheet1.addCell(gtz);
Label xz=new Label(2,i*12+2, "乡(镇) ");
sheet1.addCell(xz);
sheet1.mergeCells(4,i*12+2,11,i*12+2);
Label ycg=new Label(4,i*12+2, "洋草沟村 ");//可更改
sheet1.addCell(ycg);
//Label cun=new Label(6,i*12+2, "村 ");
//sheet1.addCell(cun);
//sheet1.mergeCells(7,i*12+2,11,i*12+2);
Label tkrq=new Label(12,i*12+2, "填卡日期: ");
sheet1.addCell(tkrq);
Label year=new Label(13,i*12+2, "2006 年 ");
sheet1.addCell(year);
Label month=new Label(14,i*12+2, "9 月 ");
sheet1.addCell(month);
sheet1.mergeCells(15,i*12+2,16,i*12+2);
Label day=new Label(15,i*12+2, "日 ");
sheet1.addCell(day);
//sheet1.setRowView(i*12+3,800);