2. jsp中
try {
String original_filename = "fileToOutput.xls";
String sRealPath = (String) original_filename;
//產生要存的excel
File file = new File(sRealPath);
//產生一檔案WritableWorkbook讓程式匯出
WritableWorkbook writableWorkBook = Workbook.createWorkbook(file);
//在檔案中開啟一新的sheet
WritableSheet writableSheet = writableWorkBook.createSheet("我是第一張sheet", 1);
//WritableSheet writableSheet2 = writableWorkBook.createSheet("我是第二張sheet", 2);
//設定寫入儲存格的字型大小
WritableFont chFont12w = new WritableFont(WritableFont.createFont("Times New Roman"), 12);
WritableCellFormat writableCellFormat = new WritableCellFormat(chFont12w);
//label中的(0,0)代表excel中的(A,0)
//label中的(1,0)代表excel中的(B,0)
//label中的(1,1)代表excel中的(B,1),以此類推
Label deptLabel = new Label(0, 0, "印出字串",writableCellFormat);
writableSheet.addCell(deptLabel);
//寫入EXCEL檔案
writableWorkBook.write();
//關閉檔案
writableWorkBook.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
沒有留言:
張貼留言