apache-poi

Simple Excel (XLSX) creation

Basic excel

    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);
    }

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow