Convert excel chart to OOXML

It works guys!!! Thank you soo much for the help!

@Adhirath,

Thank you for your kind words. We glad to hear that the new version meets your needs. If you have any further questions or feedback, please don’t hesitate to reach out to us.

1 Like

Hi guys, it’s working great unfortunately I am facing issue with retrieving the WordML in case of the following charts-
Box and Whisker, Histogram, Pareto, Treemap, map .
Are these not supported or my code is at fault.

@Adhirath,

Could you please elaborate on the issue you are experiencing? Also, please zip and attach sample input Excel file(s) along with any output files (if generated). Additionally, we would appreciate it if you could share the sample code snippet you are using with Aspose.Cells APIs. We will check your issue soon.

sure, I’ll get back to you

@Adhirath
Thank you for your feedback. Please take your time to zip and attach sample excel files along with any output files (if generated). It would be helpful to provide runnable sample code and screenshots to reproduce the issue. We will check it soon.

This console app should help with understanding the issue. It is still giving me a chart but it’s content is empty. Please have a look.

Same happens for the following chart types as well-
Histogram, Pareto, Treemap, map

@Adhirath
If we directly convert xlsx to docx, BoxAndWhisker Chart works fine in docx.

  Workbook workbook = new Workbook(dir + "BoxAndWhisker.xlsx");
  var saveOptions = new DocxSaveOptions();
  //saveOptions.AsFlatOpc = true;
  saveOptions.SaveAsEditableShapes = true;
  workbook.Save(dir + "net259.4.docx", saveOptions);

net259.zip (34.3 KB)
We fixed an issue of theme color of docx file in 25.9.4

Maybe it should be issue that Aspose.Words does not support advance charts(Histogram, Pareto, Treemap, map ) since office 2016.
If you still want to use Aspose.Words to extract charts , please contact Aspose.Words team.
And is there any issue in docx flatopc file generated by Cells?

Yes, even when using AsFlatOpc true the OOXML seems to have no chart details. I tried copy/pasting as well and I get what you’re saying even word does not support pasting these charts with data. Let me look further into it.

@Adhirath,

Thank you for your feedback. It appears that MS Word has certain limitations and does not support these advanced charts. Kindly take your time to review it at your convenience, and please do not hesitate to reach out to us if you have any further questions or comments.

1 Like

@Adhirath
We compared the charts in the docx files generated by Aspose.Cells and MS Words.
Aspose.Words will not parse charts since office 2016 if chart drawing node is under mc:AlternateContent node in the document.xml file
We will add it soon.
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-59071

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.

@Adhirath
We have fixed this issue, please check the attached files:
OOXML.docx (22.1 KB)

dest.docx (19.0 KB)
which are generated inner hotfix with the following codes:

var workbook = new Workbook(dir + "BoxAndWhisker.xlsx");
var saveOptions = new DocxSaveOptions();
//saveOptions.AsFlatOpc = true;
saveOptions.SaveAsEditableShapes = true;
//saveOptions.SaveElementType = SaveElementType.Chart;
workbook.Save(dir + "dest.docx", saveOptions);
//   ms.Position = 0;
var sourceDoc = new Aspose.Words.Document(dir + "dest.docx");

// Find the first chart shape in the document
var chartShape = sourceDoc.GetChildNodes(NodeType.Shape, true)
    .OfType<Aspose.Words.Drawing.Shape>()
    .FirstOrDefault(s => s.HasChart);

if (chartShape == null)
    throw new InvalidOperationException("No chart found in the document.");

// Create a new document and import the chart
var newDoc = new Aspose.Words.Document();
var builder = new Aspose.Words.DocumentBuilder(newDoc);

NodeImporter importer = new NodeImporter(sourceDoc, newDoc, ImportFormatMode.KeepSourceFormatting);
Node importedChart = importer.ImportNode(chartShape, true);

builder.InsertNode(importedChart);

using (var memoryStream = new MemoryStream())
{
    newDoc.Save(dir + "OOXML.docx", new Aspose.Words.Saving.OoxmlSaveOptions(Aspose.Words.SaveFormat.Docx));
}

BTW , Aspose.Cells can directly export Excel chart to Word FlatOpc with simply Workbook.Save() method, why do you still export to docx ,then export chart to flatopc? Is there any node which does not comply with the specifications of ooxml.

This was our old approach, just wanted to show that the chart was showing up empty. But even when we tried using the flatOpc approach I could not find the chart info. Were you recommending some other solution?
Also thanks again guys!

If I use the Paid support is it possible to get this hotfix early?

@Adhirath,

We will evaluate and get back to you soon.

Yes, generally, we provide fixes in the paid support desk.

@Adhirath
Please confirm whether the file https://forum.aspose.com/uploads/default/111853 can work fine.
If yes and Paid support is used, we will provide this hotfix in this week.

Sure, can you please also check for these chart types-
Box and Whisker, Histogram, Pareto, Treemap, map .
and will I be able to get the correct OOXML for the same if I use this code-
saveOptions.AsFlatOpc = true;
saveOptions.SaveAsEditableShapes = true;
saveOptions.SaveElementType = SaveElementType.Chart;
workbook.Save(dir + “dest.docx”, saveOptions);

If this is working fine I’ll reach out using the paid support. Thanks!

@Adhirath
Please refer to the sample code and check result files. result.zip (57.0 KB)

Workbook workbook = new Workbook(filePath + "sample.xlsx");

DocxSaveOptions saveOptions = new DocxSaveOptions();
saveOptions.AsFlatOpc = true;
saveOptions.SaveAsEditableShapes = true;
saveOptions.SaveElementType = SaveElementType.Chart;
workbook.Save(filePath + "dest.xml", saveOptions);

workbook.Save(filePath + "dest.docx");

This works. We’ll reach out to you guys on Paid support. Thanks!
Is it fine if I ask for this hotfix using the ticket number you provided?

@Adhirath

Please post on Paid Support Services ,then Paid Support team will provide you the hotfix.