473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel (in XML format) to a dataset

I have a XML file that is basically a Excel file saved as XML. I need
to be able to change the XML into a different format.

I was thinking one approach would be to:

1. Populate the dataset based on the XML file I get from excel
2. Use a WriteXML to create a XML file in the format I need.

Will this work? How do I get started on this? Are there any other
alternate ways of doing this?

TIA

Feb 15 '06 #1
3 1814
I'm unfamiliar with the format that XML saves in, so if you could post
some it that would help. As for the WriteXML, it just writes out the
data in the data table (which may be the same format as what you
imported, I have not tried this).

You could try changing the schema or loading a new schema on the
dataset and then calling the WriteXML Method, but I don't know if that
would work. When I have needed to control the format of an XML
document, I have written up my own logic to parse and write the xml
file.

I answered another DataSet question about writing xml here
(http://groups.google.com/group/micro...816696cabf590e)
but I don't know if that will help you out.

I would model the format you want (with lists of CollectionBase) and
then parse the xml data and place it into the appropriate location,
then write out the data.

Really hope this helps you out somehow,
Darren Kopp
http://blog.secudocs.com/

Feb 15 '06 #2

Check my blog:
http://spaces.msn.com/sholliday/

9/22/2005

You need to do an XML to XML transformation.

The format of the Excel XML is .... unique. It also has namespaces. So
there isn't a super trivial example.
I have some code below. I think it will work, but it will definately get
you going.
It took me about 2 weeks to figure this out, so post a 'thank you' please,
(and any issues if you run into them)

Ok..

Create an excel file.
3 columns, the first row is the header.
uid,lastname,fi rstname

Add like 4 more rows of real data ( "123","Smith"," John" .. like that)

Save as XML.

I have the C# code, which will show how to apply the XSL to the XML.
There is xsl also. Hopefully, it won't get screwed up
///////////////// START C# code
/// <summary>
/// Summary description for XMLtoXSLTransfo rmWrapper.
/// </summary>
public class XMLtoXSLTransfo rmWrapper
{

string debugMsg=null;

public void DoTranslation(s tring xmlFile, string xslFile, string
outputFile)
{

try
{

//Create a new XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load(xslFi le);

//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument(x mlFile);

//Create an XmlTextWriter which outputs to the console.
//XmlWriter writer = new XmlTextWriter(C onsole.Out);

//Transform the data and send the output to the console.
//xslt.Transform( mydata,null,wri ter, null);
xslt.Transform (xmlFile, outputFile);
}
catch (Exception ex)
{
debugMsg = ex.Message;
Console.WriteLi ne (debugMsg);

}
}

public XMLtoXSLTransfo rmWrapper()
{
//
// TODO: Add constructor logic here
//
}
}
}


//END C#

//START XSL



<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet" >

<xsl:template match="/">
<OneWellDefined DS>
<!--<myRootPosition ><xsl:value-of select="positio n()"/></myRootPosition>-->
<xsl:apply-templates select="ss:Work book"/>
</OneWellDefinedD S>
</xsl:template>
<xsl:template match="ss:Workb ook">
<!--<myWorkbookPosi tion><xsl:value-of
select="positio n()"/></myWorkbookPosit ion>-->

<xsl:apply-templates select="ss:Work sheet"/>

</xsl:template>
<xsl:template match="ss:Works heet">
<!--<myWorksheetPos ition><xsl:valu e-of
select="positio n()"/></myWorksheetPosi tion>-->
<xsl:choose>
<xsl:when test="position( )=1">

<xsl:apply-templates select="ss:Tabl e"/>

</xsl:when>
<xsl:otherwis e>
</xsl:otherwise>

</xsl:choose>

</xsl:template>
<xsl:template match="ss:Table ">
<!--<myTablePositio n><xsl:value-of
select="positio n()"/></myTablePosition >-->
<xsl:apply-templates select="ss:Row"/>

</xsl:template>
<xsl:template match="ss:Row">
<!--<myRowPosition> <xsl:value-of select="positio n()"/></myRowPosition>-->
<xsl:choose>
<xsl:when test="position( )=1">

</xsl:when>
<xsl:otherwis e>
<customerInfo >
<!--<myPosition><xs l:value-of select="positio n()"/></myPosition>-->

