During the conversion of a worksheet to HTML, the column widths of the exported HTML change between Windows and Linux OS. The conditions that produce this behavior are:
- The “Normal Style” of the worksheet is modified - specifically the “standard font” assigned to the Normal Style is "Times New Roman 9 pts
- The “default column width” is un-altered (at 8.5)
- The font for the “Normal Style” does not exist in the Linux environment.
- There seems to be a font substitution that occurs during the process that generates the HTML. However, the “WarningCallback” feature does not notify that the substitution happens.
1. Create a Java class with the following code:
public static void main(String[] args) {
// assumes the Workbook is in the classpath
Workbook wb = new Workbook(“ColumnWidthsBug.xlsx”);
wb.getWorksheets().setActiveSheetIndex(0);
// export the worksheet
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
// use UTF-8 encoding
options.setEncoding(Encoding.getUTF8());
options.setHtmlCrossStringType(HtmlCrossType.DEFAULT);
options.setPresentationPreference(true);
options.setExportActiveWorksheetOnly(true);
options.setExportImagesAsBase64(true);
// implement anonymous callback class
IWarningCallback callback = new IWarningCallback() {
@Override
public void warning(WarningInfo info) {
System.out.println(info.getDescription());
}
};
options.setWarningCallback(callback);
// save HTML file to current folder
File file = new File(“ColumnWidthsBug_” +
System.getProperty(“os.name”).replace(’ ', ‘_’) +
“.html”);
try (FileOutputStream out = new FileOutputStream(file)) {
wb.save(out, options);
}
if (file.exists()) {
System.out.println("Successfully generated HTML file: " +
file.getAbsolutePath());
}
}
2. In a Windows environment, copy the attached Workbook file ‘ColumnWidthsBug.xlsx’ to a folder where the Java class is compiled.
3. Execute the Java class - it should produce an HTML file that represents the converted worksheet.
4. Repeat steps 2 and 3 but on a Linux environment. It is important that the Linux environment does not have the “Times New Roman” font available to the Aspose Cells library.
Summary of the issues:
- If you compare the text from two generated HTML files, you should see that the only deltas are related to the column widths. Note that the attached file ‘HTMLComparison.html’ contains a summary of the comparisons between the two HTNL files generated from my environments.
- You can visually see that the HTML generated in the Linux OS produces unexpected results with the text wrapping within the cells as well as elongated columns. As a visual reference see the screen shots from attached files “HtmlOutputLinux.jpg” and "
HtmlOutputWindows.jpg" - Note that although an IWarningCallback was implemented in the method, the “Times New Roman” font is not reported as being substituted. Since the “default font” (from the “Normal Style”) affects the “standard column width”, I would expect that the WarningCallback mechanism should report the font substitution during the conversion process.
Environment:
* Aspose Cells version 8.6.0
* Windows 7 64-bit (used to generate ‘ColumnWidthsBug_Windows_7.html’)
* Oracle Linux Server release 5.8 64-bit (used to generate ‘ColumnWidthsBug_Linux.html’)
Attachments:
- ColumnWidthsBugFiles.zip - contains:
- ColumnWidthsBug.xlsx: Workbook which is the source of the conversion to HTML
- ColumnWidthsBug_Windows_7.html: HTML file that was generated from my Windows 7 OS
- ColumnWidthsBug_Linux.html: HTML file that was generated from my Linux OS
- HTMLComparison.html : Comparison summary of the two HTML files above.