I'm attempting to load (and convert to PDF) a XLSX spreadsheet from a SharePoint document library. When constructing the Workbook instance an exception is thrown;
Unexpected node type Element. ReadElementString method can only be called on elements with simple or empty content. Line 1, position 437. System.Xml.XmlException: Unexpected node type Element. ReadElementString method can only be called on elements with simple or empty content. Line 1, position 437. at System.Xml.XmlReader.ReadElementString() at ?.??(XmlTextReader ) at ?.??(XmlTextReader ) at ?.?.¦?() at ?.??() at ?.??(Workbook ) at Aspose.Cells.Workbook?(Stream , LoadOptions , Boolean ) at ConsoleApplication1.Program.TestExcel
The code I'm using is;
using (var web = site.OpenWeb()) { var file = web.GetFile(url);
var bytes = file.OpenBinary(SPOpenBinaryOptions.SkipVirusScan); using (var s = new MemoryStream(bytes)) { s.Seek(0, SeekOrigin.Begin);
var lo = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx) { LoadDataOnly = false, LoadDataOptions = new LoadDataOption { ImportFormula = true }, }; var wb = new Workbook(s, lo);
var so = new PdfSaveOptions {SaveFormat = SaveFormat.Pdf, OnePagePerSheet = true,}; wb.Save(pdfFile, so); s.Close(); } }
If I attempt to load the same document before its uploaded to SharePoint, I can load the document and convert to PDF as expected.
I'm using Aspose.Cells for .NET v7.1.2.0 (with Aspose.Total Suite license)
My environment is Windows Server 2008 R2 Std x64 SP1
Well, if you are using Aspose.Cells for .NET library, by default, this component works fine on WinForm, WebForms, Console, Win/Web Service or other project .NET project types without any problem, I tested converting your file on a win form/web solution and it works fine here. But if you want to use it on SharePoint platform, it may not be much feasible for it, anyways, we still recommend you to kindly check this blog first:
Moreover, we do provide a separate product: Aspose.Cells for SharePoint that is specifically designed to work on SharePoint with the product, it does support PDF conversion too from Excel spreadsheets, so you should try it.
Thanks for your reply, I've checked the blog you referred to but don't think it applies here.
If I set the LoadDataOnly property to true, then creating the Workbook instance succeeds (though only the spreadsheet data is loaded of course) and an exception is not thrown.
If I download the document concerned from SharePoint to my filesystem and attempt to load the document using a Console application, then the exception still occurs.
The document can be opened using a new Workbook instance before the document is uploaded to SharePoint without an exception being thrown - I think this is the key issue here, as the SharePoint document parser synchronises document properties and SharePoint column values when the document is saved in a document library.
It seems to me that once this has happened then the document (XLSX) is unreadable from Aspose.Cells, but I'm still able to open the document using a standard OpenXML library.
I'm, able to perform the same actions (open a document from a SharePoint document library and convert to PDF) using both Aspose.Words and Aspose.Slides without a problem.
We have logged a ticket with an id: CELLSNET-40590. We are looking into your issue (currently under process) and will get back to you to figure it out soon.
Well, I have asked the concerned developer (currently working over issue) to provide an eta for the fix is possible. Once I receive any update from him, I will let you know here.