How to write data inside ExcelSheet ?

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

  public class CreateExcelSheet {

  public static void main(String[] args) throws IOException {
 
     //Creating OutputStream Object
    FileOutputStream fos = new FileOutputStream(new File(" File Path "));

    //Create Workbook object
    XSSFWorkbook wb = new XSSFWorkbook();

    //Creating Sheet with the name : firstSheet
    XSSFSheet firstSheet = wb.createSheet("firstSheet");

    //Creating first row inside firstSheet
    XSSFRow firstRow = firstSheet.createRow(0);

    //Creating first cell inside first row
    XSSFCell firstCell = firstRow.createCell(0);

    //Set cell value to UserName
    firstCell.setCellValue("UserName");

    //This statement will Commit everything inside the provided ExcelSheet
    wb.write(fos);

    System.out.println("Created");

    //Closing the opened ExcelSheet
    wb.close();

}

The Output will look like

Design a site like this with WordPress.com
Get started