Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the operation of Apache-xwpf to word

Shulou Source: shulou.com Published: 2022-06-02 02:14:00 10月03日 Update

This article introduces what is the operation of Apache-xwpf to word, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Xwpf document structure class

XWPFDocument XWPFWordExtractor word document object

XWPFParagraph paragraph

XWPFTable form

XWPFTableRow Lin

XWPFTableCell cell

XWPFRun region

CTTblPr Table Properties

2. Read word// read file FileInputStream inputStream=new FileInputStream ("D:\\ doc.doc"); / / File object XWPFDocument document=new XWPFDocument (inputStream); / / get all paragraphs List paragraphs=document.getParagraphs (); / / traverse output for (XWPFParagraph paras:paragraphs) {System.out.println ("11" + paras.getText ());} / / get all tables List tables = document.getTables (); List rows; List cells For (XWPFTable table1:tables) {rows=table1.getRows (); for (XWPFTableRow row:rows) {cells=row.getTableCells (); for (XWPFTableCell cell:cells) {System.out.println (cell.getText ());} inputStream.close (); commonly used api// to get all paragraphs List paragraphs=document.getParagraphs (); / / get all tables List tables = document.getTables () / / get all the slices List picList = document.getAllPictures (); third, write the word// creation document XWPFDocument document=new XWPFDocument (); / / create a paragraph XWPFParagraph paragraph=document.createParagraph (); / / xwpfRun represents a region of the same attribute XWPFRun run1=paragraph.createRun (); run1.setBold (true); run1.setText ("background: VR technology maturity has reached the critical point of market explosion, consumer products"); run1.setColor ("000000"); run1=paragraph.createRun () Run1.setText ("purpose: we connect the VR technology to the 3D printer and use the VR technology to type"); run1.setColor ("ff0000"); OutputStream oStream=new FileOutputStream ("D:\\ doc.doc"); [xss_clean] (oStream); oStream.close (); fourth, write the word form XWPFDocument document=new XWPFDocument (); / / create the table XWPFTable table=document.createTable (5d5); / / get each line int rowSize=rows.size (); int cellSize;XWPFTableCell cell;XWPFTableRow row;for (int item0teri)

Tags: File table document paragraph unit attribute technology content area object more type help good same mature line tipping point product representative Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Shulou Information Xiaomi Linux