|
public string OpenFromServer()
{
ExcelEngine excelEngine = new ExcelEngine();
IWorkbook workbook;
FileStream fs = System.IO.File.Open(HttpContext.Server.MapPath("~/Files/") + "Sample.xlsx", FileMode.Open); // converting excel file to stream
workbook = excelEngine.Excel.Workbooks.Open(fs, ExcelOpenType.Automatic);
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);
HttpPostedFileBase fileBase = (HttpPostedFileBase)new HttpPostedFile(outputStream.ToArray(), "Sample1.xlsx");
HttpPostedFileBase[] files = new HttpPostedFileBase[1];
files[0] = fileBase;
OpenRequest open = new OpenRequest();
open.File = files;
fs.Close();
return Workbook.Open(open);
} |
|
public class HttpPostedFile : HttpPostedFileBase
{
private readonly byte[] fileBytes;
public HttpPostedFile(byte[] fileBytes, string fileName)
{
this.fileBytes = fileBytes;
this.InputStream = new MemoryStream(fileBytes);
this.FileName = fileName + ".xlsx";
}
public override int ContentLength => fileBytes.Length;
public override string FileName { get; }
public override Stream InputStream { get; }
} |
|
function openFromServer() {
fetch("http://localhost:54467/Home/OpenFromServer").then((response) => {
response.json().then((data) => {
debugger;
spreadsheet.openFromJson({ file: data });
});
});
} |