Free Support Forum - aspose.com

How to create a new excel file?

Hi there,

I'm evaluating the ASPOSE.Cell. It looks good. But it seems it only have the functionality to open an existing excel file and save it, is there any way to create a new excel file?

Please advise! Thanks!

Hi,

Thank you for considering Aspose.

Yes, Aspose.Cells provides the functionality to create different format excel files. Please see the sample code to see how you can create an excel file from scratch.

Sample Code:

//Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();

//Note when you create a new workbook, a default worksheet
//"Sheet1" is added (by default) to the workbook. 
//Access the first worksheet "Sheet1" in the book.
Worksheet sheet = wb.Worksheets[0];

//Access the "A1" cell in the sheet.
Cell cell = sheet.Cells["A1"];

//Input the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");

//Save the Excel file.
wb.Save("d:\\MyBook.xls", FileFormatType.Excel2003);

You can also see the following documentation link regarding creating an excel file in Java
Your First Aspose.Cells Application - Hello World

Also, please see the following documentation link for different formats in which you can create / Save a file.
Converting Workbook to Different Formats

Please see the following online demos which may help you understanding of the different supported features of Aspose.Cells,
https://demos.aspose.com

Please do let us know if you need any further assistance, we will be happy to help you out.

Thank You & Best Regards,

That helps.

Thanks!

YaKe

Hi,
Just want to know that there’s another way of doing which almost matches the first one.

//Create a new Workbook.
Workbook workbook = new Workbook();

    //Get the first worksheet.
    Worksheet sheet = workbook.getWorksheets().get(0);


    //Get the worksheet cells collection.
    Cells cells = sheet.getCells();

  //Input a value.
    cells.get("B3").setValue("Choose Dept:");
    
    Style style = cells.get("B3").getStyle();
    style.getFont().setBold(true);
    
    //Set it bold.
    cells.get("B3").setStyle(style);

  //Input some values that denote the input range for the combo box.
    cells.get("A2").setValue("Boy1");
    cells.get("A3").setValue("Boy2");
    cells.get("A4").setValue("Boy3");
    cells.get("A5").setValue("Boy4");
    cells.get("A6").setValue("Boy5");
    cells.get("A7").setValue("Boy6");

Inspired From: https://stackoverflow.com/questions/29695921/creating-excel-using-aspose

But Now I need to make it dynamic, how should I do it is my question here, @nausherwan.aslam, If I need to say A as 1, B as 2 and AA as 27 and AB as 28, i have to write some fancy logic out there, which I am trying to avoid.Any help here is greatly appreciated. :slight_smile:

  • Kushagra

@kushagra93,

You may manually change to “R1C1 reference style” in MS Excel for your needs:
Click on File > Options > Formulas
In the “Working with formulas” section, check “R1C1 reference style”.

Hope, this helps a bit.

1 Like

@ Amjad_Sahi Alright, Thanks (Y)

@kushagra93,

Good to know that your requirement/issue is sorted out. Feel free to contact us any time if you need further help or have some other issue or queries,we will be happy to assist you soon.