SaveToStream tream fails with graphs within document

#1 (23.6 KB)
This code fails with ‘Invalid chart type’ exception

var wb = new Workbook(“MacroExcel.xlsm”);
var stream = wb.SaveToStream()

Using other ‘Save’ methods does not reproduce the issue



Please try to change the code segment as following, it works fine as I tested:
Sample code:

var wb = new Workbook("e:\\test2\\MacroExcel.xlsm");
            MemoryStream stream = new MemoryStream();
            wb.Save(stream, SaveFormat.Xlsm);  

Hope, this helps a bit.


Hi @Amjad_Sahi,

thank you for your reply and thank you for your workaround, we have already implemented that
Still I would like to raise a bug with SaveToStream


If we look at the description of SaveToStream() function, it is stated as follows:

   This method provides same function as Save method and only save the workbook
   as Excel97-2003 xls file. It's mainly for calling from COM clients.

Now if you open your sample file “MacroExcel.xlsm” in Excel 365 and try to save it in Excel97-2003 format, Excel also raises exception as shown below:
Capture.PNG (13.6 KB)

Hence this is the expected behavior and you may use the method shared by @Amjad_Sahi.