在Java中向Excel文件写入内容
减小字体增大字体作者:佚名来源:不详发布时间:2005-12-6
23:29:32
可随意转载,但请注明出处及作者
SonyMusic
2003.05.15
=====================================================================
=====
在Java中向Excel文件写入内容
四、导出数据到Excel文件中
下面的例子,设置了数字、日期的格式,还有字体,颜色等。
File tempFile=new File("d:/temp/output.xls");
WritableWorkbook workbook = Workbook.createWorkbook(tempFile); WritableSheet sheet = workbook.createSheet("TestCreateExcel", 0);
//一些临时变量,用于写到excel中
Label l=null;
jxl.write.Number n=null;
jxl.write.DateTime d=null;
//预定义的一些字体和格式,同一个Excel中最好不要有太多格式
WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLUE);
WritableCellFormat headerFormat = new WritableCellFormat (headerFont);
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.RED);
WritableCellFormat titleFormat = new WritableCellFormat (titleFont);
WritableFont detFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK);
WritableCellFormat detFormat = new WritableCellFormat (detFont); NumberFormat nf=new NumberFormat("0.00000"); //用于Number的格式
WritableCellFormat priceFormat = new WritableCellFormat (detFont, nf);