package test;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class JXLTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
OutputStream fout = new FileOutputStream("D:aaa.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fout);
WritableSheet ws = wwb.createSheet("sheet名", 0);
jxl.write.WritableCellFormat wcfFC_col = new jxl.write.WritableCellFormat();
wcfFC_col.setWrap(true);
wcfFC_col.setBackground(Colour.LIGHT_BLUE);
wcfFC_col.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.THIN);
WritableCellFormat colFormat = new WritableCellFormat(wcfFC_col);
Label colLable = new Label(0, 0, "单元格", colFormat);
ws.addCell(colLable);
wwb.write(); // 写入文件
wwb.close();
fout.close();
File fl = new File("d:/aaa.xls");
FileInputStream fis = new FileInputStream(fl);
FileOutputStream f = new FileOutputStream("d:/aaa.zip");
byte[] buf = new byte[1024];
int len;
BufferedOutputStream bos = new BufferedOutputStream(f);
ZipOutputStream out = new ZipOutputStream(f);
ZipEntry ze = new ZipEntry(fl.getName());// 这是压缩包名里的文件名
out.putNextEntry(ze);// 写入新的 ZIP 文件条目并将流定位到条目数据的开始处
while ((len = fis.read(buf)) != -1) {
out.write(buf, 0, len);
out.flush();
}
fis.close();
out.close();
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我这样测试没有问题单元格也有格式,但是为什么放到jboss系统中就有问题了?
作者: shandor
发布时间: 2010-06-18