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();
}
}
}