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

@andrey.potapov,
I’ve run into another issue. The charts I’ve captured and inserted into the slide looks like its scaled somehow.
The code I’ve used is:

public virtual bool CopyExcelChartToSlide_Aspose(Workbook wkBook, string excelSheet, string chartName, Presentation slideDeck, int slideNumber, float horizCoord, float vertCoord)
        {
            bool RetVal = true;
            string msg, FullChartName;
            Worksheet WkSheet = null;
            Aspose.Cells.Charts.ChartCollection AllExcelCharts = null;
            Aspose.Cells.Charts.Chart ExcelChart = null;
            //ExcelNS.Workbook WkBook = null;
            ISlide NextSlide = null;
            string Prefix = "\t";
            const float ScaleFactor = 70;
            try
            {
                //Get the Excel chart with the specified name
                WkSheet = wkBook.Worksheets[excelSheet];

                AllExcelCharts = wkBook.Worksheets[excelSheet].Charts;
                ExcelChart = AllExcelCharts
                                    .OfType<Aspose.Cells.Charts.Chart>()
                                    .Where(p => p.Name.ToLower() == chartName.ToLower())
                                    .FirstOrDefault();
                //If the specified chart name exists, then attempt to copy it to the slide
                //Get the slide whose index is specified
                NextSlide = slideDeck.Slides[slideNumber - 1];
                if (ExcelChart != null)
                {
                    using (MemoryStream ImgStream = new MemoryStream())
                    {
                        Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions
                        {
                            ImageType = Aspose.Cells.Drawing.ImageType.OfficeCompatibleEmf,
                            VerticalResolution = 300,
                            HorizontalResolution = 300,
                            OnlyArea = true
                        };
                        ExcelChart.ToImage(ImgStream, opts);
                        if(!ImgStream.Equals(default(MemoryStream)))
                        {
                            ImgStream.Seek(0, SeekOrigin.Begin);
                            IPPImage InsertImg = slideDeck.Images.AddImage(ImgStream);
                            NextSlide.Shapes.AddPictureFrame(ShapeType.Rectangle, horizCoord * ScaleFactor, vertCoord * ScaleFactor, ExcelChart.ChartObject.Width * (ScaleFactor / 100), ExcelChart.ChartObject.Height * (ScaleFactor / 100), InsertImg);
                        }
                        else
                        {
                            RetVal = false;
                            msg = $"Failed to save the chart { chartName} to memory stream";
                            this.OnPPTEventOccurred(msg);
                        }
                    }
                }
                else
                {
                    //Specified chart does not exist
                    RetVal = false;
                    msg = $"The chart {FullChartName} was not found";
                    this.OnPPTEventOccurred(msg);
                }

            }
            catch (Exception ex)
            {
                msg = $"An error occurred while attempting to copy the chart {chartName} to the slidee #{slideNumber}\r\n"
                    + $"Details: {ex.Message}";
                this.OnPPTEventOccurred(msg);
            }
            return RetVal;
        }

Here’s the file’s I’ve used:
SlidesTest.zip (792.0 KB)

@JThomas98,
It will take me some time to sort out your problem. I will get back to you soon.

1 Like

@JThomas98,
Thank you for your patience. I’ve performed some research and found that the issue is related to Aspose.Cells. I’ve moved this thread to Aspose.Cells forum. My colleagues will get back to you shortly.
@amjad.sahi FYI

@JThomas98
By using sample files and the following test code for testing, we can reproduce the issue. Found that excel charts are scaled when converted to EMF images. Please refer to the attachment. chart.zip (3.2 KB)

Workbook wb = new Workbook(filePath + "Chart.xlsm");
Chart chart = wb.Worksheets["MedicareCharts"].Charts["Q007"];
chart.ToImage(filePath + "chart.emf", ImageType.Emf);

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-56645

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 for redirecting it.

Thank you for confirming this, @John.He. Looking forward to the fix.

@JThomas98,

We will try to figure out your issue soon. Once we have an update on the issue (Ticket ID: “CELLSNET-56645”), we will let you know.

Hi @JThomas98
For this problem, we have optimized, part of the image file is as follows.
240906.zip (2.3 MB)

We solved the problem that the newline position was too different from Excel.
Since there is no fixed standard for the position of line breaks, and Excel may have some newline logic that we are not able to know. this revision is intended to be as Excel as possible. However, there may be individual cases where there may be a one-word difference in the position of line breaks.

That’s looking good.

@JThomas98,

Thank you for your feedback. The enhancement/fix will hopefully be included in the upcoming release of Aspose.Cells v24.9, which is scheduled for this week.

Please stay tuned!

1 Like

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

Hi, Aspose Team
Even though the issue with the text wrapping has stopped, the graph to the right of the text seems to overlap the percentage text that follows the graph.
image.png (13.3 KB)

@JThomas98
We can reproduce the issue by testing on the latest version v24.9 using the following sample code. When converting chart to emf, it was found that the text and chart overlapped. Please refer to the attachment. chart.zip (3.6 KB)

The sample code as follows:

Workbook wb = new Workbook(filePath + "Chart.xlsm");
Chart chart = wb.Worksheets["MedicareCharts"].Charts["Q019"];
chart.ToImage(filePath + "chart.emf", ImageType.Emf);

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-56761

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.

How come in this screenshot, the text is not being overlapped by the graph?

@JThomas98,

We have already logged a ticket (CELLSNET-56761) for this issue and are currently investigating it. Please allow us some time to thoroughly evaluate the issue. We will provide you with an update as soon as we have more information.

Hi @JThomas98
The new issue is in table line “Q19” which is not contains in “240906.png” I sent before.

The results of our new optimizations are as follows, which will be included in version 24.10.

240918.zip (1.8 MB)

@leoluo , I understand. I was asking because I had shared all these templates previously. Anyways, I’m glad its fixed. Looking forward to the new release. Thank you!

@JThomas98

Once Aspose.Cells for .Net 24.10(in Mid-October) is released, you will be updated here.

1 Like

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

Hey Aspose Team, I’m noticing a few more issues:

  1. In almost every chart from ExecSumReport worksheet, you’d notice that there is a [+] symbol in the bar graph in the image Aspose cells captures. But this isn’t there in excel. There are cases where there is either a [+] or [-] symbol in the graph (I’ve attached a second template, template2, to show this occurrence). In these cases, both the [+] and [-] symbols are coming together. There should only be one of these symbols along with each bar. Another thing is that the symbols are supposed to be towards the end of the bar, not at the beginning.
  2. In cases where there is no data for the year, excel shows a thin blue line even though there is no bar graph to be displayed. Where as in aspose, this thin blue line isn’t coming through.
  3. For the charts in DetailReport worksheet, the font color should be white for the percentage values inside the graph. This is being rendered as black in the aspose version.
  4. The shapes in the chart in QuadMap worksheet looks a little pixelated. This isn’t a big concern but I’d really appreciate if there’s something I can do to get a better quality.

Thank you.
Chart_Test.zip (1.8 MB)