Load from stream
Is it possible to load a spreadsheet from an Excel file stream? What I need to do is to open an Excel file in an .NET web service and add data via an .NET Excel component and then stream it to the Excel viewer without saving it to the server. Is that possible?
SIGN IN To post a reply.
2 Replies
SD
Saranya Dhayalan
Syncfusion Team
January 10, 2020 12:47 PM UTC
Hi William,
Good day to you.
We would like to let you know that you can load a Stream into Spreadsheet control by converting the Stream into Formfile and assigning it to File property of OpenRequest of Spreadsheet. We have prepared a sample, in that we have opened a excel to the spreadsheet in ‘created’ event using open method in the client side. Please refer the below code snippets and sample link.
HomeController.cs
|
public IActionResult Open(IFormCollection openRequest)
{
OpenRequest open = new OpenRequest();
MemoryStream memoryStream = new MemoryStream();
openRequest.Files[0].CopyTo(memoryStream); // Excel file is converted into Memory Stream
IFormFile formFile = new FormFile(memoryStream, 0, memoryStream.Length, "", openRequest.Files[0].FileName); // converting MemoryStream to IFormFile
open.File = formFile;
return Content(Workbook.Open(open));
} |
App.vue
|
<template>
<ejs-spreadsheet ref="spreadsheetRef" openUrl="http://localhost:55367/Home/Open" saveUrl="http://localhost:55367/Home/Save" :created="onCreated"></ejs-spreadsheet>
</template>
<script>
import Vue from 'vue';
import { SpreadsheetPlugin } from '@syncfusion/ej2-vue-spreadsheet';
Vue.use(SpreadsheetPlugin);
export default {
methods: {
onCreated: function() {
var request = new XMLHttpRequest();
request.responseType = "blob";
request.onload = () => {
var file = new File([request.response], "Sample1.xlsx");
this.$refs.spreadsheetRef.open({ file: file });
}
request.open("GET", "http://localhost:55367/" + "Sample1.xlsx");
request.send();
}
}
}
</script> |
Sample link: https://www.syncfusion.com/downloads/support/forum/150513/ze/SpreadsheetLoadFromStreamVue-324499307
Could you please check the above sample and get back to us if you need further assistance on this?
Regards,
Saranya D
WM
William Morgenweck
February 12, 2020 02:17 AM UTC
This is great. If I could ask another question, I don't see in the documentation how I can read each row and change a cell . I would like the ability to read each row and if column c has a value less than 5 I would change it to another value. Is that possible?
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
WM William Morgenweck
- Jan 9, 2020 12:02 PM UTC
- Feb 12, 2020 02:17 AM UTC