Create EMF image from Excel workwook with Aspose.Cells for Java API

Hi all,
I try to take an EMF image from Excel area using Aspose Cells version 19.10 and insert it into a Word document using Aspose Words 19.10.
When I open the document with MS Word, I can’t see some borders, for example double borders.
While if I do the same task with PNG image, there are no problems.
I attach a little example project.

asposeTests.zip (128.1 KB)

Could you help me, please?

Thanks,
Giulio

This is the code:

import com.aspose.cells.ImageOrPrintOptions;

import com.aspose.cells.ImageType;
import com.aspose.cells.PageSetup;
import com.aspose.cells.SheetRender;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.Shape;
import com.aspose.words.ShapeType;
import com.aspose.words.WrapType;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.junit.Test;

public class excelAreaToWord {

public static final String PRINT_AREA = “C2:G16”;
public static final String INPUT_REPORT = “source.xlsx”;
public static final String TEST_RESOURCES_PATH = “src/test/test-resources/”;
public static final String IMAGE_EMF = “image.emf”;
public static final String OUTPUT_EMF = “outputEMF.docx”;
public static final String IMAGE_PNG = “image.png”;
public static final String OUTPUT_PNG = “outputPNG.docx”;

@Test
public void testEMFBorders() {
try {
FileOutputStream inOutStream = new FileOutputStream(TEST_RESOURCES_PATH + IMAGE_EMF);
InputStream inputStream = this.getClass().getResourceAsStream(INPUT_REPORT);
Workbook input = new Workbook(inputStream);
Worksheet ws = input.getWorksheets().get(1);
PageSetup pageSetup = ws.getPageSetup();
pageSetup.setPrintArea(PRINT_AREA);
pageSetup.setLeftMargin(0.0);
pageSetup.setRightMargin(0.0);
pageSetup.setTopMargin(0.0);
pageSetup.setBottomMargin(0.0);
pageSetup.setPrintQuality(1200);
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setImageType(ImageType.EMF);
opts.setOnePagePerSheet(false);
opts.setOnlyArea(true);
SheetRender renderer = new SheetRender(ws, opts);
renderer.toImage(0, inOutStream);
inOutStream.flush();
inOutStream.close();
InputStream imageInputStream = this.getClass().getResourceAsStream(IMAGE_EMF);
Document outputDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(outputDoc);
Shape linkedOnly = new Shape(outputDoc, ShapeType.IMAGE);
linkedOnly.setHeight(100);
linkedOnly.setWidth(500);
linkedOnly.setWrapType(WrapType.INLINE);
linkedOnly.getImageData().setImage(imageInputStream);
builder.insertNode(linkedOnly);
builder.writeln();
builder.setDocument(outputDoc);
outputDoc.save(TEST_RESOURCES_PATH + OUTPUT_EMF);

} catch (Exception e) {
  e.printStackTrace();
}

}

@Test
public void testPNGBorders() {
try {
FileOutputStream inOutStream = new FileOutputStream(TEST_RESOURCES_PATH + IMAGE_PNG);
InputStream inputStream = this.getClass().getResourceAsStream(INPUT_REPORT);
Workbook input = new Workbook(inputStream);
Worksheet ws = input.getWorksheets().get(1);
PageSetup pageSetup = ws.getPageSetup();
pageSetup.setPrintArea(PRINT_AREA);
pageSetup.setLeftMargin(0.0);
pageSetup.setRightMargin(0.0);
pageSetup.setTopMargin(0.0);
pageSetup.setBottomMargin(0.0);
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setImageType(ImageType.PNG);
opts.setOnePagePerSheet(true);
opts.setOnlyArea(true);
opts.setHorizontalResolution(220);
opts.setVerticalResolution(220);
SheetRender renderer = new SheetRender(ws, opts);
renderer.toImage(0, inOutStream);
inOutStream.flush();
inOutStream.close();
InputStream imageInputStream = this.getClass().getResourceAsStream(IMAGE_PNG);
Document outputDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(outputDoc);
Shape linkedOnly = new Shape(outputDoc, ShapeType.IMAGE);
linkedOnly.setHeight(100);
linkedOnly.setWidth(500);
linkedOnly.setWrapType(WrapType.INLINE);
linkedOnly.getImageData().setImage(imageInputStream);
builder.insertNode(linkedOnly);
builder.writeln();
builder.setDocument(outputDoc);
outputDoc.save(TEST_RESOURCES_PATH + OUTPUT_PNG);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@giulio.andolfi,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-43035 – Borders are lost while converting Excel file to EMF

Thanks for your replay.
I wait for your feedback.
Regards,
Giulio

@giulio.andolfi,

Sure, once we sort out the issue or have new information available, we will let you know.

@giulio.andolfi,
This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-43035”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Hi @ahsaniqbalsidiqui,
our customers are pressing to know when we fix their problems.
Indicatively you can let us know in which patch and when the CELLSJAVA-43035 will be released?
Thanks

@giulio.andolfi,
This issue is resolved and will be part of next regular release in the third week of November 2019. We will notify you here once this new version is published after the QA and the release process.

@giulio.andolfi,
Please try our latest version/fix: Aspose.Cells for Java v19.10.4:

aspose-cells-19.10.4.zip (6.6 MB)

Your issue should be fixed in it.

Let us know your feedback.

Thanks @ahsaniqbalsidiqui.
We try the patch and let you know as soon as possible.

@giulio.andolfi,

Sure, take your time to evaluate the issue fix/version. Hopefully it will resolve the issue.

Hi all,
we tested your patch and our problem is fixed.
Thanks for the support.
We wait the official release.
Regards,
Giulio

@giulio.andolfi,

Good to know that your issue is sorted out by the new fix/version. Feel free to write us back if you have further comments or questions, we will be happy to assist you soon.

The issues you have found earlier (filed as CELLSJAVA-43035) have been fixed in Aspose.Cells for Java v19.11. This message was posted using Bugs notification tool by ahsaniqbalsidiqui