Transfer Excel Range formatting to word Table formatting

appreciate the help, thanks!

@Adhirath
The layout of charts in Excel and Word is different
A chart in Excel floats above a cell and does not occupy the position of the cell.
But the chart in Word is on the page and occupies a cell position.
So how to layout is a rather complex issue.

can we insert it inside the cell and get the ooxml which can be pasted into word?

@Adhirath
image.png (6.2 KB)

If you can float the chart above merged cells in the template file as the attached image, we can ignore the issue of layout .

as long as I get the OOXMl it’s fine. I can extract the ooxml from within the table no issue, is there a way to do the same currently?

@Adhirath

  1. We do not support exporting editable chart to word now. We are currently evaluating this feature.
  2. In Word file, there are 3 parts for a chart: drawing info in document.xml, chart.xml and an embedded xlsx .

got you, a different query I have is ca I improve the image quality when getting an image using imageorprintoptions or chart.toImage etc but without changing the dpi as that ends up resizing the image.
This code resizes the image while improving the quality, i want the quality but dont want the image being resized-
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions()
{
VerticalResolution = 400,
ImageType = ImageType.Png,
HorizontalResolution = 400,
};
using (MemoryStream ms = new MemoryStream())
{
chart.ToImage(ms, imgOptions);

This gives the correc tsize for the image but the quality is not that great-
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions()
{
ImageType = ImageType.Png,
};

using (MemoryStream ms = new MemoryStream())
{
chart.ToImage(ms, imgOptions);

@Adhirath,

I think you may try to use EMF image format, it will give you maximum quality and you don’t really need to set resolutions if it works for your needs.

does it allow transparent backgrounds?

@Adhirath
Because EMF format can store transparency information, EMF can support transparent backgrounds. If you still have any questions, please provide us with your sample files and test code, and we will check them soon.

@Adhirath
dest.docx (23.1 KB)

Now we can export the chart words as the attached file.
There is still an issue that each chart refers a different Excel file which only contains data source of the chart. But now we simply export whole original Excel file to docx. We are still working on changing this behavior, you can check whether the chart in the attached file is your excepted.

perfect, just what I wanted! Can I use this feature?

so the issue I am facing with emf format is the formatting and spacing change slightly-
this is an emf format image-
image.png (61.4 KB)

this is the actual image-
image.png (18.7 KB)

@Adhirath
By inserting PNG images into Excel and testing them on the latest version v25.3 using the following sample code, we can obtain the correct results. Please refer to the attachment. result.zip (67.0 KB)

Workbook wb = new Workbook(filePath + "test.xlsx");
Picture picture = wb.Worksheets[0].Pictures[0];
picture.ToImage(filePath + "out_net.emf", new ImageOrPrintOptions { ImageType = ImageType.Emf });

If you still have questions, would you like to provide your sample files and test code? We will check it soon.

yeah I have the older version maybe that’s why. can you try it with v24.7?

@Adhirath
Test on v24.7 using the provided sample file and the following sample code, we can obtain the correct result. Please refer to the attachment. out_net_24.7.zip (40.8 KB)

Workbook wb = new Workbook(filePath + "test.xlsx");
Picture picture = wb.Worksheets[0].Pictures[0];
picture.ToImage(filePath + "out_net_24.7.emf", new ImageOrPrintOptions { ImageType = ImageType.Emf });

I see, well I am trying to do Chart.ToImage not Picture.ToImage. that is somehow causing the issue. Can you try creating a chart and then do a chart.ToImage with image type as Emf. That should give the same image.

@Adhirath
By creating sample file and testing them on the v25.3 and v24.7 using the following sample code, we can obtain the correct results. Please refer to the attachment. out_chart.zip (22.1 KB)

Workbook wb = new Workbook(filePath + "sample.xlsx");
Chart chart = wb.Worksheets[0].Charts[0];
chart.ToImage(filePath + "out_chart_24.7.emf", new ImageOrPrintOptions { ImageType = ImageType.Emf });

If you still have questions, would you like to provide your sample files and test code? We will check it soon.

Hi guys I had a question, is there a way to copy a range and save the copied range with all the formatting etc. Then later paste the copied range using js api. Is that a possibility?

@Adhirath
Please use Aspose.Cells for Node.js via C++ to implement your needs. About how to manage ranges, please refer to the following documents.

1 Like