本文整理了Java中org.apache.poi.xwpf.usermodel.XWPFDocument.getParagraphs()
方法的一些代码示例,展示了XWPFDocument.getParagraphs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XWPFDocument.getParagraphs()
方法的具体详情如下:
包路径:org.apache.poi.xwpf.usermodel.XWPFDocument
类名称:XWPFDocument
方法名:getParagraphs
暂无
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* get the paragraph with the CTP class p
*
* @param p
* @return the paragraph with the CTP class p
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (int i = 0; i < getParagraphs().size(); i++) {
if (getParagraphs().get(i).getCTP() == p) {
return getParagraphs().get(i);
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
XWPFDocument doc = new XWPFDocument(OPCPackage.open("input.docx"));
for (XWPFParagraph p : doc.getParagraphs()) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
String text = r.getText(0);
if (text != null && text.contains("needle")) {
text = text.replace("needle", "haystack");
r.setText(text, 0);
}
}
}
}
for (XWPFTable tbl : doc.getTables()) {
for (XWPFTableRow row : tbl.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
String text = r.getText(0);
if (text.contains("needle")) {
text = text.replace("needle", "haystack");
r.setText(text);
}
}
}
}
}
}
doc.write(new FileOutputStream("output.docx"));
代码示例来源:origin: Sayi/poi-tl
@Override
public List<ElementTemplate> visitDocument(XWPFDocument doc) {
if (null == doc)
return null;
this.eleTemplates = new ArrayList<ElementTemplate>();
visitParagraphs(doc.getParagraphs());
visitTables(doc.getTables());
visitHeaders(doc.getHeaderList());
visitFooters(doc.getFooterList());
return eleTemplates;
}
代码示例来源:origin: stackoverflow.com
XWPFDocument doc = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = doc.getParagraphs();
for (XWPFParagraph p : paragraphs) {
... do something here
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* get the paragraph with the CTP class p
*
* @param p
* @return the paragraph with the CTP class p
*/
public XWPFParagraph getParagraph(CTP p) {
for (int i = 0; i < getParagraphs().size(); i++) {
if (getParagraphs().get(i).getCTP() == p) {
return getParagraphs().get(i);
}
}
return null;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
/**
* get the paragraph with the CTP class p
*
* @param p
* @return the paragraph with the CTP class p
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (int i = 0; i < getParagraphs().size(); i++) {
if (getParagraphs().get(i).getCTP() == p) {
return getParagraphs().get(i);
}
}
return null;
}
代码示例来源:origin: stackoverflow.com
public void readFontSizeFromDocx() throws IOException
{
InputStream is = this.getClass().getClassLoader().getResourceAsStream("templates/ExampleFontSize.docx");
XWPFDocument doc = new XWPFDocument(is);
for (XWPFParagraph paragraph : doc.getParagraphs())
{
for (XWPFRun run : paragraph.getRuns())
{
System.out.println(run.getFontSize());
}
}
}
代码示例来源:origin: stackoverflow.com
XWPFDocument doc = new XWPFDocument(OPCPackage.open("myfile.docx"));
for (XWPFParagraph paragraph : doc.getParagraphs()) {
int pos = 0;
for (XWPFRun run : paragraph.getRuns()) {
for (character c : run.text().toCharArray()) {
System.out.println("The character at " + pos + " is " + c);
pos++;
}
}
}
代码示例来源:origin: micromata/projectforge
private void replaceInWholeDocument(XWPFDocument document, Map<String, String> map)
{
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph paragraph : paragraphs) {
if (StringUtils.isEmpty(paragraph.getText()) == false) {
replaceInParagraph(paragraph, map);
}
}
}
代码示例来源:origin: stackoverflow.com
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
public void readDocxFile() {
try {
File file = new File("C:/NetBeans Output/documentx.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: net.paissad.tools.reqcoco.parser/reqcoco-parser-docx
@Override
public Collection<Requirement> parse(final URI uri, final ReqDeclTagConfig declTagConfig, final Map<String, Object> options)
throws ReqParserException {
try (final InputStream in = Files.newInputStream(Paths.get(uri)); final XWPFDocument document = new XWPFDocument(in)) {
final Set<Requirement> declaredRequirements = new HashSet<>();
final Predicate<String> textContainsRequirementPredicate = Pattern.compile(declTagConfig.getCompleteRegex()).asPredicate();
LOGGER.debug("Retrieving all paragraphs contained into the docx file -> {}", uri);
document.getParagraphs().stream().map(XWPFParagraph::getText).filter(textContainsRequirementPredicate)
.forEach(text -> declaredRequirements.addAll(getRequirementsFromString(declTagConfig, text)));
return declaredRequirements;
} catch (IOException e) {
String errMsg = "Error while reading the docx file : " + e.getMessage();
LOGGER.error(errMsg, e);
throw new ReqParserException(errMsg, e);
}
}
代码示例来源:origin: org.hswebframework/hsweb-expands-office
@Override
public void read(InputStream inputStream, WordReaderCallBack callBack) throws Exception {
XWPFDocument document = new XWPFDocument(inputStream);
document.getParagraphs().forEach(callBack::onParagraph);
document.getTables().forEach(callBack::onTable);
callBack.done(document);
}
代码示例来源:origin: hs-web/hsweb-expands
@Override
public void read(InputStream inputStream, WordReaderCallBack callBack) throws Exception {
XWPFDocument document = new XWPFDocument(inputStream);
document.getParagraphs().forEach(callBack::onParagraph);
document.getTables().forEach(callBack::onTable);
callBack.done(document);
}
代码示例来源:origin: stackoverflow.com
File f=new File("test.docx");
FileInputStream fis = new FileInputStream(f);
XWPFDocument xdoc=new XWPFDocument(OPCPackage.open(fis));
XWPFStyles styles=xdoc.getStyles();
List<XWPFParagraph> xwpfparagraphs =xdoc.getParagraphs();
System.out.println();
for(int i=0;i<xwpfparagraphs.size();i++)
{
System.out.println("paragraph style id "+(i+1)+":"+xwpfparagraphs.get(i).getStyleID());
if(xwpfparagraphs.get(i).getStyleID()!=null)
{
String styleid=xwpfparagraphs.get(i).getStyleID();
XWPFStyle style=styles.getStyle(styleid);
if(style!=null)
{
System.out.println("Style name:"+style.getName());
if(style.getName().startsWith("heading"))
{
//this is a heading
}
}
}
}
代码示例来源:origin: stackoverflow.com
XWPFDocument document = new XWPFDocument(PoiTest.class.getResourceAsStream("twocolumn.docx"));
XWPFParagraph tmpParagraph = document.getParagraphs().get(0);
for (int i = 0; i < 100; i++) {
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("LALALALAALALAAAA");
tmpRun.setFontSize(18);
}
document.write(new FileOutputStream(new File("C:\\temp\\poi.docx")));
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream(new File("transformed.docx"));
XWPFDocument doc = new XWPFDocument(new FileInputStream(new File("original.docx")));
for(XWPFParagraph p:doc.getParagraphs()){
for(XWPFRun r:p.getRuns()){
for(CTText ct:r.getCTR().getTList()){
String str = ct.getStringValue();
if(str.contains("NAME")){
str = str.replace("NAME", "Java Dev");
ct.setStringValue(str);
}
}
}
}
doc.write(fos);
}
代码示例来源:origin: graphaware/neo4j-nlp
@Override
public List<Page> parse(InputStream fs, List<String> filterPatterns) throws Exception {
List<Page> pages = new ArrayList<>();
XWPFDocument document = new XWPFDocument(fs);
int i = 1;
for (XWPFParagraph xwpfParagraph : document.getParagraphs()) {
Page page = new Page(i);
List<XWPFRun> runs = xwpfParagraph.getRuns();
StringBuilder sb = new StringBuilder();
for (XWPFRun run : runs) {
if (null != run.getText(0)) {
sb.append(run.getText(0));
}
}
page.getParagraphs().add(sb.toString());
if (!sb.toString().equals("")) {
pages.add(page);
++i;
}
}
return pages;
}
}
代码示例来源:origin: stackoverflow.com
XWPFParagraph pr = doc.getParagraphs().get(0);
int pos = destDoc.getParagraphs().size() - 1;
代码示例来源:origin: stackoverflow.com
for (XWPFParagraph p : doc.getParagraphs()){
代码示例来源:origin: com.github.nic-luo/rober-office
/**
* 构造函数,用以分析文档,解析出所有的标签
*
* @param document Word OOXML document instance.
*/
public WordBookMarkParser(XWPFDocument document) {
//初始化标签缓存
this.bookmarks = new HashMap<String, BookMark>();
// 首先解析文档普通段落中的标签
this.procParaList(document.getParagraphs());
//利用繁琐的方法,从所有的表格中得到得到标签,处理比较原始和简单
List<XWPFTable> tableList = document.getTables();
for (XWPFTable table : tableList) {
//得到表格的列信息
List<XWPFTableRow> rowList = table.getRows();
for (XWPFTableRow row : rowList){
//得到行中的列信息
List<XWPFTableCell> cellList = row.getTableCells();
for (XWPFTableCell cell : cellList) {
//逐个解析标签信息
//this.procParaList(cell.getParagraphs(), row);
this.procParaList(cell);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!