<xsl:apply-templates select="ss:Cell "/>
</customerInfo>

</xsl:otherwise>

</xsl:choose>
</xsl:template>
<xsl:template match="ss:Cell" >


<!--<myCellPosition ><xsl:value-of
select="$varCur rentAttributePo sition"/></myCellPosition>-->

<xsl:choose>
<xsl:when test="position( )=1">
<xsl:call-template name="xuid" />
</xsl:when>
<xsl:when test="position( )=2">
<xsl:call-template name="xlastname " />
</xsl:when>

<xsl:when test="position( )=3">
<xsl:call-template name="xfirstnam e" />
</xsl:when>

<xsl:otherwis e>

</xsl:otherwise>

</xsl:choose>

</xsl:template>
<xsl:template name="xuid">
<uid><xsl:val ue-of select="."/></uid>
</xsl:template>

<xsl:template name="xlastname ">
<lastname><xsl: value-of select="."/></lastname>
</xsl:template>

<xsl:template name="xfirstnam e">
<firstname><xsl :value-of select="."/></firstname>
</xsl:template>


</xsl:stylesheet>

Feb 15 '06 #3
What format would you like to change your XML file into?

Are you converting from XML to Excel file?
If so; just open your XML file in Excel, Excel will display the XML
file as an Excel sheet.

Your approach sounds feasible; the dataset will allow you to loop
through the tables, rows and columns. You can then generate a file
(StreamWriter) with your desired format / extension.

Feb 15 '06 #4

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

Similar topics

1
3476
by: Sushmita | last post by:
Hi, I have written an ASP script that connects to a database and runs a stored procedure and displays the results in text format ...using the <TABLE> tag. But I would like to have these results appear in a NEW Window in an Excel format. I used :
2
2834
by: cschang | last post by:
One of my client stations using IE 6 (v6.0.2800) to open one of my page which write the records into an excel format. However, it got some strange pop-up message that I can not figure out where it went wrong or need to adjust. The pop-up message is like as Some files can harm your computer. If the file information below looks suspicious, or you do not fully trust the source, do not open or save this file. File name: ...
2
6324
by: Hon Seng Phuah | last post by:
Hi all, I have a huge excel format file wants to export to sql server database. One of the field has combination of numeric and alphanumeric. When I import the excel format to sql server database, the numeric is successfully imported but the alphanumeric does not import at all. Does anyone know how to solve my problem?
1
2372
by: george_y | last post by:
I need some help to generate with a C++ programm a file in Excel format (or at least in a way that all the information in it can be read by Excel) containing a graph with the data I choose. As an example I include a simple script that generates an output file with two columns of integers and I` d like to add in it a graph in the same file so that when you open the output file aaa.xls with Excel both the numrical data and graph are...
0
2061
by: Katie | last post by:
Our ASP.NET app produces a page in excel format using Response.ContentType = "application/vnd.ms-excel" Response.Write(strExcel) (where strExcel is a tab and carriage return delimited string) When this page is sent to the browser (IE6SP1), the excel active X control opens up within IE6. Then if you do a File|Save As, you can save the file locally.
7
5076
by: postings | last post by:
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
6
18565
by: Sam Johnson | last post by:
HI I tried to send the following SQL string to an open databse, to export a table into excel format: g.Connection = conn 'valid OleDBConnection and Command objects g.CommandText = "SELECT * INTO XLSTest IN 'C:\' 'Excel 8.0;' FROM Table1" g.ExecuteNonQuery()
1
3078
by: Ray | last post by:
Hi, Now, I would like to export data to excel from sql server. Is there any easy way to export to excel from dataset? Thanks, Ray
2
1199
by: Thanks | last post by:
I am using asp.net(2003). I would like to output the data from the result of storeprocedure (sql 2000 server) into excel format. (office 2003) Can I do that? Please show me the coding if it can.
2
2136
by: Dhananjay | last post by:
Hi all , I have got problem when i am tring to exportGridview Data into Excel format. It is going into text format ,but what i want is if the field is number/currency then it should go into number/currency format itself .Data exported to excel are all exported as text. Export to excel should maintain the formatting like numbers and money should be numbers and money in excel .
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.