While we capturing the image from excel we are not getting perfectly closed to excel

HI @alexey.noskov
Hope you are doing well!!.

We are struggling with ASPOSE plugin. We need your help to fix an issue. While we capturing the image from excel and simply paste in word file, we are not getting perfectly closed to excel.

here is public repo of JAVA code : GitHub - ravikmr474/sample-aspose

When we capture image with above code on windows machine, here is the output:
windows sample.docx (167.2 KB)

When we capture image with above code on Linux machine(hosted on Linux server), here is the output:
linuxsample.docx (158.8 KB)

**When we just copy cells from excel file and just paste it simply as image on word file. Without any code/manually: This is our desired output.
ExpectedOutput.docx (22.4 KB)

Note: Just run the app and we have created /download end-point to fetch the word file.
We have added excel file in resource folder which we are reading to capture the image, in the above code.

@ravikmr474 Since you are using Aspose.Cells to convert Excel workbook to image, I will move your request into the appropriate forum. My colleagues from Aspose.Cells team will help you shortly.

@ravikmr474,

I checked your resource files. I could not notice any differences in the output images (pasted into Word document) when comparing with the original Excel sheet contents. The images generated by Aspose.Cells are identical to Excel spreadsheet. Even I compared the original Excel sheet (contents) with your expected output Word document (containing the pasted image (by Aspose.Cells)). I spotted double lined border (bottom) for one/two cells in Excel spreadsheet whereas your expected output document have thick (bottom) border line which is wrong (see the screenshot sc_shot1.png (126.8 KB) for your reference). In short, Aspose.Cells renders the spreadsheet to image ok similar to MS Excel’s original formatted data/contents. Could you please elaborate what’s wrong with the output images by Aspose.Cells API? Please highlight issues with details by encircling in red color while comparing original Excel sheet (shown in MS Excel) vs output image by Aspose.Cells API. We will understand your issue(s) and then evaluate it accordingly.

@amjad.sahi

My issue is that I am striving for uniformity in font size, font weight, and darkness across all three documents. However, I am encountering inconsistencies when attempting to replicate the appearance of the left document, which was created by manually copying Excel cells and pasting them as a picture in Word. Specifically, when I use ASPOSE cell to achieve this functionality, there are noticeable differences in the font’s appearance between the Linux and Windows versions of the resulting document, as shown in the images on the right.

Explanation.png (281.0 KB)

@ravikmr474,

Thanks for the screenshot and further details.

Do you mean the extracted image on Windows machine is ok and output image on Linux machine is not fine? Please make sure that Arial font (used in the workbook) is installed on linux machine. First, you need to install all the fonts (.ttf files) used in your Excel file on linux machine and then specify the font configurations via code at the start of your program (before using any other Aspose.Cells for Java API). See the document for your reference.

If you still find the issue, kindly do render to PDF file (you may add a line at the end to save to PDF) as well and provide the generated PDF file here, we will check it further.

@ravikmr474

Please capture Emf image from excel instead of jpg image. So the ImageOrPrintOptions options will be:

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.setOnePagePerSheet(true);
        options.setImageType(ImageType.EMF);
//      options.setImageType(ImageType.JPEG);
//      options.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//      options.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
//              RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//      options.setHorizontalResolution(200);
//      options.setVerticalResolution(200);
//      options.setTiffCompression(TiffCompression.COMPRESSION_LZW);
//      options.setQuality(100);
        options.setCheckWorkbookDefaultFont(true);
        options.setDefaultFont("Arial");

Also, when you insert the captured image to word file, please load the captured image file to bytes and insert it to word directly, instead of using the following code to resaving it again.

bout = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", bout);

Note: please remove your shared public github project, because your license file is exposed.

@ravikmr474

The code you used to set margin by POI:

XSSFWorkbook workbook = new XSSFWorkbook(excelFile);
XSSFSheet spreadsheet = workbook.getSheet("sheet_1_image");
spreadsheet.setMargin(Sheet.LeftMargin, 0.0);
spreadsheet.setMargin(Sheet.RightMargin, 0.0);
spreadsheet.setMargin(Sheet.TopMargin, 0.0);
spreadsheet.setMargin(Sheet.BottomMargin, 0.0);

Aspose.Cells can do it easily:

Workbook workbook = new Workbook(excelFile);
Worksheet worksheet = workbook.getWorksheets().get("sheet_1_image");
worksheet.getPageSetup().setLeftMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);

