Hi, Aspose Team
I’m noticing an issue where the contents of my chart are pushed to the right when rendering the chart into an image.
The code I’ve used is:
Document RepDoc = new Document();
DocumentBuilder Builder = new DocumentBuilder(RepDoc);
using (Workbook TemplateWB = new Workbook(dir + @"\Test_04222025_02\Chart_Template.xlsm"))
{
Worksheet sourceWS = TemplateWB.Worksheets["DetailCharts"];
//Set print area
sourceWS.PageSetup.PrintArea = $"B73:M110";
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,
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_04072025_2\Output2.docx");
I have described the issue in detail in the word document named “Output2” in my attachment.
I have noticed this happening in all the charts in the worksheet “DetailCharts”.
Test_04222025_2.zip (8.5 MB)