- Home
- Forum
- ASP.NET Core - EJ 2
- Spreadsheet
Spreadsheet
Is there an example of the Spreadsheet control in a Razor Pages app?
I have looked over the examples and all are for MVC, having trouble getting it to work in a Razor Pages app.
A sample in Razors pages would be greatly appreciated.
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
SP
Sangeetha Priya Murugan
Syncfusion Team
October 9, 2020 05:42 PM UTC
Hi Sheldon,
Thank you for your patience.
We have checked your reported requirement and it can be achievable in our Spreadsheet. For your convenience, we have prepared the sample based on your requirement. Please find the link below.
Sample Link: https://www.syncfusion.com/downloads/support/forum/158367/ze/PdfViewer_RazorPages-1687875300
Could you please check the above sample and get back to us if you need further assistance.
Regards,
Sangeetha M
Marked as answer
SH
Sheldon
October 9, 2020 06:38 PM UTC
Thank you.
I modified slightly for the openUrl and saveUrl and it works now.
A couple things I did not have was the "handler?" page direction, "use strict"; and
private readonly IHostingEnvironment _hostingEnvironment;
public Scorecard2Model(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
adding these worked.
SP
Sangeetha Priya Murugan
Syncfusion Team
October 12, 2020 05:51 AM UTC
Hi Sheldon,
Thank you for your update, Please feel free to contact us if you need any further assistance on this.
Regards,
Sangeetha M
SH
Sheldon
October 16, 2020 06:03 PM UTC
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();
}
}
}
MV
Madhan Venkateshan
Syncfusion Team
October 20, 2020 11:33 AM UTC
Hi Sheldon,
Good day to you.
You can avoid the cache issue by adding the below meta tag in your layout.html to prevent caching, please refer the below code snippets.
_Layout.cshtml
|
<head>
<meta http-equiv="Cache-control" content="no-cache">
</head> |
Regards,
Madhan V
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
- Marked answer
-
SH Sheldon
- Oct 8, 2020 01:40 PM UTC
- Oct 20, 2020 11:33 AM UTC