Created
February 10, 2019 23:17
-
-
Save shikaiwen/3095979ab8578ae7ee368afbaea82dac to your computer and use it in GitHub Desktop.
翟天临博士论文字数word处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<properties> | |
<poi.version>3.10-FINAL</poi.version> | |
</properties> | |
<dependency> | |
<groupId>org.apache.poi</groupId> | |
<artifactId>poi</artifactId> | |
<version>${poi.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.poi</groupId> | |
<artifactId>poi-ooxml</artifactId> | |
<version>${poi.version}</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kevin; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; | |
import org.apache.poi.xwpf.usermodel.XWPFDocument; | |
import org.apache.poi.xwpf.usermodel.XWPFParagraph; | |
import org.apache.poi.xwpf.usermodel.XWPFRun; | |
/** | |
* A simple WOrdprocessingML document created by POI XWPF API | |
*/ | |
public class SimpleDocument { | |
public static void main(String[] args) throws Exception { | |
read(); | |
} | |
public static void read() throws Exception{ | |
String fileName = "C:\\Users\\admin\\Desktop\\Doctor\\博士论文最终定稿-翟天临.docx"; | |
XWPFDocument docx = new XWPFDocument(new FileInputStream(fileName)); | |
XWPFWordExtractor we = new XWPFWordExtractor(docx); | |
String fullText = we.getText(); | |
System.out.println(fullText.length()); | |
} | |
public static void write() throws Exception{ | |
//Blank Document | |
XWPFDocument document = new XWPFDocument(); | |
//Write the Document in file system | |
String fileName = "C:\\Users\\admin\\Desktop\\Doctor\\博士论文最终定稿-翟天临.docx"; | |
FileOutputStream out = new FileOutputStream(new File(fileName)); | |
//create Paragraph | |
XWPFParagraph paragraph = document.createParagraph(); | |
XWPFRun run = paragraph.createRun(); | |
StringBuilder sb = new StringBuilder(); | |
for(int i = 0 ; i < 100000;i++) { | |
sb.append("论"); | |
} | |
run.setText(sb.toString()); | |
document.write(out); | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment