该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
今天做POI解析word2007为html的时候,虽然已经转换到了html了,但是存在一个问题,那就是转换之后,表格中的内容从ASCII编码变为了unicode编码,具体代码如下:
实现转换的代码:
public class POIReadWordToHtml2007 {
public static void main(String[] args){
try {
File f = new File("C:\\Users\\Administrator\\Desktop\\wordAndExcel\\现场验收.docx");
if (!f.exists()) {
System.out.println("Sorry File does not Exists!");
} else {
if (f.getName().endsWith(".docx") || f.getName().endsWith(".DOCX")) {
// 1) Load DOCX into XWPFDocument
InputStream in = new FileInputStream(f);
XWPFDocument document = new XWPFDocument(in);
// 2) Prepare XHTML options (here we set the IURIResolver to
// load images from a "word/media" folder)
File imageFolderFile = new File("C:\\Users\\Administrator\\Desktop\\image");
XHTMLOptions options = XHTMLOptions.create().URIResolver(
new FileURIResolver(imageFolderFile));
options.setExtractor(new FileImageExtractor(imageFolderFile));
options.setIgnoreStylesIfUnused(false);
options.setFragment(true);
// 3) Convert XWPFDocument to XHTML
File file = new File("C:\\Users\\Administrator\\Desktop\\现场验收.html");
OutputStream out = new FileOutputStream(file);
XHTMLConverter.getInstance().convert(document, out, options);
BufferedReader in1 = new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\现场验收.html"));
String str;
while ((str = in1.readLine()) != null)
{
System.out.println(str);
}
in1.close();
// file.delete();
} else {
System.out.println("Enter only MS Office 2007+ files");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
转换后的部分html代码:
【题干】
ewqeqwe
导入的习题_你好
【选项】
【无】
【答案】
1111
【解析】
解析法大法师法
【结束】
其中的 【 就是我需要的内容,但是不知道怎么的就被转换为了这种编码的内容了,浏览器能够正确的解析这种编码的内容。
跪求大神告知如何修改!