2011-02-02 14 views
0

私はXML文書を持っており、データをより見やすくするためにExcelシートに変換する必要があります。また、マクロを追加することもできます。Javaでプログラムを使ってXML文書をExcelシートに変換する

XML文書はかなり複雑で、実際にはXStreamを使用してXMLに変換されたJavaアプリケーションオブジェクトです。

タグを列名にする必要があり、属性を列値にする必要があります。

誰かが私がそれについてどのようにすべきかを示唆することができたら、大きな助けになるでしょうか?

私はApache POIを使用しようとしましたが、XML要素を動的に選択することができず、1つずつ繰り返して、タグ名に基づいて値を選ぶことはできません。 。

ありがとうございます。

答えて

0

私はApache POIがあなたの最良の選択だと思っていますが、おそらくXML解析アルゴリズムの一部と結びついています。たぶん、可能なすべてのxml値を2次元の配列またはリストに格納しようとする可能性があります。その後、それを反復して、POI POIを利用することができます。

String[][] array = .. //parsed xml 

for(String[] row : array){ 
     createCell(); 
     for(String cell : row){ 
     createRow(); 
     } 
} 
0
I would suggest a combination of POI(as it can read the latest version of Excel)JAXB and XSD 

1.First step would be to define a Schema Definition file(XSD) and define all the element names(classes) and its references(class attributes). 

For example Imagine your XML like this: 

<human> 
    <man1> 
    <age> 
    </age> 
    </man1> 
    <man2> 
    <age> 
    </age> 
    </man2> 
     . 
     . 
</human> 

2.Imagine each man1,man2 nodes as objects of a class called man so define a man element name in your XSD and define its elements. 
3. After that generate the classes from that xsd, do a maven clean install if you are using Maven. 
4. Unmarshall the xml to objects of the generated classes. 
5. Read each of the object in a loop and using POI open a new Excel file and insert the read data into the Excel file 
関連する問題