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
@JThomas98
Your issue(CELLSNET-58169) has been resolved and the fixed functionality will be released with version 25.5.
@duojie.yang,
Can you provide a screenshot of the fix if possible?
Thanks.
@JThomas98,
We will check if we could provide you a screenshot/image showing the fixed results for your reference. We may get back to you soon.
@JThomas98
This is the result after repair.
CELLSNET-58169.png (53.8 KB)
This is looking good. Thanks.
Looking forward to the other fixes.
@JThomas98,
Thank you for confirming. We will also address the other issues and update you here as soon as we have new information.
@JThomas98,
We are pleased to inform you that your issue, i.e., CELLSNET-58168 (The shapes that overlap with the x-axis and y-axis are somehow behind the axis) has been resolved. The results of our optimization are as follows. It will be effective in the upcoming release, Aspose.Cells v25.5 which is expected to be published in the second week of May 2025. You will be notified once the new version is released.
CELLSNET-58168-fix.png (14.7 KB)
This is looking good. Thanks!
@JThomas98
Thank you for the confirmation. We will update here when the new version 25.5 is released(mid May).
Hi, I don’t know if this is right but from comparing a few charts in excel and its rendered image, I have a feeling that texts and shapes in the chart are slightly smaller in the image aspose captures.
To test this theory, I’ve super imposed the excel chart over the image aspose has captured and you can see this in the word document called “Word_Template”.
The code I’ve used to create the output is:
Document RepDoc = new Document();
DocumentBuilder Builder = new DocumentBuilder(RepDoc);
using (Workbook TemplateWB = new Workbook(dir + @"\Test_04282025\Excel_Template.xlsm"))
{
Worksheet sourceWS = TemplateWB.Worksheets["Demographics"];
//Set print area
sourceWS.PageSetup.PrintArea = $"AH72:DT123";
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.Emf,
HorizontalResolution = 100,
VerticalResolution = 100,
OnlyArea = true,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
};
// 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_04282025\Word_Template.docx");
Test_04282025.zip (8.9 MB)
@JThomas98
Thank you for the provided code and documents. We will look into it and give feedback when we have some findings.
1 Like
@JThomas98,
Thanks for the template Excel file, screenshot and code snippet.
After initial testing, I am able to reproduce the issue as you mentioned. I found that texts and shapes in the chart are slightly smaller in the image Aspose.Cells captures.
We require thorough evaluation of the issue. I am able to reproduce the issue as the user has mentioned by using his template Excel file and sample code snippet
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-58312
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.
Looking forward to it. Thanks!
@JThomas98,
We have started analyzing the issue. We keep you posted with updates once available on the issue (“CELLSNET-58312”).
1 Like
The issues you have found earlier (filed as CELLSNET-58169,CELLSNET-58168) have been fixed in this update. This message was posted using Bugs notification tool by leoluo
Hi Aspose Team
Any updates on CELLSNET-58312 & CELLSNET-58167? Thanks.