- Home
- Forum
- JavaScript - EJ 2
- Excel File Upload from a Blazor wasm application
Excel File Upload from a Blazor wasm application
Dear Support,
Do you have a component for Blazor wasm application to upload excel file from the client side to a list of records, so it can be sent to the server for storage?
Regards,
Amjad.
SIGN IN To post a reply.
1 Reply
GK
Gayathri KarunaiAnandam
Syncfusion Team
July 20, 2021 11:34 AM UTC
Hi Amjad,
We have analyzed your query. Currently, we does not have support for Spreadsheet in blazor. We have already considered this as a control in blazor and it is expected to be available for any of our upcoming release.
You can track the status of this feature using below link.
We can render JS Spreadsheet in Blazor application by invoking JSRuntime. Please refer below code snippets.
Code snippet:
Index.razor
|
@inject IJSRuntime jsRuntime
<div class="control-section">
<div class="control-wrapper">
<div id="spreadsheet"></div>
</div>
</div>
@code{
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jsRuntime.InvokeAsync<object>("RenderSpreadsheet");
}
} |
_Host.cshtml
|
<script>
function RenderSpreadsheet() {
var spreadsheet = new ej.spreadsheet.Spreadsheet({
allowSave: true,
openUrl: 'https://ej2services.syncfusion.com/production/web-services/api/spreadsheet/open',
saveUrl: 'https://ej2services.syncfusion.com/development/web-services/api/spreadsheet/save',
});
//Render initialized Spreadsheet component
spreadsheet.appendTo('#spreadsheet');
}
</script> |
For your reference, we have prepared a sample based on this scenario. Please check the below link.
Please check the below code snippet for Spreadsheet core service.
Controller:
|
public IActionResult Open(IFormCollection openRequest)
{
ExcelEngine excelEngine = new ExcelEngine();
IWorkbook workbook;
FileStream fs = System.IO.File.Open("./wwwroot/Sample1.xlsx", FileMode.Open);
workbook = excelEngine.Excel.Workbooks.Open(fs, ExcelOpenType.Automatic);
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);
IFormFile formFile = new FormFile(outputStream, 0, outputStream.Length, "", "Sample1.xlsx"); // converting MemoryStream to IFormFile
OpenRequest open = new OpenRequest();
open.File = formFile;
fs.Close();
return Content(Workbook.Open(open));
}
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() + "/wwwroot/Sample1.xlsx";
FileStream outputStream = new FileStream(filePath, FileMode.Create);
workbook.SaveAs(outputStream);
outputStream.Close();
return "Spreadsheet saved in server";
}
catch (Exception ex)
{
return "Failure";
}
}
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
public class CustomArgs
{
public string customValue { get; set; }
public string address { get; set; }
public int sheetIndex { get; set; }
} |
Core service: https://www.syncfusion.com/downloads/support/forum/167388/ze/SSLoadExcelDirectlyFromServer-14008583561934601425
Please check the above links and get back to us, if you need further assistance.
Regards,
Gayathri K
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
AK Amjad Khan
- Jul 15, 2021 11:22 AM UTC
- Jul 20, 2021 11:34 AM UTC