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. powershell中word doc文件不同頁面上的不同頁眉?
- 3. 在JAVA中使用Apache POI和iText創建Word(DOC)中的PDF
- 4. 使用word interp統計單詞doc中的分頁符
- 5. 使用java更新word doc中定製屬性的值
- 6. 複製word doc中的所有元素
- 7. 從DOC提取頁面到新的DOC
- 8. Android創建Word(doc)文件
- 9. 解析Word(.doc /.docx)文檔
- 10. 如何使用Java程序獲取MS Word文件(.doc)中的行數
- 11. 在word中添加多個圖像doc
- 12. 從Word Doc Binary中提取文本
- 13. 在Silverlight 3中顯示Ms Word 2003 .doc
- 14. 將數據導出到Servlet中的MS Word(.doc)?
- 15. 讀取Word存儲爲BLOB數據庫中的DOC
- 16. 通過Office Interop Library在Word文檔(2003 .doc)中顯示頁眉和頁腳
- 17. 打印.doc(不docx)沒有打開Word JAVA
- 18. 如何複製.doc頁面
- 19. Java doc模式
- 20. 將Word文檔(* .doc)轉儲到文本?
- 21. 將pdf轉換爲word doc文件
- 22. 如何打開varbinary word doc爲HTML
- 23. 從XML轉換爲Microsoft Word Doc
- 24. Apache POI Word .DOC替換文本
- 25. MailMerge InsertHtml遵循Word-doc對齊
- 26. 將Word Doc保存爲2003 XML與VBA
- 27. 寫報告給word(doc和rtf)和excel
- 28. 將JasperReports導出爲XSL(Excel)或DOC(Word)
- 29. 像Word一樣格式化Doc
- 30. 使用python的doc,docx或rtf文件中的頁數
你能在圖書館說,這個文檔類屬於??? – 2018-02-26 14:18:12
請檢查代碼中的評論 – 2018-03-01 15:44:24