We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Save to Server

Thread ID:

Created:

Updated:

Platform:

Replies:

127270 Nov 7,2016 03:10 PM Nov 8,2016 07:39 AM JavaScript 1
loading
Tags: ejSpreadSheet
Will Smith
Asked On November 7, 2016 03:10 PM

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);

Silambarasan I [Syncfusion]
Replied On November 8, 2016 07:39 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;