I don’t think it’s perfectly match on windows machine too. I want exact copy of manual copied images in word from excel.

@ravikmr474,

Please follow the instructions shared by @peyton.xu in his reply and let us know if you still have any issue.

We have tried same code still we are facing issue. Can you please add this code to given repo code and share screenshot with us?

We are just copying cells as picture image.png (44.4 KB)
and pasting it in word file, please check the below file. Screenshot and below file at both palace image is same. We need this functionality, please let us know if this is possible or not with ASPOSE library.
Copy_as_pic_excel.docx (15.2 KB)

@ravikmr474

To make thing be simple, you can use the following code to capture an Emf image, then manually insert it to Word file.
If you still have issue, please share us the result word file and screenshots to highlight the issue.

		Workbook workbook = new Workbook("My-excel.xlsx");
		FontConfigs.setDefaultFontName("Arial");
		workbook.calculateFormula();
		Style defaultStyle = workbook.getDefaultStyle();

		defaultStyle.getFont().setName("Arial");
		defaultStyle.getFont().setSize(10);
		defaultStyle.setTextWrapped(true);
		defaultStyle.getFont().setBold(false);
		workbook.setDefaultStyle(defaultStyle);
		
		workbook.getWorksheets().get(0).getPageSetup().setPrintArea("A5:B31");
		workbook.getWorksheets().get(0).getPageSetup().setLeftMargin(0);
		workbook.getWorksheets().get(0).getPageSetup().setRightMargin(0);
		workbook.getWorksheets().get(0).getPageSetup().setTopMargin(0);
		workbook.getWorksheets().get(0).getPageSetup().setBottomMargin(0);
		
		ImageOrPrintOptions options = new ImageOrPrintOptions();
		options.setOnePagePerSheet(true);
		options.setImageType(ImageType.EMF);
//		options.setImageType(ImageType.JPEG);
//		options.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//		options.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
//				RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//		options.setHorizontalResolution(200);
//		options.setVerticalResolution(200);
//		options.setTiffCompression(TiffCompression.COMPRESSION_LZW);
//		options.setQuality(100);
		options.setCheckWorkbookDefaultFont(true);
		options.setDefaultFont("Arial");
		
		SheetRender sr = new SheetRender(workbook.getWorksheets().get(0), options);
		sr.toImage(0, "output.emf");

Here is the word file that I insert the output Emf image manually into it:InsertGeneratedEmfimageManually.docx (23.2 KB)

Manually adding won’t work for me. We are automating this process. Can you please share what we need to write for insert the image in word file.

check in this document. There is two pages, in 1st one. I have added image after copying through Aspose cell by code. In second page I have added image manually just copying as image and paste on word document. I want 2nd page exact copy using your ASPOSE, please let me know can you provide me code of exact copy from excel and paste it in word doc using ASPOSE.
document (2).docx (153.9 KB)

@ravikmr474

There are two steps in your code:

  1. Capture image from Excel file
  2. Insert the captured image into Word file

First, we need to make sure the captured image is OK in first step. So I shared code to capture an Emf image, and let you insert the image into Word file manually.

Does the word file match your needs?

If yes, we can go to next step. e.g. You can require Aspose.Words to insert the captured Emf image by code.

Captured image is not exactly same I have applied image type EMF. Output after captured : image.png (110.5 KB) attaching screenshot cuz Can’t upload emf file type. What exactly I wanted image.png (84.3 KB)

@ravikmr474,

Please zip the EMF file and attach it here.

@ravikmr474

Please open the word file which you inserted the caputred Emf image(by Aspose.Cells) manually on one side, and open the word file which you copied as image from Excel and pasted the image manually on the other side. Share us screenshots that highlight the differences with side by side comparing.

By the way, which option do you select while you are copying range as picture? “As shown on screen” or “As shown when printed”?
screenshot_copy_as_picture.png (93.6 KB)

EMF file: emfFile.zip (12.0 KB)

document.docx (31.2 KB)

We have inserted EMF file in that document using aspose cell. It is coming with bold characters.

Our desired output
Doc3.docx (15.3 KB)

@ravikmr474

It seems that you set HorizontalResolution and VerticalResolution on ImageOrPrintOptions, please use the same option as I shared.

Also, which the option do you choose?

When we remove the resolution we are getting more worse picture. We are selecting cells from excel and paste it in word by press ctrl +c in word doc after that just ctrl+v on excel as image.png (45.5 KB) image but this job is manual process.