在java中在JTextarea中显示word的内容,用到poi
但是在textarea中显示的时候乱码了,textarea中是不是好像不能显示图片,但是也不能显示文字吗,好像可以用Jtextpane显示,
但是现在做了一大半,求高人指导下思路
但是在textarea中显示的时候乱码了,textarea中是不是好像不能显示图片,但是也不能显示文字吗,好像可以用Jtextpane显示,
但是现在做了一大半,求高人指导下思路
解决方案 »
- swing文本域的问题
- 一个时间器的重载run()方法的问题。不知道在run()内能不能够创建对象
- GRETA正则表达式rpattern初始化 在线等
- 抽象类与上转型对象调用的问题!!
- 一个mocha的使用问题
- 怎样将Label.getText()的文字的一部分(如第1个字)设置成其他颜色?(100奉上)
- 如何更新
- 急!!我用installanywhere怎么也放不到开始菜单里面去!!!!!!
- applet小问题,我却不能搞定
- 请教高手,怎样让java的应用程序在后台运行,图标在右下角状态栏?
- 谁给我发个孙浏毅JAVA宝典丛书PDF电子书(电子工业出版社出版)
- Java开子进程调用一个bat文件,bat文件里的cd命令无效怎么办?
JTextarea是可以显示文字的。
word和txt没什么区别,都是用输入输出流读取。String s="";
fr=new FileReader("src/com/briup/ch11/wtmpx");
br=new BufferedReader(fr);
String str="";
while((str=br.readLine())!=null){
s+=str; }
br.close();
然后把s在JTextarea中输出就行。
你提到了乱码,那是格式转换的问题,不知道你word中用的是什么格式,br=new BufferedReader
(new InputStreamReader
(new FileInputStream(file),"GBK"));//file指的是你文件路径,GBK你的文件的格式
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Word文档遵守这样的格式?? 不可能。
这个跟什么有关,比喻word里面有标题
File f = new File(ReaderListener.path);
InputStream in =new FileInputStream(f);
HWPFDocument msWord=new HWPFDocument(in);
Range range = msWord.getRange();
PicturesTable pTable = msWord.getPicturesTable();//获取图表对象
int numCharacterRuns = msWord.getRange().numCharacterRuns();//获取文档的段落
@SuppressWarnings("rawtypes")
//ArrayList content = new ArrayList();
byte[] content = null;
for (int i = 0; i < numCharacterRuns; i++) {
//CharacterRun这个类表示一个文本运行,有着共同的属性。
CharacterRun characterRun = msWord.getRange().getCharacterRun(i);
//判断,是图片则把图片位置替换为image标签,再把图片输出到指定位置
if (pTable.hasPicture(characterRun)) {
Picture pic = pTable.extractPicture(characterRun, true);//选取ptable中picture
//试建议的文件名:在“数据”流和扩展,试图确定图片的内容从第一个字节的十六进制表示的图像结构失调。
content = pic.getContent();//获取图片内容的字节数组
ReaderGUI.text.insertIcon(new ImageIcon(content));
} else {//纯文本则直接拼接
ReaderGUI.text.replaceSelection(characterRun.text()+"\n");
}//System.out.println(text);
}
//ReaderGUI.text.replaceSelection(range.text());
System.out.println(content.length);
in.close();
}
贴出来,就是word里面的图片的格式有限制(.png的可以),这里没有考虑word里面的表格,word里面的字体样式也没有去弄