I have code that is intended to read an Excel template, save it as another workbook, and open the new workbook. The code is below. It is throwing an ArgumentNullException on the second .Open, "Value cannot be null. Parameter name: item". I have read that code after a SaveAs to a file won't work, so I'm saving to a stream and saving that to a file. The Open still bombs. My Syncfusion.core.dll and Syncfusion.XlsIO.Base.dll have a Version of 9.2.3.0.138 and a Runtime Version or v2.0.50727.
Code:
string ext = System.Convert.ToString(System.IO.Path.GetExtension(_xlsTemplateFile).ToLower());
switch (ext)
{
case ".xlsx":
application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel2010;
break;
case ".xlsm":
application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel2010;
break;
default:
application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel97to2003;
break;
}
templateWorkbook = application.Workbooks.Open(_xlsTemplateFile, Syncfusion.XlsIO.ExcelParseOptions.Default);
_xlsSaveFile = System.IO.Path.ChangeExtension(_xlsSaveFile, ext);
//templateWorkbook.SaveAs(_xlsSaveFile);
using (var mstream = new MemoryStream())
{
templateWorkbook.SaveAs(mstream);
mstream.Position = 0; //set to beginning
using (var fstream = new FileStream(_xlsSaveFile, FileMode.OpenOrCreate))
{
mstream.CopyTo(fstream);
fstream.Flush();
}
}
templateWorkbook.Close();
reportWorkbook = application.Workbooks.Open(_xlsSaveFile, ExcelOpenType.Automatic);
templateWorkbook = null;