1
这一切都混淆在我的脑海中,我无法把头围住它。Excel到XML,编码问题
我有一个excel文件,我必须解析,使用Java,并转换为XML。使用jExcel库,我可以实现解析,并且应用程序可以做正确的工作,并将正确的字符串放在正确的位置。所以对于解析部分,我已经涵盖了。
当我尝试将文件转码为UTF-8时出现问题。
我认为excel文件的编码是ISO-8859-1,但我不确定它是否是。然后,在将我的字符串添加到xml文件之前,我使用此函数。
private static String isoToUtf(String thingie){
byte[] bytedata = thingie.getBytes() ; // Comes in ISO form, as the character set in the DB is set to ISO
Charset iso = Charset.forName("ISO-8859-1");
CharsetDecoder isodecoder = iso.newDecoder();
ByteBuffer bbuf = ByteBuffer.wrap(bytedata);
CharBuffer cbuf = isodecoder.decode(bbuf); // Decode from ISO to UTF-16
Charset utf8 = Charset.forName("UTF-8");
CharsetEncoder utf8encoder = utf8.newEncoder();
ByteBuffer outbuffer = utf8encoder.encode(cbuf); // Encode from UTF-16 to UTF-8
return new String(outbuffer.array(), "UTF-8");
}
不知何故,它不起作用。我仍然失去了一些腐败的人物。
另外:我绝对必须这样做,它必须最终显示在音符上。
使用java.io.File类打开excel文件。
准确地说,你是在编写XML吗?如果你只是写字符串,那么我可以保证你在许多方面做错了,尤其是UTF-8转换。阅读此更多信息:http://www.kdgregory.com/index.php?page=xml.builder – kdgregory 2009-09-18 16:13:53
如果您正在阅读Excel,我非常怀疑字符串是否在固定编码中,请参阅http://sc.openoffice .ORG/excelfileformat.pdf – Mark 2009-09-18 16:58:33