Save to Server

Is there a way to save the data in a spreadsheet control to the server? I don't mind downloading it to client, but I would like to keep changes on the server side too.

Spreadsheet.Save(sheetModel, sheetData, filename, ExportFormat.XLSX, ExcelVersion.Excel2013);

1 Reply

SI Silambarasan I Syncfusion Team November 8, 2016 12:39 PM UTC

Hi Will, 
 
Thank you for using Syncfusion products. 
 
Your requirement “To save the data in a Spreadsheet control to the server” can be achieved by using ‘Save()’ method in Spreadsheet.  Please refer the following code example. 
 
C# 
 
[AcceptVerbs(HttpVerbs.Post)] 
public void ExportToExcel(string sheetModel, string sheetData, string password) 
{ 
    SaveFileToDB(sheetModel, sheetData); 
    //... 
} 
 
 
[AcceptVerbs(HttpVerbs.Post)] 
public void SaveFileToDB(string sheetModel, string sheetData) 
{ 
    string dbConnectionStr = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\spreadsheetDB.mdf;Integrated Security=True"; 
    SqlConnection sqlCon = new SqlConnection(dbConnectionStr); 
    sqlCon.Open(); 
 
    //Get Spreadsheet data as Stream 
    Stream streamData = Spreadsheet.Save(sheetModel, sheetData, ExportFormat.XLSX, ExcelVersion.Excel2013); 
    Byte[] dataBytes = ((MemoryStream)streamData).ToArray(); 
 
    SqlCommand sqlComm = new SqlCommand("INSERT INTO [dbo].[Table]([FileName], [FileData]) VALUES (@FileName, @FileData)", sqlCon); 
    sqlComm.Parameters.AddWithValue("@FileName", "Sample"); 
    sqlComm.Parameters.AddWithValue("@FileData", dataBytes); 
    sqlComm.ExecuteNonQuery(); 
    sqlCon.Close(); 
} 
 
 
 
HTML 
 
$("#Spreadsheet").ejSpreadsheet({ 
    //... 
    exportSettings: 
    { 
        excelUrl: "/Home/ExportToExcel", 
    } 
}); 
 
 
 
 
 
For your convenience, we have prepared a sample to demonstrate this and the same can be downloaded from the below link, 
 
 
 
Regards, 
Silambarasan I 


Loader.
Up arrow icon