Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, August 30, 2013 5:00 AM
In XML Serialization we have a direct method for XML Serialization. But for excel we don't have such direct methods, We can serialize the Excel data also.
Step 1 : Load the Excel data to DataSet and the using DataSet XML Writer Convert the Excel to XML Document.
Step 2 : After converting it the Excel data will convert to XML. Then you can serialize the data using the XML Data Serialization methods.
All replies (1)
Monday, September 2, 2013 3:05 AM âś…Answered
Hi Girithara,
It seems that you've already known the answer.
About how to load the excel data into a DataSet, please see the following code:
private DataSet ReadExcelToDataSet(string filePath){ DataSet ds= new DataSet(); string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text\"", filePath); using (OleDbConnection dbConnection = new OleDbConnection(strConn)) { using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", dbConnection)) //rename sheet if required! dbAdapter.Fill(ds); return ds; }}
About how to serialize and deserialize xml using XmlSerializer, please take a look at the below sample:
http://dotnet.dzone.com/articles/serializing-and-deserializing
Hope it'll give you more help.
Caillen
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.