读取文件DOC
import com.spire.doc.*;
import com.spire.doc.documents.DocumentObjectType;
import com.spire.doc.documents.Paragraph;
public class SpireUtils {
public static void spireParagraphDoc(String path) {
Document doc = new Document(path);
for (int i = 0; i < doc.getSections().getCount(); i++) {
Section section = doc.getSections().get(i);
for (int j = 0; j < section.getParagraphs().getCount(); j++) {
Paragraph paragraph = section.getParagraphs().get(j);
String text = paragraph.getText();
if (StringUtils.isNotEmpty(text)){
System.out.println(text);
}
}
}
}
public static void spireForTableOfDoc(String path) {
Document doc = new Document(path);
for (int i = 0; i < doc.getSections().getCount(); i++) {
Section section = doc.getSections().get(i);
for (int j = 0; j < section.getBody().getChildObjects().getCount(); j++) {
DocumentObject obj = section.getBody().getChildObjects().get(j);
if (obj.getDocumentObjectType() == DocumentObjectType.Table) {
Table table = (Table) obj;
for (int k = 0; k < table.getRows().getCount(); k++) {
TableRow rows = table.getRows().get(k);
for (int p = 0; p < rows.getCells().getCount(); p++) {
for (int h = 0; h < rows.getCells().get(p).getParagraphs().getCount(); h++) {
Paragraph f = rows.getCells().get(p).getParagraphs().get(h);
System.out.println(f.getText());
}
}
}
}
}
}
}
}
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.0</version>
</dependency>