Problem while saving excel sheet as html

Hi,

I am converting excel sheet to html by using:

workbook.Save(destinationFilePath, SaveFormat.Html);

The problem is that in the converted html, the cell width gets shrunk. The numerical values are proper, but the cells which contain text are the problem area. The text gets chopped off resulting in erroneous data.

Could you please give me any pointers in that direction?

Thanks and regards,
Nikhil

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please provide us your source xls/xlsx file which you are converting to html, so that we could look into this issue.

Please also provide a screenshot to highlight the problem with red circles.

Please also download and try the latest version:
Aspose.Cells
for .NET v7.2.2.7

It should solve html issues which you are facing.

Hi Shakeel,

Thanks for an early response. PFA the zip file which contains the excel sheet and also the screenshot of the converted html file. I have highlighted the problem areas in red.

Hi,

Thanks for your sample code and description document.

I was able to replicate your issue with the code provided by you using the latest fix:
Aspose.Cells
for .NET v7.2.2.7
. I also tried different paste options, but they did not work.

We have logged this issue in our database. We will look into it and fix the problems and let you know asap.

This issue has been logged as CELLSNET-40847.

Below is my test code. I have attached the output html file and screenshot for a reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\Excel to Html\Test1.xlsx”;



Workbook workbook = new Workbook(filePath, new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx));

Workbook destWorkbook = new Workbook();

Worksheet destSheet = destWorkbook.Worksheets[0];

int TotalRowCount = 0;

for (int i = 0; i < workbook.Worksheets.Count; i++)

{

Worksheet sourceSheet = workbook.Worksheets[i];

Aspose.Cells.Range sourceRange = sourceSheet.Cells.MaxDisplayRange;

Aspose.Cells.Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn, sourceRange.RowCount, sourceRange.ColumnCount);


PasteOptions opts = new PasteOptions();

opts.PasteType = PasteType.All;


//Paste Options are also not working

destRange.Copy(sourceRange,opts);

TotalRowCount = sourceRange.RowCount + TotalRowCount;

}

destWorkbook.Save(filePath + “.out2.html”, Aspose.Cells.SaveFormat.Html);



Screenshot:

Thanks Shakeel,

Will wait to hear back from you.

Warm Regards,
Nikhil

Hi,


I think Aspose.Cells works the same way as MS Excel does. For confirmation, you may try to copy the cells range in a sheet to paste into another worksheet, you will see that it presents the same view as per the output file (generated by Aspose.Cells). Shakeel Faiz has provided you a good code segment using the Paste Special options, but after look into it, I found if I do it in MS Excel manually, I actually got the same result as Aspose.Cells provides. So, I think it is not an issue, I think for your need, you need to first use copy/paste special facility to copy/paste the column widths from source range to destination range. After this, you need to again copy/paste the range/values from source range to destination range. See the sample code below that works fine as I tested, this is the same code as Shakeel Faiz shared but I updated / added a few lines accordingly. It works fine as per your requirements.

Sample code:

string filePath = @“e:\test2\Excel to Html\Test1.xlsx”;


Workbook workbook = new Workbook(filePath, new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx));
Workbook destWorkbook = new Workbook();
Worksheet destSheet = destWorkbook.Worksheets[0];
int TotalRowCount = 0;
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
Worksheet sourceSheet = workbook.Worksheets[i];
Aspose.Cells.Range sourceRange = sourceSheet.Cells.MaxDisplayRange;
Aspose.Cells.Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn, sourceRange.RowCount, sourceRange.ColumnCount);

PasteOptions opts = new PasteOptions();
opts.PasteType = PasteType.ColumnWidths;

destRange.Copy(sourceRange, opts); //First you will copy/paste the column widths
destRange.Copy(sourceRange);//Now copy the range
TotalRowCount = sourceRange.RowCount + TotalRowCount;
}
destWorkbook.Save(filePath + “_out.html”, Aspose.Cells.SaveFormat.Html);

Thank you.

Hi Amjad,

I checked out the code and as long as the Excel sheet is well formatted and the cells are blown up to their full automatic widths(i.e. there are no columns overlapping each other), there doesn't seem to be any problem in the conversion. Thanks for the reply.

Regards,
Nikhil

Hi,

Thanks for your feedback and using Aspose.Cells.

We will close this issue after some investigation at our end. If we found some bug, we will fix it.

Hi,

I got the problem. The scenario is that I have a cloud project. My web role uploads the excel file to a blob and notifies the worker about it via a queue. The worker then downloads the excel, and uses Aspose to convert it to HTML, and uploads the output back to a blob.
I executed the same code twice, once using the cloud scenario mentioned above and once by picking up files from the local machine and storing the output back to the local machine.
What I noticed was that the same code that works perfectly in the second scenario doesn’t work as well in the first scenario. i.e. the cloud one.
Could you guys please look into the matter?

Hi,


Well, I am not sure about your issue. Again, just for your information, Aspose.Cells works the same way as MS Excel does. You may confirm it in MS Excel following the steps in it manually. Moreover, Aspose.Cells for .NET is a created in managed C# and is just a .NET library used to create, manipulate or convert MS Excel file formats. It works the same way as other .NET component works in .NET and different environments or platforms. So, I think if it works fine in a simple Winform/Webforms projects etc., it is not an issue with the product.

Moreover, we have also an alternate solution if you do not want to write all the implementation classes codes on cloud. You can use our other file format expert, i.e. Saaspose to convert your documents on any platform including Java, .NET, PHP, Ruby etc and many more. Saaspose allows you to convert your documents with a single API call. You can also use Saaspose SDK for your favorable platforms in your applications.
Please check Saaspose API documentation http://saaspose.com/docs/display/cells/Home for more details on how to use Saaspose.Cells in your application (for .NET, PHP, Ruby, JAVA platforms etc.) to create or convert documents accordingly and see SDK details for your needs.


Thank you.

Hi Amjad,
Thanks for the clarification. Will dig into Saapose as suggested.

Regards,
Nikhil

Hi,

Thanks for considering Aspose and digging into Saaspose.

If you need any sort of help relating to Aspose components, please let us know, we will be glad to help you.

Hi,

Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v7.7.1.2 and let us know your feedback.

Please also note when PasteType is PasteType.All, column width is not copied.

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


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.