我对Java有点陌生。我有一个java方法,它使用JAXB生成具有XML内容的StringWriter:
PrepareXMLService.java
public StringWriter prepare(Report report) throws JAXBException {
StringWriter xmlStringWriter = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(Report.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
jaxbMarshaller.marshal(report, xmlStringWriter);
return xmlStringWriter;
}XML内容的xmlStringWriter
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<report>
<reportObject>
<object>CLIENT_ID</object>
<objectValue>1111111</objectValue>
</reportObject>
<reportContent>
<reportInterval>
<startDate>2015-07-01T00:00:00+03:00</startDate>
<endDate>2016-06-30T23:59:59+03:00</endDate>
</reportInterval>
<client>
<clientId>1111111</clientId>
<clientName>test</clientName>
<clientTown>test</clientTown>
<clientAddress>test</clientAddress>
</client>
<transaction>
<transactionDate>2015-10-23T00:00:00+03:00</transactionDate>
<transactionAmount>23</transactionAmount>
<transactionCurrency>7777</transactionCurrency>
<transactionClientId>8798768789</transactionClientId>
<transactionNetAmount>22</transactionNetAmount>
</transaction>
</reportContent>
</report>我需要用这个StringWriter创建一个Excel文件。为此,我必须使用Apache,但我不太明白如何使用我的StringWriter来实现它。我不能编写带有数据的物理XML文件,以便在后面读取它,因为这是业务方面禁止的,而且我不认为这是非常有效的。
发布于 2016-10-10 06:56:46
尝试以下链接http://www.javaworld.com/article/2076189/enterprise-java/book-excerpt--converting-xml-to-spreadsheet--and-vice-versa.html中给出的解决方案
https://stackoverflow.com/questions/39952685
复制相似问题