Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Import XML Excel into dataset

0 views
Skip to first unread message

post...@alexshirley.com

unread,
Oct 25, 2005, 8:30:07 AM10/25/05
to
Hi - can you help please?

Please review the following straightforward code which works fine with
ordinary XML files.

----------------------------------------------------------------
Dim originalxmlsource As New DataSet
Dim xmlfilename As String = Request.PhysicalApplicationPath _ &
"myfilename.xml"
MyDataGrid.DataSource = originalxmlsource
MyDataGrid.DataBind()
----------------------------------------------------------------

In actuality what I really need to do is import an Excel XML file,
which was originally generated by Office Web Components (Excel 2002).
OWC would only allow me to Export in Excel XML, rather than native
Excel format.

If I try to use the above code using Excel XML I get a "Specified cast
is not valid" error.

So my question is how can I neatly import Excel XML into a dataset?

Many thanks!

Alex

Curt_C [MVP]

unread,
Oct 25, 2005, 9:06:02 AM10/25/05
to
Have you looked at the DataSet.ReadXml() method?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

post...@alexshirley.com

unread,
Oct 25, 2005, 9:16:30 AM10/25/05
to
Opps sorry I didn't post the code properly (doh!), yes it includes the
readxml method, but it won't read Excel XML.
Revised code here - thanks Alex

----------------------------------------------------------------
Dim originalxmlsource As New DataSet
Dim xmlfilename As String = Request.PhysicalApplicationPath _ &
"myfilename.xml"

originalxmlsource.ReadXml(xmlfilename)

Curt_C [MVP]

unread,
Oct 25, 2005, 9:41:04 AM10/25/05
to
which line, specifically, is getting the cast error?
Is they XML file a valid XML file?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

post...@alexshirley.com

unread,
Oct 25, 2005, 10:47:00 AM10/25/05
to
Hi Curt

This line gets "Specified cast is not valid":
originalxmlsource.ReadXml(xmlfilename)

But if only happens if I use an Excel 2002 XML spreadsheet, that's what
I want to import into a dataset.
Plain XML works fine.

Thanks

Alex

Curt_C [MVP]

unread,
Oct 25, 2005, 2:03:01 PM10/25/05
to
You may have to do some manual cleanup on the XML then.. sounds like it's not
validating correctly as proper XML.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

vMike

unread,
Oct 25, 2005, 3:27:29 PM10/25/05
to

<post...@alexshirley.com> wrote in message
news:1130243407....@o13g2000cwo.googlegroups.com...

> Hi - can you help please?
>
> Please review the following straightforward code which works fine with
> ordinary XML files.
>
> ----------------------------------------------------------------
> Dim originalxmlsource As New DataSet
> Dim xmlfilename As String = Request.PhysicalApplicationPath _ &
> "myfilename.xml"
> MyDataGrid.DataSource = originalxmlsource
> MyDataGrid.DataBind()
> ----------------------------------------------------------------
>

I think you may need 2003 version for exporting xml in a readable format as
2002 seems to export all of the excel spreadsheet formats etc. There may be
someone out there that has a customize file output writer to write the
desire xml format. A workaround may be to link you excel spreadsheet to
MSAcess and use the access export for xml (DataOnly). Hope this helps


post...@alexshirley.com

unread,
Oct 26, 2005, 5:31:12 AM10/26/05
to
Thank vMike

>I think you may need 2003 version for exporting xml in a readable format as
>2002 seems to export all of the excel spreadsheet formats etc.

I was wondering if there was a way of transforming the Excel 2002 XML
file itself (i.e. strip out the garbage) before it got read in....

Hmmm....

Cheers

Alex

0 new messages