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.
Unfortunately, activation email could not send to your email. Please try again.

Convertng an xml string to an xls formatted string

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 08:03 AM

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

Regards,
V.A.Mathu Mohan


Avril Craighead
Replied On September 11, 2015 04:18 AM

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 06:44 AM

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.

Regards,
Mathu Mohan V A


Avril Craighead
Replied On September 15, 2015 04:16 AM

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 07:35 AM

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

Regards,
Mathu Mohan V A


CONFIRMATION

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.

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.

;