Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

excel - Convert rows of spreadsheet to separate XML files

I am looking for a system to convert a spreadsheet (or CSV file) with a few hundred rows of data into individual XML files. One column in the spreadsheet would be the required filename, and the other columns would contain data to be inserted into specific nodes in the XML based on a template.

Kind Regards, Dan

Edit 1 If it can be handled totally within Excel, creating a new XML for each row and inserting the relevant column data into the correct location of the XML template that would be the best outcome.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would go the xslt2 path. Save the file as csv, and then you can use a xslt template such as : http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html to convert it to xml.

Edit the template to create a new xsl:result-document whenever you want your new file. Basically you should edit the lines containing

<row>
<xsl:variable name="lineItems" select="fn:getTokens(.)" as="xs:string+" />

Where a new <row> element is created, and replace them with something like:

<xsl:variable name="lineItems" select="fn:getTokens(.)" as="xs:string+" />
<xsl:result-document href="$lineItems[1]">

Also replace </row> with </xsl:result-document> of-course you should change the template to your output needs, and change <xsl:param name="pathToCSV" select="'file:///c:/csv.csv'" /> to reference to your file.

The code above is untested, but I believe it should work.

Edit 1:

xslt2 bindings exist in many programing languages, and there are stand-alone versions as well. You can also split the process in two: save the xml version in excel, and transform the resulting xml to many xml files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...