Convert excel chart to OOXML

Hi guys, I am facing an issue, whenever I mark SaveAsEditableShapes as true I get the error object reference not set to an instance of an object. What could be the reason?
Here is the code-
chartOOXMLCode.zip (932 Bytes)

@Adhirath,

Thanks for the code segment.

We would appreciate it if you could share a sample project (including complete source code free of compilation errors) along with sample file(s) to help us reproduce the issue on our end. We will review it promptly.

I’ll try to do that, till then is there something I should check that might help with this?

@Adhirath

Thank you for your feedback. We cannot locate the issue based solely on the provided code snippets. If you can provide sample files and executable test code, it will be very helpful for us to locate the issue. We will check it soon.

PS. please zip the sample file prior attaching here.

1 Like

Hi guys, here is the console app. As soon as it hits workbook.Save() I get the null ref error-

@Adhirath,

Thanks for sharing the sample app with template Excel file.

I am able to reproduce the issue as you mentioned by using your sample project with your template Excel file. I found if we mark SaveAsEditableShapes as “true” I get the error “object reference not set to an instance of an object” upon saving to DOCX. But it works fine if we don’t set the property.

using (var ms = new MemoryStream())
{
    var workbook = new Workbook("ChartConsoleExcelSheet.xlsx");
    var saveOptions = new DocxSaveOptions();
    saveOptions.SaveAsEditableShapes = true;
    workbook.Save(ms, saveOptions);//error
}

We require thorough evaluation of the issue. 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-58958

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.

Can I have an ETA on it? Kinda need this feature urgently. Thanks!

@Adhirath,

Thank you for bringing this issue to our attention. As it has just been logged, we kindly request a little time (2-3 days) to thoroughly evaluate the issue. Rest assured, we aim to address the problem promptly. We will provide an update here as soon as we have more information.

@Adhirath
We have supported exporting to flatopc files. Please check the attached generate files:
flatopc.zip (10.8 KB)

[Test]
 public void CELLSNET58945()
 {
     Workbook workbook = new Workbook(Constants.sourcePath + "CELLSNET58945.xlsx");           

     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
     saveOptions.AsFlatOpc = true;
     workbook.Save(Constants.destPath + "CELLSNET58945_Excel.xml", saveOptions);
     workbook = new Workbook(Constants.destPath + "CELLSNET58945_Excel.xml");
     Assert.AreEqual("a", workbook.Worksheets[0].Cells["A1"].StringValue);
     Assert.AreEqual(1, workbook.Worksheets[0].Charts.Count);


 }
 [Test]
 public void CellsNet58945_docx()
 {
     Workbook workbook = new Workbook(Constants.sourcePath + "CELLSNET58945.xlsx");
     DocxSaveOptions saveOptions = new DocxSaveOptions();
     saveOptions.AsFlatOpc = true;
     saveOptions.SaveAsEditableShapes = true;
     saveOptions.EmbedXlsxAsChartDataSource = false;
     workbook.Save(Constants.destPath + "CELLSNET58945_word.xml", saveOptions);
     String text = File.ReadAllText(Constants.destPath + "CELLSNET58945_word.xml");
     Assert.IsTrue(text.IndexOf("chart1.xml") !=  -1);
     Assert.IsTrue(text.IndexOf("xlsx") == -1);
 }

Sure, looking forward to it!

does this excel document have a chart? I’m asking because the XML doesn’t house a chart1.xml package.

@Adhirath
Please check attached flatopc with chart:
chart_flatopc.zip (27.0 KB)

@Adhirath,

Moreover, we are pleased to inform you that your issue (Ticket ID: “CELLSNET-58958”) has been resolved. This fix/enhancement will be included in the next release (Aspose.Cells v25.9), which is scheduled for the second week of September 2025. We will contact you again once the new version is available.

looks great, wanted to enquire if there was a way to just include the chart in the doc XML which currently has the table as well. So what I was doing was saving the excel doc as docx and then importing the chart to another doc and then saving that as flatopc to just get the chart related XML data. Is it possible to get the same if I have AsFlatOpc = true and SaveAsEditableShapes = true? it would make more sense according to me.

That’s amazing! What was the issue though if you don’t mind sharing.

@Adhirath
Do you only want to export a chart to flatopc?
If yes, we can copy chart to an empty workbook, then convert it to flatopc as the following :

 Workbook workbook = new Workbook(dir + "Book1.xlsx");
 Chart chart = workbook.Worksheets[0].Charts[0];
 Workbook w = new Workbook();
 w.Worksheets[0].Shapes.AddCopy(chart.ChartObject, 0, 0, 0, 0);
          
 DocxSaveOptions saveOptions = new DocxSaveOptions();
 saveOptions.AsFlatOpc = true;
 saveOptions.SaveAsEditableShapes = true;
 saveOptions.EmbedXlsxAsChartDataSource = false;

 w.Save(dir + "word_flatopc.xml", saveOptions);

word_flatopc.zip (9.0 KB)

Yes I do want only the chart to export to flapOpc, but even this flatOpc you provided has table tags. What happens because of that is when I insert this xml I get the table design and layout options along with chart design which I would like to avoid. I believe whenever the SaveAsEditableShapes is enabled the table will be present in the OOXML. So the only way I have been able to avoid that is after saving it to Docx I copy only the chart into a new doc and then save that as flatOpc. If we can replicate this great, otherwise I am absolutely fine with just having EmbedXlsxAsChartDataSource saveoption. Hope this makes sense.

@Adhirath
Thank you for your feedback. We have understood your needs. You need to directly convert the chart to flapOpc, and there are no table tags in the conversion result file.

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-58963

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

@Adhirath

Workbook workbook = new Workbook(dir + "Book1.xlsx");
//Chart chart = workbook.Worksheets[1].Charts[0];
//Workbook w = new Workbook();
//w.Worksheets[0].Shapes.AddCopy(chart.ChartObject, 0, 0, 0, 0);

DocxSaveOptions saveOptions = new DocxSaveOptions();
saveOptions.AsFlatOpc = true;
saveOptions.SaveAsEditableShapes = true;
//saveOptions.EmbedXlsxAsChartDataSource = false;
saveOptions.SaveElementType = SaveElementType.Chart;
workbook.Save(dir + "OnlyChart.xml", saveOptions);

Please the attached flatopc file
OnlyChart.zip (15.2 KB)

There is no <tbl> node now.

looks good. Thanks guys really appreciate the effort!