24
A
回答
25
你可以尝试在Apache API为Word文档:
它作为获取页计数的方法:
public int getPageCount()
返回: 如果SummaryInformation不包含页面co,则页面计数为0或0 UNT。
11
使用Apache POI的SummaryInformation获取MS Word文档
10
的总页数我发现了一个非常酷的班,那算页字,Excel和PowerPoint。借助Apache POI。它适用于旧的doc和新的docx。
String lowerFilePath = filePath.toLowerCase();
if (lowerFilePath.endsWith(".xls")) {
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(lowerFilePath));
Integer sheetNums = workbook.getNumberOfSheets();
if (sheetNums > 0) {
return workbook.getSheetAt(0).getRowBreaks().length + 1;
}
} else if (lowerFilePath.endsWith(".xlsx")) {
XSSFWorkbook xwb = new XSSFWorkbook(lowerFilePath);
Integer sheetNums = xwb.getNumberOfSheets();
if (sheetNums > 0) {
return xwb.getSheetAt(0).getRowBreaks().length + 1;
}
} else if (lowerFilePath.endsWith(".docx")) {
XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(lowerFilePath));
return docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
} else if (lowerFilePath.endsWith(".doc")) {
HWPFDocument wordDoc = new HWPFDocument(new FileInputStream(lowerFilePath));
return wordDoc.getSummaryInformation().getPageCount();
} else if (lowerFilePath.endsWith(".ppt")) {
HSLFSlideShow document = new HSLFSlideShow(new FileInputStream(lowerFilePath));
SlideShow slideShow = new SlideShow(document);
return slideShow.getSlides().length;
} else if (lowerFilePath.endsWith(".pptx")) {
XSLFSlideShow xdocument = new XSLFSlideShow(lowerFilePath);
XMLSlideShow xslideShow = new XMLSlideShow(xdocument);
return xslideShow.getSlides().length;
}
5
//Library is aspose
//package com.aspose.words.*
/*Open the Word Document */
Document doc = new Document("C:\\Temp\\file.doc");
/*Get page count */
int pageCount = doc.getPageCount();
2
Document doc = new Document("C:\\Data\\abc.doc");
//Get page count
int pageCount = doc.getPageCount();
//Print Page Count
System.out.println(pageCount);
如果你想使用使用Aspose.Words for Java中,document.getPageCount()API会给你的网页数量。请检查http://www.aspose.com/docs/display/wordsjava/com.aspose.words.Document.getPageCount+property
,或者您也可以使用docx4j API,
相关问题
- 1. MS Word的DOC
- 2. 在JAVA中使用Apache POI和iText创建Word(DOC)中的PDF
- 3. 使用java更新word doc中定制属性的值
- 4. 解析Word(.doc /.docx)文档
- 5. 在Silverlight 3中显示Ms Word 2003 .doc
- 6. 在word中添加多个图像doc
- 7. 读取Word存储为BLOB数据库中的DOC
- 8. 通过Office Interop Library在Word文档(2003 .doc)中显示页眉和页脚
- 9. 如何复制.doc页面
- 10. 将JasperReports导出为XSL(Excel)或DOC(Word)
- 11. 将Word文档(* .doc)转储到文本?
- 12. 将pdf转换为word doc文件
- 13. 写报告给word(doc和rtf)和excel
- 14. 如何打开varbinary word doc为HTML
- 15. 将Word Doc保存为2003 XML与VBA
- 16. 像Word一样格式化Doc
- 17. MailMerge InsertHtml遵循Word-doc对齐
- 18. 查看MS Word 2010中的.doc文件的VBA脚本
- 19. 如何在WinForms窗口中显示PDF或Word的DOC/DOCX?
- 20. 将HTML转换为.NET中的Microsoft Word .doc
- 21. VBA从word doc中的表格复制文本到excel?
- 22. Excel VBA修改excel中的word doc - 收集成员错误
- 23. 商店的MS Word的.doc在数据库中,然后把它弄出来再
- 24. Word Interop - 如何确定单词doc是否在页眉/页脚中包含页码
- 25. 用Java创建Word文档
- 26. 在现有MS Word文档(.doc和.docx)末尾添加数据
- 27. 使用RegEX从Word Doc格式化数据到SQL
- 28. Java中的Square Free Word
- 29. 如何在JAVA中编写word文件中的页面编号
- 30. 添加页脚Word apache poi java
你能在图书馆说,这个文档类属于??? – 2018-02-26 14:18:12
请检查代码中的评论 – 2018-03-01 15:44:24