Excel Charts Are Scaled when Converted to EMF Images in C#

Here’s the one I used.
Chart_Template3.zip (766.7 KB)

@JThomas98,

Thanks for the template XLSM file.

I tested your scenario/case with Aspose.Cells for .NET v24.12. I used your template XLSM file and render two charts (“DetailChart_USEDTRANS” and “DetailChart_WEBMATS”) from DetailReport worksheet but I could not reproduce the issue you mentioned. I found no part of text before the charts is clipped.

Workbook book = new Workbook("e:\\test2\\Chart_Template3.xlsm");
Chart chart = book.Worksheets["DetailReport"].Charts["DetailChart_USEDTRANS"];
Chart chart1 = book.Worksheets["DetailReport"].Charts["DetailChart_WEBMATS"];
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
imageOptions.ImageType = ImageType.Png;
chart.ToImage("e:\\test2\\out_net1.png", imageOptions);
chart1.ToImage("e:\\test2\\out_net2.png", imageOptions);

out_net1.png (3.1 KB)
out_net2.png (3.0 KB)

Let us know if you find any issue with some other charts, which chart (from which worksheet(s))? Could you provide more details with sample code snippet to reproduce the issue on our end, we will check it soon.

Here are some test files I’ve used along with the code sample and outputs.
Charts 1, 2 & 3 are cases where the text is clipped.
Charts 4, 5 & 6 are cases where the text wrapping is different from what it is in excel.
Each of these files have a different template for you to see how it’s happening in all of these templates.
Template1.zip (1.1 MB)

Template2.zip (1.0 MB)

Template3.zip (1.1 MB)

string filePath = @"C:\Documents\Aspose Test\Template2\Chart_Template2.xlsm";
//Load the Excel file
Workbook workbook = new Workbook(filePath);
Chart chart1 = workbook.Worksheets["DetailReport"].Charts["DetailChart_USEDTRANS"];
Chart chart2 = workbook.Worksheets["DetailReport"].Charts["DetailChart_RATETRANS"];
Chart chart3 = workbook.Worksheets["DetailReport"].Charts["DetailChart_WEBMATS"];
Chart chart4 = workbook.Worksheets["DetailReport"].Charts["DetailChart_CPPR"];
Chart chart5 = workbook.Worksheets["DetailReport"].Charts["DetailChart_POPHLTH"];
Chart chart6 = workbook.Worksheets["DetailReport"].Charts["DetailChart_UM"];
ImageOrPrintOptions opts = new ImageOrPrintOptions
   {
        ImageType = ImageType.Png,
        VerticalResolution = 300,
        HorizontalResolution = 300,
        SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
        OnlyArea = true
   };
chart1.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net1.png", opts);
chart2.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net2.png", opts);
chart3.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net3.png", opts);
chart4.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net4.png", opts);
chart5.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net5.png", opts);
chart6.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net6.png", opts);

If VerticalResolution, HorizontalResolution, SmoothingMode and OnlyArea properties are not set, the text clipping is even more evident.

string filePath = @"C:\Documents\Aspose Test\Template2\Chart_Template2.xlsm";
//Load the Excel file
Workbook workbook = new Workbook(filePath);
Chart chart1 = workbook.Worksheets["DetailReport"].Charts["DetailChart_USEDTRANS"];
Chart chart2 = workbook.Worksheets["DetailReport"].Charts["DetailChart_RATETRANS"];
Chart chart3 = workbook.Worksheets["DetailReport"].Charts["DetailChart_WEBMATS"];
ImageOrPrintOptions opts = new ImageOrPrintOptions
   {
        ImageType = ImageType.Png
   };
chart1.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net1.png", opts);
chart2.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net2.png", opts);
chart3.ToImage(@"C:\Documents\Aspose Test\Template2\Out_net3.png", opts);

Out_net1.png (1.9 KB)

Out_net2.png (1.7 KB)

Out_net3.png (2.1 KB)

Hi @JThomas98
Thank you for providing the new template files. With these files, we are able to reproduce the issue.
We will prioritize solving the text clipped issue.

For the text wrapping issue, since there is no fixed standard line break position in Excel, it may occur when the percentage width on the right side is changed arbitrarily. We are sorry about this and we will continue to optimize to make it as good as possible.

@JThomas98
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-57418

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you. I was really looking forward to this getting fixed in the new version.

@JThomas98,

You are welcome. We will keep you informed about any updates regarding the issue (Ticket ID: “CELLSNET-57418”). We hope to resolve it soon.

Hi @JThomas98
For this issue, based on the 3 new files you provided, the images of all generated charts are as follows:
CELLSNET-57418_241214.zip (704.5 KB)

  1. Text clipped problem is fixed.
  2. About line breaks issue, we have conducted research and testing. Since there is no fixed standard for line break positions, currently it is difficult to match every Excel’s line break positions. We have made adjustments as much as possible, and currently, the error in line break positions is within one word.

Let me go through each of these inputs and find out if everything’s looking alright. In terms of the text wrapping, I understand the situation. As long as it’s not a huge difference, I can work with it. Thanks.

@JThomas98,

Sure, feel free to take your time assessing the results (images) to see if they meet your expectations. Your feedback is valued.

1 Like

I’ve gone through all of the charts you’ve shared and I can confirm that it’s what I’m expecting. Thank you for sharing these. The next release is in January only, right?

@JThomas98
Thank you for your feedback. You’re right. Aspose.Cells for .NET v25.1 will be released in the first half of January 2025. You will be notified when the next version is released.

@JThomas98,

However, if you require an interim or quick fix, you might be able to obtain it if you have Paid Support Services.

The issues you have found earlier (filed as CELLSNET-57418) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Hey Aspose Team,
Unfortunately, I have another issue that’s come up. The chart called DetailChart_COMPLAN has a text alignment issue.

TextAlignmentIssue.jpg (252.7 KB)

If you look at the screenshot I’ve shared, you’ll notice that the labels on the y-axis seem to be more right aligned in excel where as in aspose’s output, it seems to center aligned. Another thing is that the text that take up only one line, they seem to look alright. Not sure why the text that is wrapped into 2 or more lines have a different alignment.

@JThomas98
We can reproduce the issue in “Chart_Template1.xlsm”, “Chart_Template2.xlsm”, “Char_Template3.xlsm” as you mentioned, Y-axis labels alignment is wrong when it is more than one line.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-57730

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @JThomas98
For the issue CELLSNET-57730 ( Y-axis labels alignment is wrong when it is more than one line), our optimized results are as follows, which will take effect in version 25.2.
250205.png (53.2 KB)

Okay, its looking better. Thanks.

@JThomas98,

We appreciate your input. We will update you on the new version as soon as it is released.

The issues you have found earlier (filed as CELLSNET-57730) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi