Shapes in charts rendered by aspose cells into image is slightly different from the excel itself

Hi Aspose Team,

I’m trying to convert charts/ranges in excel to images to insert them into word document.
The code I’m using to do this is:

Document RepDoc = new Document();
DocumentBuilder Builder = new DocumentBuilder(RepDoc);
using (Workbook TemplateWB = new Workbook(dir + @"\Test_04072025\Excel_Template.xlsm"))
{
    Worksheet sourceWS = TemplateWB.Worksheets["Q038_STND_1"];

    //Set print area
    sourceWS.PageSetup.PrintArea = $"P51:AK102";
    sourceWS.PageSetup.LeftMargin = 0;
    sourceWS.PageSetup.RightMargin = 0;
    sourceWS.PageSetup.TopMargin = 0;
    sourceWS.PageSetup.BottomMargin = 0;
    // Clear any header/footer as they'll be captured when converting the worksheet to image
    sourceWS.PageSetup.ClearHeaderFooter();

    // Set OnePagePerSheet option as true
    ImageOrPrintOptions options = new ImageOrPrintOptions
    {
        OnePagePerSheet = true,
        ImageType = Aspose.Cells.Drawing.ImageType.OfficeCompatibleEmf,
        HorizontalResolution = 100,
        VerticalResolution = 100,
        OnlyArea = true
    };

    // Take the image of your worksheet
    SheetRender Render = new SheetRender(sourceWS, options);
    // Create a stream to save the image in
    MemoryStream ImgStream = new MemoryStream();
    Render.ToImage(0, ImgStream); //Returns an image of the cell range if an accuarate cell range is suppiled
    if (ImgStream != MemoryStream.Null)
    {                    
        // Insert this image into the place of the old shape.
        Shape newOleShape = Builder.InsertImage(ImgStream);
        Aspose.Words.PageSetup PS = Builder.CurrentSection.PageSetup;
        double PageWidth = PS.PageWidth - PS.LeftMargin - PS.RightMargin;
        if (PageWidth < newOleShape.Width)
            {
                  newOleShape.Width = PageWidth;
            }
    }
}
RepDoc.Save(dir + @"\Test_04072025\Word_Template.docx");

Test_04072025.zip (176.9 KB)

I have highlighted the issues in red in the word document named “Word_Template.docm”

Issue #1 - The shapes in the graph plotting seems to lower resolution when compared to its legends to the right of the graph. Column “Markers” next to the graph shows the legends. This is highlighted in green in the word document.

Issue #2 - The shapes that overlap with the x-axis and y-axis are somehow behind the axis. Where as if you look at excel equivalent, you’ll notice that the shape seems to be in front of the axis. These are highlighted in red in the word document.

Issue #3 - Some shapes under the column “Marker” have an underline/bottom border. Not sure how this is happening. But the excel equivalent doesn’t have this. These are highlighted in orange in the word document.

@JThomas98

It seems you are experiencing several issues when converting Excel charts to images using Aspose.Cells. Let’s address each of your concerns:

Issue #1: Lower Resolution of Shapes in the Graph

The resolution of the shapes in the chart may appear lower compared to the legends due to the settings used in the ImageOrPrintOptions. You can try increasing the HorizontalResolution and VerticalResolution properties to improve the quality of the rendered image. For example, setting these values to 300 or higher can enhance the clarity of the shapes.

Issue #2: Shapes Behind the Axes

If the shapes are appearing behind the x-axis and y-axis, this could be related to the rendering order of the chart elements. Unfortunately, the rendering engine may not always replicate the exact layering seen in Excel. You might want to check if there are any properties in the chart settings that control the z-order of the shapes, or consider adjusting the chart layout in Excel before rendering.

Issue #3: Underline/Bottom Border on Shapes

The appearance of an underline or bottom border on shapes that do not exist in the original Excel chart could be a rendering artifact. This might occur due to differences in how Aspose.Cells interprets certain formatting. Ensure that the shapes in Excel do not have any borders or underlines applied. If the issue persists, you may need to manually adjust the properties of the shapes after rendering.

Suggested Code Adjustments

Here’s a modified snippet of your code that increases the resolution:

ImageOrPrintOptions options = new ImageOrPrintOptions
{
    OnePagePerSheet = true,
    ImageType = Aspose.Cells.Drawing.ImageType.OfficeCompatibleEmf,
    HorizontalResolution = 300, // Increased resolution
    VerticalResolution = 300, // Increased resolution
    OnlyArea = true
};

By adjusting the resolution, you may see improvements in the quality of the rendered images. If the issues persist, consider reaching out to Aspose support for further assistance, as they may have more insights into specific rendering behaviors.

If you have any further questions or need additional assistance, feel free to ask!

I need additional assistance.

@JThomas98,

Thanks for the template Excel file, Word document, sample code and details.

After initial testing, I am able to reproduce all (three) issues as you mentioned by using your template Excel file and sample code snippet.

We require thorough evaluation of the issues. 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-58167 - The shapes in the graph plotting seems to lower resolution when compared to its legends to the right of the graph
  • CELLSNET-58168 - The shapes that overlap with the x-axis and y-axis are somehow behind the axis
  • CELLSNET-58169 - Some shapes under the column “Marker” have an underline/bottom border

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.

1 Like