Java - Tworzenie plików excel *.xls
W przykładzie wykorzystana została biblioteka Apache POI -
download
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...
Workbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("C:\\sample.xlsx");
Sheet sh = wb.createSheet("newSheet1");
sh.createRow(0);
sh.getRow(0).createCell(0).setCellValue("Hours");
sh.getRow(0).createCell(1).setCellValue("Sunday");
sh.getRow(0).createCell(2).setCellValue("Monday");
sh.getRow(0).createCell(3).setCellValue("Tuesday");
sh.getRow(0).createCell(4).setCellValue("Wednesday");
sh.getRow(0).createCell(5).setCellValue("Thursday");
sh.getRow(0).createCell(6).setCellValue("Friday");
sh.getRow(0).createCell(7).setCellValue("Saturday");
for(int k = 1; k<25;k++){
sh.createRow(k);
sh.getRow(k).createCell(0).setCellValue(k-1);
}
for (int i = 0; i <> for(int j = 0; j<24;j++){
sh.getRow(j+1).createCell(i+1).setCellValue("Row "+j+" Cell "+i);
}
wb.write(fos);
fos.close();
0 komentarze: