加载,操作和保存WPS文字(Word)文档
原WPS文字文档:
 
import com.spire.doc.Document;import com.spire.doc.FileFormat;import com.spire.doc.Section;import com.spire.doc.documents.Paragraph;import java.awt.*;import java.io.*;public class LoadAndEditWpsWord {    public static void main(String[] args) throws IOException {        //通过流加载WPS文字文档        FileInputStream inputStream = new FileInputStream(new File("Sample.wps"));        Document document = new Document();        document.loadFromStream(inputStream, FileFormat.Doc);        //获取文档的第一个节        Section section = document.getSections().get(0);        //获取该节中第一个段落        Paragraph paragraph = section.getParagraphs().get(0);        //给该段落设置背景颜色        paragraph.getFormat().setBackColor(Color.pink);        //将结果文档保存到流        ByteArrayOutputStream bos = new ByteArrayOutputStream();        document.saveToStream(bos, FileFormat.Doc);        //将流写入WPS文档        FileOutputStream fos = new FileOutputStream("Output.wps");        fos.write(bos.toByteArray());        //关闭流        bos.close();        fos.close();    }}
结果文档:
 
创建 WPS 文字(Word)文档
 
Spire.Doc for Java 4.7.0已发布。该版本增强了转换Word/RTF到PDF,以及转换HTML到Word的功能。此外,本次更新还修复了加载和保存Word文档等时出现的问题。
整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!