資料列印到excel,支援多sheet頁
阿新 • • 發佈:2018-11-05
public class excelDemo {
public static void main(String[] args) {
try{
XSSFWorkbook wb = new XSSFWorkbook();
String s="ss";
String t="tt";
ArrayList array=new ArrayList();
array.add(s);
array.add(t);
XSSFSheet sheet;
for (int i = 0; i < 2; i++) {
sheet = wb.createSheet(array.get(i).toString());
for (int j = 0; j < 2; j++) {
XSSFRow row = sheet.createRow(j + 1);
row.createCell(0).setCellValue("ss");
}
}
//建立檔案流
OutputStream stream = new FileOutputStream("G://12121.xlsx");
//寫入資料
wb.write(stream);
//關閉檔案流
stream.close();
}catch(Exception e) {
}
}
}
public static void main(String[] args) {
try{
XSSFWorkbook wb = new XSSFWorkbook();
String s="ss";
String t="tt";
ArrayList array=new ArrayList();
array.add(s);
array.add(t);
XSSFSheet sheet;
for (int i = 0; i < 2; i++) {
sheet = wb.createSheet(array.get(i).toString());
for (int j = 0; j < 2; j++) {
XSSFRow row = sheet.createRow(j + 1);
row.createCell(0).setCellValue("ss");
}
}
//建立檔案流
OutputStream stream = new FileOutputStream("G://12121.xlsx");
//寫入資料
wb.write(stream);
//關閉檔案流
stream.close();
}catch(Exception e) {
}
}
}