@Adhirath,
Similarly if you need to export the chart (only) in Excel spreadsheet, you may set printable area/range which should cover your desired chart area to be exported in the DOCX. To get the chart area range you may make use ChartObject’s specific attributes/properties. See the following sample code for your reference.
e.g.,
Sample code:
// Load the workbook containing the chart
Workbook workbook = new Workbook("e:\\test2\\Bk_chart1.xlsx");
Worksheet worksheet = workbook.Worksheets[0]; // Assuming chart is in the first worksheet
// Get the first chart in the worksheet
Chart chart = worksheet.Charts[0];
// Retrieve the chart's position and size
int startRow = chart.ChartObject.UpperLeftRow;
int startColumn = chart.ChartObject.UpperLeftColumn;
int endRow = chart.ChartObject.LowerRightRow;
int endColumn = chart.ChartObject.LowerRightColumn;
// Define the chart range as printable area
string printableArea = CellsHelper.CellIndexToName(startRow, startColumn) + ":" + CellsHelper.CellIndexToName(endRow, endColumn);
// Set the printable area for the worksheet
worksheet.PageSetup.PrintArea = printableArea;
DocxSaveOptions options = new DocxSaveOptions();
workbook.Save("e:\\test2\\out1.docx", options);
Hope, this helps a bit.
The chart name saved in excel and the one in aspose chart objects is different, Why?
@Adhirath,
Please zip and attach the Excel file and output DOCX file. Also, share your sample (runnable) code. We will check your issue soon.
Okay so I dont just want the image of the chart I want it’s OOXMl. how do i get that?
@Adhirath,
This is not supported as chart image would be rendered in the output DOCX. Maybe, embedding Excel chart as an OLE object in MS Word document can be an option. I think you may check with Aspose.Words team (in relevant forum) if they support it and how to accomplish the task.
@Adhirath
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-52212 Support converting editable chart to docx
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
one more query, when I adjust imageOrPrintOptions why are the vertical and horizontal resolution metrics in dpi? from my understanding dpi should only affect print quality but it ends up improving my image quality if i keep it 150 or higher and i get worse quality at 96 or less. How does this work ?
@Adhirath,
The DPI (dots per inch) settings in ImageOrPrintOptions
directly affect the image (rendering) quality and not just printing quality. Please note:
- Higher DPI (e.g., 150–300 or more) results in clearer images with sharper text and graphical objects (e.g., charts).
- Lower DPI (e.g., 96 or less) can make images pixelated or blurry.
- Aspose.Cells treats DPI as a rendering resolution metric for bitmap conversion.
1 Like
Hi guys we are planning to buy the license for the latest version of Aspose. Just wanted to confirm if all the formatting will be transferred when I save a range as Docx such as the borders and intrinsic allignment, etc. Also wanted to know if the chart saving as ooxml will be pushed to the current version if and when resolved.
@Adhirath
When saving a range in docx format, all format information within the selected range will be saved together, and the data format within the range will be consistent with that in Excel. All bug fixes and feature enhancements are based on the latest version.
1 Like
great, any updates on this-
Issue ID(s): CELLSNET-52212 Support converting editable chart to docx
@Adhirath
We apologize, there is currently no update. Once we have any new information, we will share it with you. We will get back to you soon.
appreciate the help, thanks!
@Adhirath
The layout of charts in Excel and Word is different
A chart in Excel floats above a cell and does not occupy the position of the cell.
But the chart in Word is on the page and occupies a cell position.
So how to layout is a rather complex issue.
can we insert it inside the cell and get the ooxml which can be pasted into word?
@Adhirath
image.png (6.2 KB)
If you can float the chart above merged cells in the template file as the attached image, we can ignore the issue of layout .
as long as I get the OOXMl it’s fine. I can extract the ooxml from within the table no issue, is there a way to do the same currently?
got you, a different query I have is ca I improve the image quality when getting an image using imageorprintoptions or chart.toImage etc but without changing the dpi as that ends up resizing the image.
This code resizes the image while improving the quality, i want the quality but dont want the image being resized-
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions()
{
VerticalResolution = 400,
ImageType = ImageType.Png,
HorizontalResolution = 400,
};
using (MemoryStream ms = new MemoryStream())
{
chart.ToImage(ms, imgOptions);
This gives the correc tsize for the image but the quality is not that great-
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions()
{
ImageType = ImageType.Png,
};
using (MemoryStream ms = new MemoryStream())
{
chart.ToImage(ms, imgOptions);
@Adhirath,
I think you may try to use EMF image format, it will give you maximum quality and you don’t really need to set resolutions if it works for your needs.