Create New Spreadsheet in xlsx4j

Aspose.Cells - Create New Spreadsheet

Workbook class is available for simple use.


 //Instantiating a Workbook object

Workbook workbook = new Workbook();

//Adding a new worksheet to the Workbook object

WorksheetCollection worksheets = workbook.getWorksheets();

Worksheet worksheet = worksheets.add("My Worksheet");

Cells cells = worksheet.getCells();

//Adding some value to cell

Cell cell = cells.get("A1");

cell.setValue("This is Aspose test of fonts!");

//Saving the Excel file + "newWorksheet_Aspose.xls");

xlsx4j - Create New Spreadsheet

Below sample shows how new spreadsheet can be created while using xlsx4j.


 public static void main(String[] args) throws Exception {

    String outputfilepath = dataDir + "newWorksheet_Xlsx4j.xlsx";

    SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();

    WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);


    SaveToZipFile saver = new SaveToZipFile(pkg);;

    System.out.println("\n\n done .. " + outputfilepath);


private static void addContent(WorksheetPart sheet) {

    // Minimal content already present

    SheetData sheetData = sheet.getJaxbElement().getSheetData();

    // Now add

    Row row = Context.getsmlObjectFactory().createRow();

    Cell cell = Context.getsmlObjectFactory().createCell();



    row.getC().add(createCell("hello world!"));




    // Note: if you are trying to add characters, not a number,

    // the easiest approach is to use inline strings (as opposed to the shared string table).

    // See

    // and


private static Cell createCell(String content) {

    Cell cell = Context.getsmlObjectFactory().createCell();

    CTXstringWhitespace ctx = Context.getsmlObjectFactory().createCTXstringWhitespace();


    CTRst ctrst = new CTRst();



    cell.setIs(ctrst); // add ctrst as inline string

    return cell;


Download Running Code

Download Sample Code