Cell width is not being honoured in HTML output

Hi,


I am using Aspose Cells 8.3.2.

While fetching HTML output of the given table, the width of the columns is not being honoured. However, this was working fine with Apose Cellls 8.3.0.

Snippet of the HTML Output from version 8.3.0:

Snippet of the HTML Output from version 8.3.2:
<col width=64 span=4 style=‘width:48pt’>

I have also attached the source excel file being used.

Following is the source code to generate HTML output:
Workbook workbook = new Workbook(“C:\TestWidth.xlsx”);
com.aspose.cells.Worksheet selectedWorksheet = workbook.getWorksheets().get(“Sheet1”);
ListObject listObject = selectedWorksheet.getListObjects().get(“Table1”);
Range sourceRange = listObject.getDataRange();
//Include table’s header row
int fcol = sourceRange.getFirstColumn();
int frow = sourceRange.getFirstRow() - 1; // including the first header row.
int rowCount = sourceRange.getRowCount() + 1; // including the first header row.
int colCount = sourceRange.getColumnCount();

sourceRange = selectedWorksheet.getCells().createRange(frow, fcol, rowCount, colCount);
File htmlFile = new File(“c:/out.html”);
Workbook targetWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = targetWorkbook.getWorksheets();
com.aspose.cells.Worksheet targetWs = (com.aspose.cells.Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);
targetWorkbook.save(htmlFile.getAbsolutePath(), SaveFormat.HTML);

Thanks,
Neeraj

Hi Neeraj,


Thank you for contacting Aspose support.

I have evaluated your presented scenario while using the latest version of Aspose.Cells for Java 8.4.0.5, and was able to replicate the said issue. The column widths in the HTML does not seem to correspond to the column widths in the input spreadsheet. However, I believe the issue is not related to the HTML rendering but with the PasteOptions class. As you are using the Range.copy method to copy a range onto a new Workbook, the PasteType.All does not copy the column widths along with data & formatting onto the new range. You may confirm this by saving the result in spreadsheet format (XLSX) rather than HTML.

I am performing more tests before logging this incident as an issue in our bug tracking system. In the meanwhile, could you please share the resultant spreadsheet as discussed above.
Hi,

I tried saving the copied range resultant into XLSX format & observed that column widths are not being honored in the output.
However, the PasteType.All option worked fine in 8.3 release & copied the column widths & data to the resultant output very well. Moreover, this solution was suggested by one of the Aspose team members.
Is this a break post 8.3 release ?
How do I retain column widths in the outputs while using the latest Aspose releases like 8.3.2 or beyond?

Also, I have attached the copied range excel & source excel.
Worksheet : Charts & tables
Input range A72:H87

Thanks,
Neeraj

Hi Neeraj,


Thank you for the confirmation.

We have tested the presented scenario again while using the latest version of Aspose.Cells for Java 8.4.0.5 & previous releases 8.3.0, 8.3.1 & 8.3.2. We have noticed that the said issue (Column widths not being copied with PasteType.All) was introduced somewhere between 8.3.1 & 8.3.2, and still persists with latest release 8.4.0.5. We need to investigate the matter thoroughly so the issue has been logged in our database under the ticket CELLSJAVA-41262, Please allow us some time to properly analyze the scenario to pin point the problem cause. In the meanwhile, we will keep you posted with updates in this regard.

Hi,

Thanks for using Aspose.Cells.

If you select “All” in “Paste Special” tab when paste a range in MS Excel , MS Excel does not copy the width of columns.

Aspose.Cells works same as MS Excel now.

Hi Neeraj,


Please try the following piece of code and let us know of your feedback.

Java

Workbook workbook = new Workbook(“D:/TestWidth.xlsx”);
Worksheet selectedWorksheet = workbook.getWorksheets().get(“Sheet1”);
ListObject listObject = selectedWorksheet.getListObjects().get(“Table1”);
Range sourceRange = listObject.getDataRange();
int fcol = sourceRange.getFirstColumn();
int frow = sourceRange.getFirstRow() - 1;
int rowCount = sourceRange.getRowCount() + 1;
int colCount = sourceRange.getColumnCount();
sourceRange = selectedWorksheet.getCells().createRange(frow, fcol, rowCount, colCount);

File htmlFile = new File(“D:/out.html”);
Workbook targetWorkbook = new Workbook(FileFormatType.XLSX);
WorksheetCollection targetWsc = targetWorkbook.getWorksheets();
Worksheet targetWs = (Worksheet)targetWsc.get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
//Copy column widths
options.setPasteType(PasteType.COLUMN_WIDTHS);
targetRange.copy(sourceRange, options);
//Copy everything else
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);
targetWorkbook.save(htmlFile.getAbsolutePath(), SaveFormat.HTML);