Creating a new Excel file

Hi,

How can I create a new excel file using Aspose.Cells?

Thanks in advance

/Mamun

Hi Mamun,

Thanks for considering Aspose.

Please consult the following sample code with comments attached:

//Instantiate a workbook.
Workbook workbook = new Workbook();
//Get the first (default) worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Get the cells in the sheet.
Cells cells = sheet.Cells;
//Merging two cells (B5:C5)into a single cell(B5).
cells.Merge(4,1,1,2);
//Put some value into the merged cell.
cells["B5"].PutValue("Hello World!");
//Align the text as Center aligned.
cells["B5"].Style.HorizontalAlignment = TextAlignmentType.Center;
//Save the file.
workbook.Save("d:\\test\\test_book.xls");
For further ref, please check the different wiki topics for your need:
Thank you.

Thanks a lot. If I want to open visually a file at runtime, what should I do?

Hi,

Well, Aspose.Cells is a pure library rather than a visual GUI control. The library is used to read and write native excel files with all types of sophisticated formattings, formula calculations, charts creation and more. The reports generated by Aspose.Cells component can be viewed in Excel Viewer or MS Excel. The component is capable of sending the output file to client browser or client's MS Excel for viewing in web application or you may use System.Diagnostics.Process.Start(excelfile) method to open the file into browser in desktop application. For ref, please check:

And if you want a Visual control which has his own grid matrix to view the excel file on the form or page and you want also to create the excel file in WYSIWYG manner, you may use our Aspose.Grid control. The control has his own formula calculation engine and importing / exporting (open the excel file into its grid matrix and save the excel file to disk). It comes with two flavors i.e. Aspose.Grid.Desktop for desktop applications and Aspose.Grid.Web for web asp.net solutions.

For further ref, please check the online demos and wiki docs:

Thank you.

If i want to send the output file (Excel file) to client browser or client's MS Excel for viewing in web application, whats the procedure?

/Mamun

Hi,

Thanks for considering Aspose.

Please consult the following code snippet for your need.

Workbook workbook = new Workbook();
workbook.Worksheets[0].Cells["A1"].PutValue("Hello World!");
//Open the generated file into client's browser.
workbook.Save("MyBook.xls", SaveType.OpenInBrowser, FileFormatType.Default, HttpContext.Current.Response);
...
//Open the generated file into client's MS Excel
//workbook.Save("MyBook.xls", FileFormatType.Default, SaveType.OpenInExcel, Response);
Thank you.