Saving uploaded excel in to SQL Server Database

Hi

Please suggest best approach for below requiremnt.

User will upload excel into Aspose.Cells.GridWeb control and make necessary changes and save file. I would like to save the uploaded file into SQL Server database. so that next time the user can retreive the file and modify it and save it again for further usage. Ideally he will open file from database make changes and then it again store into database.

Also guide how I can save file into SQL Server database. I would not prefer to save entire file as blob/ ntext data type since I want to fetch reports also

Thanks in advance for ur help

Hi,

Well, there are quite a few approaches that can be used for your scenario. For example:

1) Use Aspose.Cells.GridWeb control to load the excel files into the grid for display. You may use the API i.e…,

GridWeb.WebWorksheets.ImportExcelFile(fileName) to load the file into the grid. Users can edit the file visually, apply formatting or other things. Now for saving the excel file from the gridweb to the disk or streams, you may use the code like:GridWeb.WebWorksheets.SaveToExcelFile(filename)

2) For saving the data (in the generated file) to SQL Server Database, you may try some approaches and select any one if it fits your scenario. For example, you may use your own code to fill a datatable based on the the excel file and then use ADO.NET API to fill the SQL Server Database table(s). You may import that data into the gridweb too, for example, you can use your own code using ADO.NET API to fill a datatable from your back end database tables using SQL query, now you may import the data to the gridweb using the view of that table, see the code:

GridWeb.WebWorksheets.ImportDataView(dataTable1.DefaultView, null, null)

Another way is to use data-binding feature of the GridWeb, the control provides this feature. For reference, please see the doc for reference: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net/binding-worksheet-to-a-dataset-at-run-time-using-gridweb.html

You may use different GridWeb for databinding task.

Alternatively, you may use Aspose.Cells library for the task. For example, you may use the following line of code once the edited file is saved to disk/stream by Aspose.Cells.GridWeb control:

//******You can open the saved file using Aspose.Cells.Workbook.Open() method, now export / fill a datatable based on the sheet data in the cells, finally use ADO.NET API to fill the SQL Server Database table(s) for your need.//

Sample code:

Workbook wb = new Workbook();
wb.Open(“f:\test\MyExcelFile.xls”);
Worksheet ws = wb.Worksheets[0];
int trows = ws.Cells.MaxDataRow;
int tcols = ws.Cells.MaxDataColumn;
DataTable dt = ws.Cells.ExportDataTable(0, 0,trows, tcols, true);


Hope, this helps you.

Thank you.

HI

I am able to save and load data from xml file using the following code

SaveXMLFile

this.GridWeb1.WebWorksheets.SaveSpreadSheetMLFile("C:\\Program Files\\Aspose\\Aspose.Cells for .NET\\Demos\\file\\XLSTest3.xml");

LoadfromXMLFile

GridWeb1.WebWorksheets.LoadSpreadSheetMLFile("C:\\Program Files\\Aspose\\Aspose.Cells for .NET\\Demos\\file\\XLSTest3.xml");

1) Please let me know are there any limiations of using this method for saving and loading data using this method

2)Also if the Excel sheet uploaded is multilangugal ( non English language) it gives me error in formulaes ? IS this bug or functionality not embedded i n trials version

please let me know ur reply on the same

Thanks

Sachin

Hi Sachin,

1) Please let me know are there any limiations of using this method for saving and loading data using this method

Well, there is not any specific limitation regarding “WebWorksheets.SaveSpreadSheetMLFile” and “WebWorksheets.LoadSpreadSheetMLFile” methods. If you find any issue, do let us know, we will check it soon.

2)Also if the Excel sheet uploaded is multilangugal ( non English language) it gives me error in formulaes ? IS this bug or functionality not embedded i n trials version

Well, generally, Aspose.Cells.GridWeb supports the formulas in English (US) style. So, you should make sure that the formulas should be in English (US) with their delimiter (',') settings.

Thank you.