Simple xlsx file not being rendered

Hello!

I have 3 issues with the spreadsheet (JavaScript and MVC) component:

1) I'm trying to load a spreadsheet (JS) with a very simple Excel file (attached). In fact, the file has only a text in cell A1 ("TEST CELL") and the workbook was renamed as "TestWorkbook".

In both places (my code and in the demo page at https://ej2.syncfusion.com/javascript/documentation/spreadsheet/open-save/) the file is loaded, but the workbook is empty. No text in A1 cell.


2) I didn't find a suitable method in the backend (MVC) that can convert an Excel file to Json, in a way that it can accepted by the javascript spreadsheet.
Either the methods I use, or the format obtained, don't seem to work with the JS component.

These are the test in the backend that I tried in order to pass an excel file to the spreadsheet in the browser:

TEST 1: Use of xlsio.ExcelEngine
Using engine As New Syncfusion.XlsIO.ExcelEngine
     Dim app As IApplication = engine.Excel
     Dim workbook = app.Workbooks.Open(ms) '// ms=memory stream of the excel file
     workbook.SaveAsJson(m2, True) '// m2 is another stream to hold the json
     return System.Text.Encoding.UTF8.GetChars(m2.ToArray)
End Using


The problem with thecode above is that the generated json seems not of the expected format for the spreadsheet... 
For instance, from the attached excel file, it generates something like this:
"{ \"TestWorkbook\": [ ] }"

* There is no info about the cell A1, no info about the sheets, etc...

TEST 2: Use of Workbook.open
'// I had to create a class that inherits from HttpPostedFileBase to use some syncfusion methods shown below
Private Class ExcelFile
    Inherits HttpPostedFileBase
    Private _stream As Stream
    Private _filename As String
    Public Sub New(s As Stream, name As String)
        _stream = s
        _filename = name
    End Sub
    Public Overrides ReadOnly Property ContentLength As Integer
        Get
            Return _stream.Length
        End Get
    End Property
    Public Overrides ReadOnly Property ContentType As String
        Get
            Return "applications/json"
        End Get
    End Property
    Public Overrides ReadOnly Property FileName As String
        Get
            Return _filename
        End Get
    End Property
    Public Overrides ReadOnly Property InputStream As Stream
        Get
            Return _stream
        End Get
    End Property
End Class

 Using ms As New MemoryStream()
    str.CopyTo(ms)     '// str is the filestream of the excel file
    ms.Seek(0, SeekOrigin.Begin)
    Dim file As New ExcelFile(ms, "Blank.xlsx") '//ExcelFile is the custom class defined above
    Dim a() As HttpPostedFileBase = {file}
    Dim open As New OpenRequest
    open.File = a
    result = Workbook.Open(open)
End Using

The code above generates a json like this:
"{\"Workbook\":{\"definedNames\":[],\"sheets\":[{\"name\":\"TestWorkbook\",\"rows\":[{}],\"selectedRange\":\"A2\","\usedRange\":{}}]}}"

* As it can be seen, that json doesn't containt the text in cell A1.

The components I'm using are EJ2.MVC 5, EJ2 JavaScript, EJ2.SpreadSheet.AspNet.Mvc5, and XlsIO.AspNet.Mv5, all version 18.2.0.48

3) The last issue I'm having is this: Which method should I use in the frontend in order to load an excel file (serialized to json)? supposing I have an instance of spreadsheet called xlsObj:

a) xlsObj.openFromJson ?
b) xlsObj.open ?


Thank you, regards
Alex


Attachment: Blank_875419c6.zip

4 Replies

AL Alejandro August 10, 2020 08:05 PM UTC

Hello,

Can you confirm that point 1) is a bug? I believe so since the demo page also fails rendering the excel file.

Thank you!
Alex



MV Madhan Venkateshan Syncfusion Team August 11, 2020 07:48 AM UTC

Hi Alejandro, 
 
Good day to you. 
 
Query #1: Can you confirm that point 1) is a bug? I believe so since the demo page also fails rendering the excel file. 
 
Yes, We have confirmed that the reported issue is a defect and the fix for this issue is estimated to be available on next week patch release and appreciate your patience until then. 
 
Query #2: I didn't find a suitable method in the backend (MVC) that can convert an Excel file to Json 
 
You can use the inherited class of HttpPostedFileBase and assign to File object of OpenRequest, please refer the below code snippets. 
 
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; } 
    } 
 
Query #3: The last issue I'm having is this: Which method should I use in the frontend in order to load an excel file (serialized to json)? 
 
You can use ‘openFromJson’ method to load the json data returned from server, please refer the below code snippets. 
 
function openFromServer() { 
        fetch("http://localhost:54467/Home/OpenFromServer").then((response) => { 
            response.json().then((data) => { 
              debugger; 
                spreadsheet.openFromJson({ file: data }); 
            }); 
        }); 
    } 
 
Regards, 
Madhan V 



AL Alejandro September 30, 2020 03:29 PM UTC

Hello dear people,

I've upgraded to version 18.2.0.59 of the SF components, and I'm still not able to open a simple XLSX file (attached again).

The file contains just the text "TEST CELL" in cell A1, and it's not being displayed in the spreadsheet component.

Also, the same file fails to show properly in the demo page: https://ej2.syncfusion.com/javascript/documentation/spreadsheet/open-save/

Can you confirm this is still a to-resolve bug?

Thank you!
Alex



Attachment: Blank_eae70ea.zip


SP Sangeetha Priya Murugan Syncfusion Team October 1, 2020 07:52 AM UTC

Hi Alejandro, 
 
Thank you for your update. 
 
We have checked your reported issue based on your provided excel file and we are able to reproduce it in our end. So, we confirmed this as a defect and the fix for this issue will be available in mid of October month patch release. We appreciate your patience until then.  
  
Could you please check the above details and get back to us, if you need any further assistance on this.  
  
Regards,  
Sangeetha M  



Loader.
Up arrow icon