HTML Output Produces Unpredictable Results

The conversion of a named range to HTML is producing inconsistent and unpredictable results. It seems as though when saving a named range as HTML from two different workbooks, some of the information from the first workbook is cached and persisted onto the HTML from the second workbook.

Perhaps the best way to describe this behavior is via an example. In the attached zip file, examine the “HtmlExportBug.java” file. Looking at the main method which has the following code:

public static void main(String[] args) {
int seq = 1;
if (args != null && args.length > 0 && args[0] != null) {
seq = “2”.equals(args[0]) ? 2 : 1;
}

String path = HtmlExportBug.class.getProtectionDomain().
getCodeSource().getLocation().getPath();
path = new File(path).getAbsolutePath() + File.separator;

String xlFile1, xlFile2, name1, name2, outFile1, outFile2;
if (seq == 1) {
// first generate HTMl from Simple1.xlsx then Simple2.xslx
xlFile1 = path + “Simple1.xlsx”;
xlFile2 = path + “Simple2.xlsx”;
name1 = “Sheet1!PRINT_AREA”;
name2 = “Pie_Chart_Data”;
outFile1 = path + “Simple1_seq1.html”;
outFile2 = path + “Simple2_seq1.html”;
} else {
// first generate HTMl from Simple2.xlsx then Simple1.xslx
xlFile1 = path + “Simple2.xlsx”;
xlFile2 = path + “Simple1.xlsx”;
name1 = “Pie_Chart_Data”;
name2 = “Sheet1!PRINT_AREA”;
outFile1 = path + “Simple2_seq2.html”;
outFile2 = path + “Simple1_seq2.html”;
}

System.out.println("Running sequence " + seq + ":\n 1st File: " +
xlFile1 + "\n 2nd File: " + xlFile2);

HtmlExportBug.getHtml(xlFile1, name1, outFile1);
HtmlExportBug.getHtml(xlFile2, name2, outFile2);

System.out.println("Completed output of:\n " + outFile1 +
"\n " + outFile2);

}

As you can see:

  • The HTML is being produced by the same method (“getHtml”)
    and
  • The same two files (Simple1.xslx & Simple2.xlsx) are being used
The only difference is the sequence in which the HTML is generated between the two files. When “1” is passed into the main method - Simple1 is generated first then Simple2. When “2” is passed into the main method Simple2 is generated first, then Simple1.

We have observed that if you compare the output HTML after running sequence 1 and 2, the HTML output is different. Specifically, it seems that the some data from the first file is carried over to the HTML output of the second file.

To run the sample program and reproduce this behavior:
  1. Detach the contents of the attached zip file to any folder.
  2. Run the HtmlExportBug class by passing 1 as a parameter. For example:
    java -cp %CD%;aspose-cells-8.6.3.jar HtmlExportBug 1
    This should produce the files "Simple1_seq1.html’ and "Simple2_seq1.html
  3. Run the HtmlExportBug class again, but pass 2 as a parameter this time. For example:
    java -cp %CD%;aspose-cells-8.6.3.jar HtmlExportBug 2
    This should produce the files "Simple1_seq2.html’ and "Simple2_seq2.html
  4. Perform a file comparison of the contents of Simple1_seq1.html to Simple1_seq2.html
    and additionally Simple2_seq1.html to Simple2_seq2.html.
    Ignore the deltas in the “” nodes, but you should see that there are differences when it comes to the named ranges that were converted to HTML.
Our expectation is that both sequences should produce the same HTML.
This was observed under Aspose Cells 8.6.3

Thanks.

Hi,


Thank you for providing the detail problem description and the samples for our testing.

We have evaluated the presented scenario while using Aspose.Cells for Java 8.6.3.2, and we are able to notice the said problem. Please note, we have compared all the HTML files generated in sequence 1 against the files generated in sequence 2, and the most noticeable difference is in the HTML files for the sample1.xlsx where one of the HTML files (generated in sequence 2) seems to be referencing a Named Range as “Pie_Chart_Data” which is not available in sample1.xlsx but in sample2.xlsx. Please check the attached snapshots for the comparison of the HTML files.

In order to further investigate the matter, we have logged this incident as CELLSJAVA-41676 in our bug tracking system, and have requested the concerned member of the product team to schedule its analysis at earliest possible. Please spare us little time to look further into this matter. In the meanwhile, we will keep you posted with updates in this regard.

Hi,

Thanks for using Aspose.Cells.

Please download and use the latest version: Aspose.Cells for Java (Latest Version) it generates correct results.

We have tested this issue with the latest version using the following code and output html files are correct. I have also attached the code file for your reference.

Java

