Advertisement
YChalk

Excel Writer

Feb 8th, 2022
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public static void excelWriter (String file){
  2.         try {
  3.             FileInputStream fileInputStream = new FileInputStream(file);
  4.             XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
  5.             XSSFSheet sheet = workbook.getSheetAt(0);
  6.  
  7.             for (int i = 0; i < letterCount[0].length; i++){
  8.  
  9.                 Row row = sheet.createRow(i+1);
  10.                 Cell cell = row.createCell(0);
  11.                 cell.setCellValue(letterCount[0][i]);
  12.                 for (int j = 0; j < letterCount.length; j++){
  13.                     cell = row.createCell(j+1);
  14.                     cell.setCellValue(letterCount[j][i]);
  15.                 }
  16.                 fileInputStream.close();
  17.  
  18.                 FileOutputStream fileOutputStream = new FileOutputStream(file);
  19.                 workbook.write(fileOutputStream);
  20.                 workbook.close();
  21.                 fileOutputStream.close();
  22.             }
  23.         } catch (Exception e){
  24.             System.out.println(e.getMessage());
  25.  
  26.         }
  27.     }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement