Hi,
I am using spire.Office (Xls and PdfConverter etc) in a pop email collection system which is intended to automatically convert incoming attachments to pdf for inclusion to a document management system backend.
Anyway there is a particular xlsx file being sent in by a regular user which tends to break my script.
My code is as follows:
Workbook workbook = new Workbook();
workbook.Version = ExcelVersion.Version2007;
workbook.LoadFromStream(attachment.DataStream());
PdfConverter pdfConverter = new PdfConverter(workbook);
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.PageSettings.Orientation = Spire.Pdf.PdfPageOrientation.Portrait;
pdfDocument.PageSettings.Size = Spire.Pdf.PdfPageSize.A3;
pdfDocument.PageSettings.Margins.All = 10;
PdfConverterSettings settings = new PdfConverterSettings();
settings.TemplateDocument = pdfDocument;
settings.DisplayGridLines = PdfConverterSettings.GridLinesDisplayStyle.Invisible;
settings.EmbedFonts = true;
settings.ExportDocumentProperties = true;
pdfDocument = pdfConverter.Convert(settings);
pdfDocument.SaveToFile(HttpContext.Current.Server.MapPath("~/messages/") + msgAttach.Msg_id.ToString() + ".pdf");
The offending xlsx file is attached. I know it is a nonsensical use of Excel for the contents of the file but I am unable to control that aspect unfortunately. Sorry the forum doesnt allow me to attach xlsx files.
The error I am getting is as follows:
[ArgumentNullException: Value cannot be null.
Parameter name: root]
Spire.CompoundFile.XLS.Native.Storage..ctor(IStorage root, String storageName) +171
Spire.CompoundFile.XLS.Native.Storage..ctor(IStorage root) +35
Spire.CompoundFile.XLS.Native.CompoundFile.a(Stream A_0) +187
Spire.Xls.Core.Spreadsheet.XlsApplication.CreateCompoundFile(Stream stream) +62
Spire.Xls.Core.Spreadsheet.XlsWorkbook.a(Stream A_0, String A_1, ExcelVersion A_2, ExcelParseOptions A_3) +104
Spire.Xls.Core.Spreadsheet.XlsWorkbook.a(String A_0, String A_1, ExcelVersion A_2, ExcelParseOptions A_3) +82
Spire.Xls.Core.Spreadsheet.XlsWorkbook..ctor(IInnerApp application, Object parent, String strFileName, ExcelParseOptions options, Boolean bReadOnly, String password, ExcelVersion version) +291
Spire.Xls.Core.Spreadsheet.XlsApplication.CreateWorkbook(Object parent, String strTemplateFile, ExcelParseOptions options, Boolean bReadOnly, String password, ExcelVersion version) +51
Spire.Xls.Core.Spreadsheet.Collections.XlsWorkbooksCollection.Open(String fileName, ExcelParseOptions options, Boolean isReadOnly, String password, ExcelVersion version) +42
Spire.Xls.Workbook.LoadFromFile(String fileName, ExcelVersion version) +122
Spire.Xls.Workbook.LoadFromFile(String fileName) +39
mailroom_test.convertor(Object sender, EventArgs e) in c:\inetpub\demo\mailroom\test.aspx.cs:25
mailroom_test.Page_Load(Object sender, EventArgs e) in c:\inetpub\demo\mailroom\test.aspx.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627