|
public IActionResult Open(IFormCollection openRequest)
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
OpenRequest open = new OpenRequest();
string filePath1 = Startup._env.ContentRootPath.ToString() + "/Files/File1.xlsx";
FileStream inputStream1 = new FileStream(filePath1, FileMode.Open); // opened the existing file
IWorkbook workbook = application.Workbooks.Open(inputStream1); // created the workbook
FileStream fileStream = new FileStream(Startup._env.ContentRootPath.ToString() + "/Files/ModifiedFile.xlsx", FileMode.Create);
workbook.SaveAs(fileStream); // save the workbook to stream
inputStream1.Close();
IFormFile formFile = new FormFile(fileStream, 0, fileStream.Length, "", "ModifiedFile.xlsx"); // converting MemoryStream to IFormFile
open.File = formFile;
var content = Workbook.Open(open);
fileStream.Dispose();
return Content(content);
} |
Thanks that works!
Is there a way to load the Spreadsheet control with the IWorkbook when the Spreadsheet control is first created? So when the Spreadsheet control is created, the IWorkbook loads the 'File1.xlsx' file and then the IWorkbook is set in the Spreadsheet control, instead of during Open.
|
<ejs-spreadsheet id="spreadsheet" openUrl="Home/Open" saveUrl="Save" created="onCreated">
</ejs-spreadsheet>
function onCreated() {
var ssObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
$.ajax({
type: "POST",
url: "Home/OpenFile",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
ssObj.openFromJson({ file: data });
}
})
} |