java word读写操作,替换字符

转自 https://www.jb51.net/article/101910.htm

word

java word读写操作,替换字符_第1张图片

pom.xml

 
            org.apache.poi
            poi
            3.14
        

        
            org.apache.poi
            poi-scratchpad
            3.14
        

        
            org.apache.poi
            poi-ooxml
            3.14
        


        
            org.apache.poi
            poi-ooxml-schemas
            3.14
        

        
            org.apache.poi
            ooxml-schemas
            1.3
        

java



import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.hwpf.usermodel.Range;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: syl
 * @Date: 2019/7/15 0015 14:15
 * @Description:
 */
@Slf4j
public class DocUtils {

    @SuppressWarnings("deprecation")
    @Test
    public void testReadByExtractor() throws Exception {
        InputStream is = new FileInputStream("D:\\test.doc");
        WordExtractor extractor = new WordExtractor(is);
        //输出word文档所有的文本
        log.info(extractor.getText());
        //输出页眉的内容
        //输出当前word文档的元数据信息,包括作者、文档的修改时间等。
//        log.info(extractor.getMetadataTextExtractor().getText());
        //获取各个段落的文本
//        String paraTexts[] = extractor.getParagraphText();
//        for (int i=0; i

 

 

你可能感兴趣的:(java,word)