We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Convertng an xml string to an xls formatted string

Thread ID:





120174 Sep 7,2015 03:57 PM UTC Sep 16,2015 11:35 AM UTC WPF 5
Tags: XlsIO
Avril Craighead
Asked On September 7, 2015 03:57 PM UTC

What I am trying to do with the following code snippet is convert an xml string into a string with an xls format. The output gets downloaded as a .xls file. when the resultant .xls file is opened it says the file format and extension don't match. How do I get the string into an xls format?

                // convert bytes to a string so we can insert worksheet data.
                var spreadSheetTemplate = System.Text.Encoding.UTF8.GetString(rawSpreadsheet);

                // create a worksheet on which to manage fields.
                var spreadSheet = spreadSheetTemplate.Replace("<Worksheets/>", results.ToString());

                // convert string to memory stream
                MemoryStream msSpreadSheet = new MemoryStream(Encoding.UTF8.GetBytes(spreadSheet));
                // open msSpreadSheet into the excel engine and at the same time convert it to .xls format (I think)
                var excelEngine = new ExcelEngine().Excel.Workbooks.OpenFromXml(msSpreadSheet, ExcelXmlOpenType.MSExcel);

                // store the content of the engine which should (I think) now  be in .xls format back into a string
                spreadSheet = excelEngine.ToString();

                //var spreadSheet = new ExcelEngine().Excel.Workbooks.OpenFromXml(new MemoryStream(Encoding.UTF8.GetBytes(spreadSheetTemplate.Replace("<Worksheets/>", results.ToString()))), ExcelXmlOpenType.MSExcel).ToString();

                return Encoding.UTF8.GetBytes(spreadSheet);

Mathu Mohan Vijayakumar [Syncfusion]
Replied On September 8, 2015 12:03 PM UTC

Hi Avril,

We can see that your code is invalid.

XlsIO supports spreadsheetML and does not support for other XML formats. We have shared the UG Documentation link for your reference.

UG Link: http://help.syncfusion.com/wpf/xlsio/opening-excel-workbook#open-an-xml-workbook

V.A.Mathu Mohan

Avril Craighead
Replied On September 11, 2015 08:18 AM UTC

I am sorry but I don't understand how that helps me to get the xml format string into a xls format string.

Mathu Mohan Vijayakumar [Syncfusion]
Replied On September 14, 2015 10:44 AM UTC

Hi Avril,

Currently XlsIO supports only for XML Spreadsheet 2003 format. In your code you are using XML tag “<Worksheets/>” which is not a XML Spreadsheet predefined tag. And you have used ToString() method, which does not convert the xls to XML format string.

If you have any queries, you can contact us through our Direct Trac support system.

Mathu Mohan V A

Avril Craighead
Replied On September 15, 2015 08:16 AM UTC

Thanks - I am already successfully outputting a .xml - thank you for letting me know that Syncfusion cannot output a .xls file.

Mathu Mohan Vijayakumar [Syncfusion]
Replied On September 16, 2015 11:35 AM UTC

Hi Avril,

Thank you for updating us.

If you have any queries, you can contact us through our Direct Trac support system.

Support Link: https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Mathu Mohan V A


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon