我的代碼解析XLSX到XML是這樣的:如何追加SharedStringsTable同時使用DOM解析器和Apache POI
public class ReadXlsx {
public static void processDoc(String path)throws Exception
{
OPCPackage pkg = OPCPackage.open(path);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
DOMParser parser = new DOMParser();
InputStream inp = r.getSheet("rId1");
InputSource inpSource = new InputSource(inp);
inpSource.setEncoding("UTF-8");
parser.parse(inpSource);
Document doc = parser.getDocument();
inp.close();
OutputStream writer = new FileOutputStream(System.getProperty("user.home") + "//Desktop"+"//file.xml");
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
//create string from xml tree
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
XmlToJson.Convert(System.getProperty("user.home") + "\\Desktop"+"\\file.xml",System.getProperty("user.home") + "\\Desktop"+"\\Json4.json");
}}
問題是,當我轉換.xlsx文件以.XML文件中每片將字符串被變換到這樣的事情
<c r="A1" s="43" t="s"><v>93</v></c>
這意味着在A1字符串在sharedStrings.xml 第94串(T = SV = 93表示細胞是一個字符串數組值是93)
我可以得到SharedStringsTable,但我不知道如何將它包含了 XML文件中,以便它會顯示字符串,而不是T = S V = 93像
<c r="A1" s="43"><t>This is String.</t></c>
感謝。