Free Support Forum - aspose.com

Save data to database

Hi <br><br>I have purchased ASPOSE Total. I am not sure where to get the demo for reading data from an excel sheet and saving it to my database. Could you please provide the code required.<br><br>Regards<br>Shalini<br>
Hi Shalini,

Thanks for considering Aspose.

Well, you may read data from worksheet of a workbook and export it to fill a datatable using Aspose.Cells APIs (Cells.ImportDataTable / Cells.ImportDataTableAsString methods) and use your own ADO.NET code to save it to your data source. Alternatively, you may export data to an array and later save it in your database.

May the following code help your need:

Workbook workbook = new Workbook();
workbook.Open(@"d:\test\mybook.xls");
Worksheet worksheet = workbook.Worksheets[0];
DataTable dataTable = new DataTable();
dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1);
dataGrid1.DataSource = dataTable;
.
.
.
.

For further reference, please check wiki documentation (http://www.aspose.com/wiki/default.aspx/Aspose.Cells/) especially the topic:

http://www.aspose.com/wiki/default.aspx/Aspose.Cells/ExportData.html

Thank you.

what do we need to include to define FileStream. now it gives the message - filestream not define.

Hi,

I am not very clear your need. However, I write the following code for my understanding. Kindly make sure that you have referenced System.IO namespace in your project.

E.g.,

FileStream fs = new FileStream("d:\\test\\mybook.xls",FileMode.Open);
Workbook workbook =new Workbook();
workbook.Open(fs,FileFormatType.Excel2003);
.
.
.
workbook.Save("d:\\test\\out_mybook.xls",FileFormatType.Excel2003);

Thank you.