【发布时间】:2017-07-29 17:00:01
【问题描述】:
我有一个读取和写入 .doc 文件的任务,并且必须能够读取 字体设置 表示每个单词。我目前在我的开发中使用Aspose word for Java,写入 word 并包括每个单词的字体设置正在运行。唯一的问题是有时当我尝试选择一个 .doc 文件并使用下面的代码读取它时,它不会从 System.out.print 返回任何内容。但有时它也来了,但只有几句话而不是全部内容。
final JFileChooser fc = new JFileChooser();
HomeForm form = new HomeForm();
if (evt.getSource() == jButton2)
{
int returnVal = fc.showOpenDialog(HomeForm.this);
File file = fc.getSelectedFile();
if (returnVal == JFileChooser.APPROVE_OPTION) {
JOptionPane.showMessageDialog(null, "File " +file.getName()+" choosed", "Alert", JOptionPane.CLOSED_OPTION);
jTextField1.setText(file.getName());
String dataDir = file.getPath();
String filename = file.getName();
try {
InputStream in = new FileInputStream(dataDir);
Document doc = new Document(in);
System.out.println(file.getName());;
System.out.println(doc.getText());
in.close();FileInputStream(file.getAbsolutePath());Logger.getLogger(HomeForm.class.getName()).log(Level.SEVERE, null, ex);InputStreamReader(fis, Charset.forName("UTF-8"));
} catch (FileNotFoundException ex) {
Logger.getLogger(HomeForm.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(HomeForm.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
JOptionPane.showMessageDialog(null, "File choose canceled", "Alert", JOptionPane.CLOSED_OPTION);
}
}
通过使用此代码阅读每个单词和每个单词字体设置,我是否朝着正确的方向前进?或者也许 Aspose 无法处理这些处理?请帮忙,感谢您的宝贵时间。
【问题讨论】:
-
我不熟悉这个框架,但如果你的意思是 设置 像字体大小、系列、粗体/斜体等,那么我看不到这些部分在您的代码中,据我所知,您只是阅读了文本。
标签: java ms-word ms-office aspose aspose.words