如何使用Aspose Word for Java从.doc读取文本和字体
我有一个任务要读写.doc文件,并且必须能够读取每个单词的字体设置。在我的开发中,我目前使用的是如何使用Aspose Word for Java从.doc读取文本和字体,java,ms-word,ms-office,aspose,aspose.words,Java,Ms Word,Ms Office,Aspose,Aspose.words,我有一个任务要读写.doc文件,并且必须能够读取每个单词的字体设置。在我的开发中,我目前使用的是Asposewordforjava,write-to-word和每个单词的字体设置正在运行。唯一的问题是,有时当我尝试选择一个.doc文件并使用下面的代码读取它时,它从System.out.print中不返回任何内容。但也有一些时候,它只是用很少的话,而不是整个内容 final JFileChooser fc = new JFileChooser(); HomeForm for
Aspose
wordforjava,write-to-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不能处理这种处理?请提供帮助,谢谢您的时间。您可以使用以下代码获取每个磨合文档的文本和字体名称:
Document doc = new Document("D:\temp\in.doc");
for(Run run : (Iterable) doc.getChildNodes(NodeType.RUN, true)) {
System.out.println(run.getText());
System.out.println(run.getFont().getName());
}
我作为开发人员传道者与Aspose合作。您可以使用以下代码获取每个运行中文档的文本和字体名称:
Document doc = new Document("D:\temp\in.doc");
for(Run run : (Iterable) doc.getChildNodes(NodeType.RUN, true)) {
System.out.println(run.getText());
System.out.println(run.getFont().getName());
}
我与Aspose合作,担任开发人员宣传员。我不熟悉此框架,但如果您指的是字体大小、字体系列、粗体/斜体等设置,那么我在代码中看不到这些部分,从我所看到的,您只是阅读文本。我不熟悉此框架,但如果您指的是字体大小、字体系列等设置,粗体/斜体等等,那么我在代码中看不到这些部分,从我所看到的,你只是阅读文本。如果是字体间距,我也可以得到它吗?你可以使用Font.spating属性来检索或设置字符之间的间距(以点为单位)。如果是字体间距,我也可以得到它吗?您可以使用Font.spating属性来检索或设置字符之间的间距(以点为单位)。