Running into a small issue after getting the spreadsheet control up and running.
I have a feeling it is a caching issue somewhere, but before I started investigating that which could take awhile I figured I would ask if maybe I missed something in implementation.
So when loading the page the control loads, grabs the spreadsheet and displays it. I can edit no problem and save.
The issue comes when it saves and reloads and even when I refresh the page it reloads the spreadsheet without the newest changes.
I suspect it to be a caching issue somewhere cause even when I download the spreadsheet from the application it does not have the changes just made.
It has worked as expected some of the time and reloads with new changes.
index.cshtml
@page "{handler?}"
@model ExcelModel
@using Syncfusion.EJ2
@{
ViewData["Title"] = "Excel File";
}
<ejs-spreadsheet id="spreadsheet" openUrl="Open" saveUrl="Save" created="onCreated">
</ejs-spreadsheet>
<script>
"use strict";
function onCreated() {
//Apply style to a range
this.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:I1');
var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
var request = new XMLHttpRequest();
request.responseType = "blob";
request.onload = () => {
var file = new File([request.response], "file");
spreadsheetObj.open({ file: file });
}
request.open("GET", "/" + "file path");
request.send();
}
function saveToServer() {
var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
spreadsheetObj.save();
}
</script>
index.cshtml.ca
namespace ExcelFile
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class ExcelModel : PageModel
{
private readonly IHostingEnvironment _hostingEnvironment;
public ScorecardExcelModel(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public void OnGet()
{
}
public IActionResult OnPostOpen(IFormCollection openRequest)
{
OpenRequest open = new OpenRequest();
open.File = openRequest.Files[0];
return Content(Workbook.Open(open));
}
public IActionResult OnPostSave(SaveSettings saveSettings)
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
// Convert Spreadsheet data as Stream
Stream fileStream = Workbook.Save<Stream>(saveSettings);
IWorkbook workbook = application.Workbooks.Open(fileStream);
var filePath = _hostingEnvironment.WebRootPath + @"file path";
FileStream outputStream = new FileStream(filePath, FileMode.Create);
workbook.SaveAs(outputStream);
workbook.Close();
outputStream.Dispose();
return Page();
}
}
}