Text on image disappeared in the result of conversion to HTML

Hi Aspose team

We are using Aspose Cells 8.8.3 to convert Excel to HTML format in Linux environment for cross-platform viewing.
And we found a problem in a Excel file’s conversion result that there are some text on image disappeared in the HTML result.

Here is our code for conversion test:
Workbook book = new Workbook(“2016VVV1.xls”);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

addEmptyColumn(book);
addColRowHeader(book);
addColRowHeaderStyle(book);
fixCellStyle(book);

// for ony one page output
for (int i = 0; i < book.getWorksheets().getCount(); i++) {
if (i != 1) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setExportHiddenWorksheet(false);

// for saving images
// saveOps.setExportImagesAsBase64(false);
// for viewing as one file
saveOps.setExportImagesAsBase64(true);

final Map<String, byte[]> resourceMap = new HashMap<String, byte[]>();
saveOps.setStreamProvider(new IStreamProvider() {

@Override
public void initStream(StreamProviderOptions arg0) throws Exception {
arg0.setStream(new ByteArrayOutputStream());
}

@Override
public void closeStream(StreamProviderOptions arg0)
throws Exception {
System.out.println(arg0.getDefaultPath());
OutputStream stream = arg0.getStream();
if (stream instanceof ByteArrayOutputStream) {
ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
IOUtils.write(bb.toByteArray(), new FileOutputStream(
“” + arg0.getDefaultPath()));
}
String fileName = arg0.getDefaultPath().substring(
arg0.getDefaultPath().lastIndexOf(’/’) + 1);
resourceMap.put(fileName, ((ByteArrayOutputStream) arg0
.getStream()).toByteArray());
}
});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(), new FileOutputStream(
“stream.html”));

And these are our methods to make the result more like the Excel shows in MS Office:

protected static void addEmptyColumn(Workbook book) {

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
Worksheet sheet = book.getWorksheets().get(i);
int columns = sheet.getCells().getMaxDisplayRange()
.getColumnCount();
if (columns > 0) {
sheet.getCells().insertColumn(columns);
sheet.getCells()
.clearRange(
0,
columns,
sheet.getCells().getMaxDisplayRange()
.getRowCount() - 1, columns);
sheet.getCells().getColumns().get(columns).setWidth(8.5);
}
}
}

protected static void addColRowHeader(Workbook book) {

for (int i = 0; i < book.getWorksheets().getCount(); i++) {

Worksheet sheet = book.getWorksheets().get(i);

StyleFlag styleFlagGrid = new StyleFlag();
styleFlagGrid.setBorders(true);

sheet.getCells().insertColumn(0);
sheet.getCells().insertRow(0);

sheet.getCells().getRows().get(0).setHeight(15.75);
sheet.getCells().getColumns().get(0).setWidth(4.75);

int maxRow =
// sheet.getCells().getMaxRow();
sheet.getCells().getMaxDisplayRange().getRowCount();
// sheet.getCells().unhideRows(0, maxRow, 15.75);
int maxCol =
// sheet.getCells().getMaxColumn();
sheet.getCells().getMaxDisplayRange().getColumnCount();

for (int j = 1; j < maxRow; j++) {
sheet.getCells().get(j, 0).putValue(j);
}
for (int k = 1; k < maxCol; k++) {
sheet.getCells().get(0, k)
.putValue(CellsHelper.columnIndexToName(k - 1));
}
}
}

protected static void addColRowHeaderStyle(Workbook book) throws Exception {

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
Worksheet sheet = book.getWorksheets().get(i);

StyleFlag styleFlagHeader = new StyleFlag();
styleFlagHeader.setAll(true);

Style headerStyle = book.createStyle();
headerStyle.setForegroundColor(Color.fromArgb(238, 238, 238));
headerStyle.setPattern(BackgroundType.SOLID);
headerStyle.getFont().setBold(true);
headerStyle.setVerticalAlignment(1);
headerStyle.setHorizontalAlignment(1);
headerStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
headerStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
headerStyle.setBorder(BorderType.BOTTOM_BORDER,
CellBorderType.THIN, Color.fromArgb(204, 204, 204));
headerStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN,
Color.fromArgb(204, 204, 204));

int maxRow = sheet.getCells().getMaxRow();
int maxCol = sheet.getCells().getMaxColumn();

for (int k = 0; k <= maxRow; k++) {
sheet.getCells().get(k, 0)
.setStyle(headerStyle, styleFlagHeader);
}
for (int j = 0; j <= maxCol; j++) {
sheet.getCells().get(0, j)
.setStyle(headerStyle, styleFlagHeader);
}
}
}

protected static void fixCellStyle(Workbook book) {

StyleFlag styleFlagGrid = new StyleFlag();
styleFlagGrid.setBorders(true);

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
Worksheet sheet = book.getWorksheets().get(i);
int maxRow = sheet.getCells().getMaxRow();
int maxCol = sheet.getCells().getMaxColumn();

for (int datai = 0; datai <= maxRow; datai++) {

for (int datay = 0; datay <= maxCol; datay++) {

Cell dataCell = sheet.getCells().get(datai, datay);
Style dataStyle = dataCell.getStyle();

if (dataStyle.getBorders()
.getByBorderType(BorderType.LEFT_BORDER)
.getLineStyle() == 0) {
dataStyle.setBorder(BorderType.LEFT_BORDER,
CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
}
if (dataStyle.getBorders()
.getByBorderType(BorderType.RIGHT_BORDER)
.getLineStyle() == 0) {
dataStyle.setBorder(BorderType.RIGHT_BORDER,
CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
}
if (dataStyle.getBorders()
.getByBorderType(BorderType.BOTTOM_BORDER)
.getLineStyle() == 0) {
dataStyle.setBorder(BorderType.BOTTOM_BORDER,
CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
}
if (dataStyle.getBorders()
.getByBorderType(BorderType.TOP_BORDER)
.getLineStyle() == 0) {
dataStyle.setBorder(BorderType.TOP_BORDER,
CellBorderType.THIN,
Color.fromArgb(204, 204, 204));
}
dataCell.setStyle(dataStyle, styleFlagGrid);
dataCell.getStyle().setNumber(49);
}
}
}
}

I 've uploaded comparison images, the Excel file, and the result of sheet2 (image base64).
It actually happens in sheet 2, 3, 17, and 19.

Is there something to fix this?
Please check the attachment and help us to save this problem, thank you

Best,
Craig


Hi Craig,


Thank you for sharing the samples.

I have evaluated the presented scenario while using the latest revision of Aspose.Cells for Java 8.9.2.3 (attached), and I am not able to replicate the said issue. Please check the attachment for the resultant HTML files for worksheets 2, 3, 17 & 19. Please give the latest version a try on your side and let us know your feedback.

Hi Babar.Raza


Thank you for the information.
This problem can be fixed with Cells 8.9.2.3.

Hi,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.