Add Data in Cells

Aspose.Cells - Add Data in Cells

Aspose.Cells provides a class, Workbook, that represents a Microsoft Excel file. Workbook class contains a WorksheetCollection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides a Cellscollection. Each item in the Cells collection represents an object of the Cell class.


 //Instantiating a Workbook object

Workbook workbook = new Workbook();

//Accessing the added worksheet in the Excel file

Worksheet worksheet = workbook.getWorksheets().get(0);

Cells cells = worksheet.getCells();

cells.get("A1").setValue("Hello World"); //Adding a string value to the cell

cells.get("A2").setValue(20.5); //Adding a double value to the cell

cells.get("A3").setValue(15); //Adding an integer  value to the cell

cells.get("A4").setValue(true); //Adding a boolean value to the cell

Cell cell = cells.get("A5"); //Adding a date/time value to the cell


//Setting the display format of the date

Style style = cell.getStyle();


cell.setStyle(style); + "DataInCells_Aspose.xls"); //Saving the Excel file

Apache POI SS - HSSF XSSF - Add Data in Cells

In Apache POI SS row.createCell(1).setCellValue can be used to add data in cells.


 Workbook wb = new HSSFWorkbook();

CreationHelper createHelper = wb.getCreationHelper();

Sheet sheet = wb.createSheet("new sheet");

// Create a row and put some cells in it. Rows are 0 based.

Row row = sheet.createRow((short)0);

// Create a cell and put a value in it.

Cell cell = row.createCell(0);


// Or do it on one line.



createHelper.createRichTextString("This is a string"));


// Write the output to a file

FileOutputStream fileOut = new FileOutputStream(dataDir + "DataInCells_Apache.xls");



Download Running Code

Download Sample Code