We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue converting HTML to XLSX

Hi,

I am using Aspose Version 8.4.2.0 to convert dynamic HTML string to excel(xlsx/xls) file. There also includes external css. In the Method, the html string is dynamic. For different report the html string will be different. So after getting the report I am attaching my external stylesheet to it and trying to pass it to excel to generate the result.

Here the main code we are using is:

Response.AddHeader(“Content-Type”, “application/octet-stream”);
Response.AppendHeader(“content-disposition”, “attachment;filename=”" + reportFileName + “_” + DateTime.Now.ToString(“MMddyyyyHHmmss”,
CultureInfo.InvariantCulture) + “.xls”");
Response.ContentType = “application/vnd.ms-excel”;
HTMLLoadOptions options = new HTMLLoadOptions(LoadFormat.Html);
byte[] byteArray = Encoding.ASCII.GetBytes(html);
MemoryStream stream = new MemoryStream();
stream.Read(byteArray, 0, byteArray.Length);
Workbook book = new Workbook(stream, options);
book.Save(stream, new XlsSaveOptions(SaveFormat.Excel97To2003));

Using this code I am able to generate the report, but while opening the report I am getting a warning message “The File Format and extension don’t match. The file could be corrupted or unsafe”.
The only reason I am using Aspose is so that we don’t get this warning message. Can you help me resolve this issue?Need fast resolution.

Thanks

@saptarockz,

Thanks for the sample code segment.

We need your HTML string to evaluate your issue precisely. Also your sample code is not in order or it is incomplete. The correct order might be: first create byte arrays based on your html string/file and then read into streams. Now instantiate workbook object from the stream (with respect to HTML load options) . Then, define memory stream and save the workbook to streams (with respect to relevant save format type). You may set the memory stream’s position to “0” or at the start. Now use Response object’s relevant methods/attributes to instantiate different parameters to binary write (after converting the memory streams to arrays) data to the specified file, so it could be output/retrieved on client’s end (using browser type).

If you still find the issue, kindly provide us a sample project (runnable) to show the issue, you may zip the project prior attaching here, we will check it soon. Also, provide template files (input (if any) and output file). This will help us really to evaluate your issue precisely to consequently figure it out soon.