Czy istnieje prosty sposób na policzenie liczby stron dokumentu programu Word to .doc lub .docx?Liczba stron w dokumencie słowo w java
Dzięki
Czy istnieje prosty sposób na policzenie liczby stron dokumentu programu Word to .doc lub .docx?Liczba stron w dokumencie słowo w java
Dzięki
można spróbować API Apache do Dokumentów słowo:
ona jako metoda uzyskiwania liczbę stron:
public int getPageCount()
Zwraca: Liczba stron lub 0, jeśli podsumowanie informacji nie zawiera strony co unt.
Użyj Apache POI SummaryInformation sprowadzić całkowitej liczby wydrukowanych stron wyrazu MS dokumentu
znalazłam naprawdę fajne lekcje, które liczą Strony dla Słowo, Excel i PowerPoint. Przy pomocy Apache POI. I to jest dla starego doc i nowego 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;
}
źródło: OfficeTools.getPageCount()
//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();
Document doc = new Document("C:\\Data\\abc.doc");
//Get page count
int pageCount = doc.getPageCount();
//Print Page Count
System.out.println(pageCount);
Jeśli chcesz użyć Aspose.Words for Java, document.getPageCount() API daje liczbę stron. Proszę sprawdzić http://www.aspose.com/docs/display/wordsjava/com.aspose.words.Document.getPageCount+property
lub można również użyć API docx4j,
Czy można powiedzieć, w której bibliotece, to należy do klasy Document ??? –
proszę sprawdzić komentarze w kodzie –