<button class="e-btn" onclick="saveToServer()">Save Back to Server</button>
<ejs-spreadsheet id="spreadsheet" openUrl="Home/Open" saveUrl="Home/Save" created="onCreated"></ejs-spreadsheet>
<script>
function onCreated() {
var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
var request = new XMLHttpRequest();
request.responseType = "blob";
request.onload = () => {
var file = new File([request.response], "Sample1.xlsx");
spreadsheetObj.open({ file: file });
}
request.open("GET", "/Files/" + "Sample1.xlsx");
request.send();
}
function saveToServer() {
var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
spreadsheetObj.save();
}
</script> |
public string Save(SaveSettings saveSettings)
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
try
{
// Convert Spreadsheet data as Stream
Stream fileStream = Workbook.Save<Stream>(saveSettings);
IWorkbook workbook = application.Workbooks.Open(fileStream);
var filePath = Startup._env.ContentRootPath.ToString() + "/Files/Sample1.xlsx";
FileStream outputStream = new FileStream(filePath, FileMode.Create);
workbook.SaveAs(outputStream);
return "Spreadsheet saved in server";
}
catch (Exception ex)
{
return "Failure";
}
} |
<script src="https://cdn.syncfusion.com/ej2/17.3.16/dist/ej2.min.js"></script> |