import com.aspose.cells.Cells;
import com.aspose.cells.CellsHelper;
import com.aspose.cells.Encoding;
import com.aspose.cells.HtmlCrossType;
import com.aspose.cells.HtmlHiddenColDisplayType;
import com.aspose.cells.HtmlHiddenRowDisplayType;
import com.aspose.cells.HtmlSaveOptions;
import com.aspose.cells.Name;
import com.aspose.cells.NameCollection;
import com.aspose.cells.Range;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class HtmlExport
{

public static void main(String[] args)
{
System.out.println(CellsHelper.getVersion());
run41676(1);
run41676(2);
}
private static void run41676(int seq)
{
String path = “D:\Downloads\x\y\”;

String xlFile1, xlFile2, name1, name2, outFile1, outFile2;
if (seq == 1) {
// first generate HTMl from Simple1.xlsx then Simple2.xslx
xlFile1 = path + “Simple1.xlsx”;
xlFile2 = path + “Simple2.xlsx”;
name1 = “Sheet1!PRINT_AREA”;
name2 = “Pie_Chart_Data”;
outFile1 = path + “Simple1_seq1.html”;
outFile2 = path + “Simple2_seq1.html”;
} else {
// first generate HTMl from Simple2.xlsx then Simple1.xslx
xlFile1 = path + “Simple2.xlsx”;
xlFile2 = path + “Simple1.xlsx”;
name1 = “Pie_Chart_Data”;
name2 = “Sheet1!PRINT_AREA”;
outFile1 = path + “Simple2_seq2.html”;
outFile2 = path + “Simple1_seq2.html”;
}

System.out.println("Running sequence " + seq + ":\n 1st File: " +
xlFile1 + "\n 2nd File: " + xlFile2);

getHtml(xlFile1, name1, outFile1);
getHtml(xlFile2, name2, outFile2);

System.out.println("Completed output of:\n " + outFile1 +
"\n " + outFile2);
}
/**
* Generates HTML from the given named range within the given Excel workbook and
* saves the HTML as a file in the current folder.
*
* @param xlFile full path to the Excel file.
* @param xlRange String representing the named range to be converted to HTML
* @param outFile full path of output file.
*/
private static void getHtml(String xlFile, String xlRange, String outFile) {

try {
Workbook wb = new Workbook(xlFile);
NameCollection names = wb.getWorksheets().getNames();
Name name = names.get(xlRange);

Range rng = name.getRange();
Worksheet sheet = rng.getWorksheet();
Cells cells = sheet.getCells();
int firstCol = rng.getFirstColumn();
int firstRow = rng.getFirstRow();
int maxCol = cells.getMaxDisplayRange().getColumnCount();
int maxRow = cells.getMaxDisplayRange().getRowCount();

// hide all the rows and columns that are not part of the range
if (firstCol > 0) {
cells.hideColumns(0, firstCol - 1);
}
if (firstCol + rng.getColumnCount() < maxCol) {
cells.hideColumns(firstCol + rng.getColumnCount(), maxCol);
}
if (firstRow > 0) {
cells.hideRows(0, firstRow - 1);
}
if (firstRow + rng.getRowCount() < maxRow) {
cells.hideRows(firstRow + rng.getRowCount(), maxRow);
}

wb.getWorksheets().setActiveSheetIndex(sheet.getIndex());

// export the worksheet
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setEncoding(Encoding.getUTF8());
options.setHtmlCrossStringType(HtmlCrossType.CROSS);
options.setPresentationPreference(true);
options.setExportHiddenWorksheet(false);
options.setExportActiveWorksheetOnly(true);
options.setExportImagesAsBase64(true); // aovids the temp folder
options.setCreateDirectory(false);
options.setExpImageToTempDir(false);
options.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);

wb.save(outFile, options);

} catch (Exception ex) {
System.out.println("Unexpected exception: " + ex.getMessage());
ex.printStackTrace();
}
}
}

Hi Shakeel,

Thank you for your prompt response and for providing the latest Cells version (8.6.3.4). Unfortunately, I am still seeing some inconsistencies between the generated HTML files using the new version. The key deltas in the output are:

  • In Simple1_seq1.html, there is an anchor ("") node with the
    name “PRINT_AREA” which does not exist in Simple1_seq2.html
  • In Simple1_seq2.html, there is an anchor node with the name “Pie_Chart_Data” which does not exist in Simple1_seq1.html
  • In Simple2_seq2.html, there is an anchor node with the name “Pie_Chart_Data” which does not exist in Simple2_seq1.html
  • In Simple2_seq2.html, there is an “” node which does not exist in Simple2_seq1.html
I’m not sure why you’re not seeing these results, but I should point out that in unlike the test code you provided above - my tests run sequence 1 and sequence 2 in a separate Java process. I believe this is important because it seems that the HtmlSaveOptions class is somehow holding on to some data from the very first export (i.e. when the class becomes instantiated). By running the two sequences in a separate Java process, we’re ensuring that the HtmlSaveOptions class is in its un-instantiated state in the first run.

I should also note that I reproduced the issue (with the same results) under the following environments:
  • Windows 7 running Java 1.7.0_85
  • Linux 5 running 1.7.0_85
Thanks.

Hi,


Thank you for writing back and sorry for the inconvenience.

Please note, the said problem does not occur when the conversion process (both sequences) are executed in a single process as you have mentioned it, however, the problem is reproducible if both sequences are executed in separate processes. I have already updated the ticket with these observations, and have requested the concerned member of the product team to schedule the analysis accordingly. We will share the analysis results as soon as we have completed the preliminary investigation.

Note: I have reevaluated the scenario under Windows 10 x64 against JDK 1.8.0_66 & Aspose.Cells for Java 8.6.3.4.

Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSJAVA-41676 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Hi,

Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for Java v8.6.3.6 and let us know your feedback.

Hi Shakeel,

The Aspose.Cells version 8.6.3.6 you provided works well! I got the expected results in my environment.

May I assume that the fix will be part of the next official Cells release (8.6.4)?

Thanks for your help.
- Carlos

Hi Carlos,


Thank you for the confirmation. It is good to know that you are up & running again. Yes, this fix will be part of the next official release of Aspose.Cells for Java, which is scheduled for the up coming week.

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


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