472,992 Members | 3,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Read XML based file that is recognized by Excel

I am having a problem reading an Excel file that is XML based. The directory
I am reading contains Excel files that can be of two types. Either generic Microsoft
based or XML based. I am reading the Microsoft based files with an OleDbDataAdapter.
Then filling the contents of the first worksheet into a dataset.

However when I try to add the XML based file to my dataset using an XmlTextReader
I can never seem to get it to save to a different table in the dataset in the same
format as when I use an OleDbDataAdapter for the generic Excel files. If I save
it(using ds.ReadXml) to my existing DataSet (which already has one table in it)
and no table gets created.

I tried saving it to a brand new DataSet and saw that 10 tables were created. I assume
mostly all are these are style sheet information. The last table (entitled "data") seems
to have all my data. I then tried to do a copy of that table and place it in my existing
DataSet. However column header information is not captured and I can't read the
table because when I open up the DataSet at a (later point in my program) I retrieve
datarow elements by specifying column names and the OleDb connection complains
it can't find them.

Perhaps there is a tweak I need to the XmlTextReader or perhaps my XML based
Excel file? I was thinking worse case I would try to find some OS command to convert
the file to a real Microsoft based format but obviously it would be easier to tweak
the XmlTextReader or the file itself. Here is a snippet of the code along with a
sample of the XML text file. If anyone has any solutions, it would be greatly appreciated!!

OleDbConnection objConn = new OleDbConnection(fileConnectionString);
objConn.Open(); //<---- This will trigger an exception if the file is XML based
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + worksheetName + "$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet ds = new DataSet();
// Create new FileStream to read schema with.
System.IO.FileStream fsReadXml = new System.IO.FileStream (filename, System.IO.FileMode.Open);
// Create an XmlTextReader to read the file.
System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml);
// Read the XML document into the DataSet.
ds.ReadXml(myXmlReader, XmlReadMode.ReadSchema);
// Close the XmlTextReader
DataTable xmlData = ds.Tables["data"].Copy();
xmlData.TableName = filename;

<?xml version='1.0'?>
<ss:Workbook xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet'>
<ss:Style ss:ID='1'>
<ss:Font ss:Bold='1'/>
<ss:Style ss:ID="s22">
<ss:NumberFormat ss:Format="Short Date"/>
<ss:Worksheet ss:Name='Survey'>
<ss:Table><ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Column ss:Width='60'/>
<ss:Row ss:StyleID='1'>
<ss:Cell><ss:Data ss:Type='String'>MEM_ID</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>CALL_DATE</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>SURVEY_FORM</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>SOURCE</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>REASON_CODE</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>ACTION_CODE</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>OPERATOR_ID</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>COMMENTS</ss:Data></ss:Cell>

<ss:Cell><ss:Data ss:Type='String'>555555555</ss:Data></ss:Cell>
<ss:Cell ss:StyleID="s22"><ss:Data ss:Type='DateTime'>2005-10-21T12:00:00.000</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>DNTL</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>MSPA</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>ee</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>ff</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'>elmer_fudd</ss:Data></ss:Cell>
<ss:Cell><ss:Data ss:Type='String'></ss:Data></ss:Cell>
</ss:Table> </ss:Worksheet> </ss:Workbook>

Nov 17 '05 #1
0 4613

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Majordomo | last post by:
-- >>>> --36742377 **** Command '--36742377' not recognized. >>>> Content-Type: text/plain; charset=us-ascii **** Command 'content-type:' not recognized. >>>> Content-Transfer-Encoding: 7bit...
by: Reza Solouki | last post by:
Hello, I never had to do anything with office tools programmatically till now(I guess there is first time for everything), so this might be a very silly and simple question for some of you. Any...
by: ntuyen01 | last post by:
Hi All, I try to read the data from the excel, but I ran into this problem I have two excel files. file one.xls data inside like this: 1234 1234 1234 1234 abc-123 ...
by: Vader | last post by:
I am new to this forum. Thanks in advance for and help. The following is what I am looking for: 1. I need help with VB code to open a MS Word (.doc) file. 2. Read lines from the MS Word (.doc)...
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
by: Defacta | last post by:
Hi, When I upload an excel file, PHP does not recognize the type of this file: echo $HTTP_POST_FILES ; returns: application/octet-stream Whereas a word file returns: application/msword
by: phub11 | last post by:
I'm wanting to populate a drop-down based on the contents of one column in an Excel file, and then submit the file to a PHP script. I've gotten PHP to read and process the Excel file fine...
by: Patrice | last post by:
Hello, I'm streaming an Excel file to IE using the content-disposition header. If the user opens the file, Excel appends a "" to its name (the name looks file in IE temporary internet files). It...
by: paintballer4lfe | last post by:
Hello, i am trying to create a code or get something that lets me read an excel file and take whats in the excel file and then put all of the cells into a list box, or import certain cells into a...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.