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

Free Support Forum - aspose.com

Error while converting MHTML file into XLSX

Hi,
I was evaluating Aspose.Cells DLL. We are trying to convert a MHTML file into XLSX format. While using the below code, I am getting an issue which says

"An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in Aspose.Cells.dll

Additional information: Length cannot be less than zero."

Here is my code. I am using visual studio 2015 console application.

        HTMLLoadOptions options = new HTMLLoadOptions(LoadFormat.MHtml);
        HtmlSaveOptions soptions = new HtmlSaveOptions(SaveFormat.Xlsx);       
        Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(@"C:\Users\rr274355\Desktop\ex.mhtml");
        book.Save(@"C:\Users\rr274355\Desktop\" + "output.xlsx", soptions);

Please let me know if there is any solution for this issue

Thanks,
Subha.S

@subha.sundar,

We need your template file “ex.mhtml”, so we could evaluate your issue on our end. Please provide us the template file.

By the way, could you change your sample code as following if it makes any difference:
e.g
Sample code:

HTMLLoadOptions options = new HTMLLoadOptions(LoadFormat.MHtml);
OoxmlSaveOptions soptions = new OoxmlSaveOptions(SaveFormat.Xlsx);
Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(@“C:\Users\rr274355\Desktop\ex.mhtml”, options);
book.Save(@“C:\Users\rr274355\Desktop” + “output.xlsx”, soptions);

Thank you.

Hi ,
I have tried your code. But still couldn’t solve this issue.

And also I have attached the sample MHTML file
sample.zip (8.6 KB)

Please let me know if you find the solution.

Thanks,
Subha.S

@subha.sundar,

Thanks for the template MHTML file.

After an initial test, I am able to observe the issue as you mentioned by loading your attached template MHTML file format. I found ‘System.ArgumentOutOfRangeException’ occurred when loading the MHTML file:
e.g
Sample code:

HTMLLoadOptions options = new HTMLLoadOptions(LoadFormat.MHtml); 
    Aspose.Cells.Workbook book = new Aspose.Cells.Workbook("e:\\test2\\sample.mhtml", options); 

I have logged a ticket with an id “CELLSNET-45467” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Thank you.

Hi,
Any updates on this issue. Please let me know the updates.

@subha.sundar,

I checked your issue’s status, it is in Progress. Our concerned developer is working over your issue and hopefully it will be fixed in the next 3-5 days or so. If your issue is not fixed in this time span, kindly do contact us here.

Thank you.

@subha.sundar,

We are pleased to inform you that we have fixed your issue now. We will soon provide you the fix after performing QA and incorporating other enhancements and fixes. I hope you should be getting the fix (we will provide you the Download link here) in the next couple of days or so.

Keep in touch.

Thank you.

@subha.sundar

Please download and try the following fix and let us know your feedback.

@shakeel.faiz and @Amjad_Sahi ,
Thanks for the fix and it is working good now.

Thanks,
Subha.S

@subha.sundar,

Thanks for your feedback.

We are glad to hear your issue is sorted out by the new fix/version. Feel free to write us back if you have further comments and questions, we will happy to assist you soon.

Thank you.

Hi @Amjad_Sahi,
I having couple of doubts.

  1. Is there any option to have the conversion as in-memory. Like I am having a memory stream and want to convert into a memory stream that will be directly loaded into the browser without saving as a file.
    Because to buy the license, this required is mandatory for us.

  2. Is there any option to convert byte stream into PDF and also excel file into PDF?

Let me know if I am missing something or you have any doubts.

Thanks,
Subha.S

@subha.sundar,

Yes, you may read/write files from/to memory streams. All you need to do is choose the relevant overload of Workbook constructor when loading the Excel or HTML file. Similarly, you will use relevant overloads of the method when saving the Workbook via Workbook.Save().

See the document on how to read the file from streams:
https://docs.aspose.com/display/cellsnet/Different+Ways+to+Open+Files#DifferentWaystoOpenFiles-OpeningaFileusingaStream
(Note: you got to use your own code to read the file into streams first then use Aspose.Cells APIs to open the file from streams)

https://docs.aspose.com/display/cellsnet/Different+Ways+to+Save+Files#DifferentWaystoSaveFiles-SavingFiletoaStream
(This will denote on how to save the file to memory stream or file streams. You may save the workbook to Excel or PDF streams. You have to use your own code to write the file (PDF/Excel, etc.) from streams).

Hope, this helps a bit.

Thank you.

Hi @Amjad_Sahi,
Thanks for the link and that helps. And one more requirement we are looking is to read a Data Set and write into excel. Is there any options available for that. I saw that ImportDatatable() method is for Data Tables. But is there any available methods for Data Set?

It will be helpful if you send sample code for that.

Thanks,
Subha.S

@subha.sundar,

Well, DataSet is just a container (like a folder) which may contain a collection of DataTable objects. There is no such method available to import DataSet tables/objects in one go. I think you may easily loop through data tables (etc.) in the DataSet and import data tables (one by one) via Aspose.Cells APIs.

Hope, this helps a bit.

Thank you.

@Amjad_Sahi
Thanks for the quick reply. We will work it out as you said for dataset.

Thanks,
Subha.S

The issues you have found earlier (filed as CELLSNET-45467) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi

The issues you have found earlier (filed as CELLSNET-45467) have been fixed in this update.