We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

WordArt's Style is missing after conversion to HTML format

Hi Aspose team

We have a Excel file that we converted to HTML format with Aspose Cells 8.9.0, and we found that the output image from the WordArt in the Excel lost its style.

Here are our methods to modify Workbook for better viewing:
protected 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 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();
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 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 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);
// set to Text
dataCell.getStyle().setNumber(49);
}
}
}
}

And here is the code for conversion test:
Workbook book = new Workbook(“custom/input/xlsx/XL_007_1.xlsx”);
this.addEmptyColumn(book);
this.addColRowHeader(book);
this.addColRowHeaderStyle(book);
this.fixCellStyle(book);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

// for one sheet output only
for (int i = 0; i < book.getWorksheets().getCount(); i++) {
if (i != 0) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setExportHiddenWorksheet(false);
saveOps.setClearData(false);
saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
// true for single html only
saveOps.setExportImagesAsBase64(true);
// false for saving image
//saveOps.setExportImagesAsBase64(false);

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(
“custom/output/xlsx/” + 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(
“custom/output/xlsx/stream.html”));


Is there any option to make the image of WordArt after conversion more like the original in the Excel file?
I 've uploaded the Excel file, the result, and the comparison image. Please check this and thanks for your help :slight_smile:

Best,
Craig

Hi Graig,

Thank you for sharing the sample spreadsheet.

Please note, the current set of Aspose.Cells APIs do not support rendering the gradient fill for the shapes including WordArt, that is the reason, the colors of the text in WordArt are rendering as plain black in resultant HTML. I have logged a feature request in this regard with Id CELLSJAVA-41950. Please spare us little time for the feasibility analysis. In the meanwhile, we will keep you posted with updates in this regard.

Hi,


Please try our latest version/fix: Aspose.Cells for Java v16.12.5

We have fixed your issue now.

Let us know your feedback.

Thank you.

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


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

Hi Amjad.Sahi


I tried Cells 17.1.0, and this WordArt can be rendered correctly.
Thanks for fixing this issue :slight_smile:

Craig

Hi,


Thanks for your feedback.

Good to know that your issue is sorted out by the new version/fix. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.