apache-poi Simple Excel (XLSX) creation Basic excel


Example

    String fileName = "Fruit.xlsx"; 

    String sheetName = "Apples";

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet(sheetName) ;

    for (int r=0;r < 3; r++ )
    {
        XSSFRow row = sheet.createRow(r);

        //iterating c number of columns
        for (int c=0;c < 3; c++ )
        {
            XSSFCell cell = row.createCell(c);

            cell.setCellValue("Nice apple, in row: "+r+" and col: "+c);
        }
    }

    try(FileOutputStream fos = new FileOutputStream(fileName))
    {
        wb.write(fos);
    }