Java:将XML内容的StringWriter转换成Excel文件

我对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; } 

xmlStringWriter的XML内容

 <?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创build一个Excel文件。 我必须使用Apache POI,但是我不太了解如何使用StringWriter来完成这项工作。 我不能写一个带有数据的物理XML文件来读取它,因为这是商业方面所禁止的,我不认为这是很有效的。