简体   繁体   English

将 csv/excel 转换为 xml 的工具

[英]Tool to convert csv/excel to xml

As title but would like the flexibility to specify how the output xml file will look like.作为标题,但希望能够灵活地指定输出 xml 文件的外观。 Any free tool available on windows platform that I can use to achieve that?我可以使用 Windows 平台上的任何免费工具来实现这一目标? Thanks谢谢

Use XSLT to obtain required output format. 使用XSLT获得所需的输出格式。

CSV -> CSV2XML -> XSLT -> XML CSV-> CSV2XML-> XSLT-> XML

XSLT is the true and straight way "to specify how the output xml file will look like". XSLT是“指定输出xml文件的外观”的正确方法。

You could read it into a dataset and use the dataset's WriteXML methods to output to XML. 您可以将其读入数据集,并使用数据集的WriteXML方法输出到XML。

It looks like this guy used XSLT. 看起来这家伙使用过XSLT。

I needed to convert a CSV file to a corresponding XML representation as follows: 我需要将CSV文件转换为相应的XML表示,如下所示:

CSV CSV

header1;header2;header3
data1;data2;data3
data4;data5;data6

XML XML

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <row>
        <header1>data1</header1>
        <header2>data2</header2>
        <header3>data3</header3>
    </row>
    <row>
        <header1>data4</header1>
        <header2>data5</header2>
        <header3>data6</header3>
    </row>
</root>

I found this tool to be exactly what I needed (it's in German, though): CSV2XML 我发现此工具正是我所需要的(尽管它是德语的): CSV2XML

It is written in Java and comes as a .jar file with a little Swing UI. 它是用Java编写的,并且是带有少量Swing UI的.jar文件。 It's somewhat configurable regarding input and output format, too. 关于输入和输出格式,它也是可以配置的。

You can use DBUnit and Java: 您可以使用DBUnit和Java:

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.excel.XlsDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;

public class XlsToXml {
    public static void main(String[] args) {    
        try {
            FileInputStream stream = new FileInputStream(args[0]);
            IDataSet dataset = new XlsDataSet(stream);
            OutputStream out = new ByteArrayOutputStream();
            FlatXmlDataSet.write(dataset, out);
            System.out.println(out);
        } catch (Exception e) { 
            e.printStackTrace();
        }
    }        
}

This will give you cells as attributes. 这将为您提供单元格作为属性。 Use XmlDataSet instead of FlatXmlDataSet if you want your XML formatted differently. 如果希望XML格式不同,请使用XmlDataSet而不是FlatXmlDataSet。

The easiest way is to use http://xmlgrid.net online tool to convert csv or Excel xls/xlsx to XML. 最简单的方法是使用http://xmlgrid.net在线工具将csv或Excel xls / xlsx转换为XML。 The converted XML will be displayed in an XML grid editor which allows you to change element/attribute names, delete or add rows/columns. 转换后的XML将显示在XML网格编辑器中,该编辑器允许您更改元素/属性名称,删除或添加行/列。

Since its open source, you should find the flexibility you need. 由于它是开源的,因此您应该找到所需的灵活性。 http://csv2xml.sourceforge.net/ http://csv2xml.sourceforge.net/

I think what you're looking for is Microsoft LogParser . 我认为您正在寻找的是Microsoft LogParser Jeff did a post about it awhile back. 杰夫不久前发表了一篇关于它的文章 Here are the forums if you need it but it's pretty straight forward. 如果需要的话,这里是论坛 ,但是很简单。

I haven't tried this but it looks like it handles your problem. 我还没有试过这个 ,但它看起来像它处理你的问题。

Good luck! 祝好运!

You can use Elev.at ( http://elev.at ) to convert from XLS to XML. 您可以使用Elev.at( http://elev.at )将XLS转换为XML。 It is a free web API. 它是一个免费的Web API。

I have an example data that needs to be converted from CSV to XML.我有一个需要从 CSV 转换为 XML 的示例数据。 Here are two online tools to meet this demand:这里有两个在线工具可以满足这种需求:

  1. Convert CSV to XML将 CSV 转换为 XML

  2. Convert Excel to XML将 Excel 转换为 XML

CSV CSV文件

id,name
1,Roberta
2,Oliver
3,Shayna

The output XML:输出 XML:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <row><id>1</id><name>Roberta</name></row>
    <row><id>2</id><name>Oliver</name></row>
    <row><id>3</id><name>Shayna</name></row>
</root>

嗯..我正在寻找更多现成的工具,并不是真正用于编程目的,我在发布之前检查了此http://csv2xml.sourceforge.net/ ,但是它缺乏灵活性来配置输出格式,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM