paragraph.getRuns(),以单独段落 [英] paragraph.getRuns() to seperate a paragraph

查看:3390
本文介绍了paragraph.getRuns(),以单独段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Apache POI来自动改变合约的日期,我是在怎样的剂量paragraph.getRuns()很困惑分开一个段落。我有以下段落
自2014年10月1日起至2014年10月31日止。

When I use Apache poi to change the date of a contract automatically, i am very confused at the how dose paragraph.getRuns() separate a paragraph. I have the following paragraph 自 2014 年 10 月 1 日起至 2014 年 10 月 31 日止

我用下面的code看到XWPFRun多少呢paragraph.getRuns()的返回

I use the following code to see how many XWPFRun does paragraph.getRuns() return

String currentParagraph = "";
                for(XWPFRun xwpfRun : paragraph.getRuns()){
                    currentParagraph += xwpfRun.getText(0);
                    System.out.println(currentParagraph);
                }

我发现的第一个五年号码都是一个独立xwpfRun,例如,2014,10,1
但最后一个数字31被分离成两xwpfRun:3,和1;

I find the first five number are all a xwpfRun independently,eg ,2014,10,1 but the last number "31" was separated into two xwpfRun :"3", and "1";

这使得它很难改变由xwpfRun日期,我想知道如何处理这个问题以及如何做paragraph.getRuns()的作品?

This makes it hard to change the date by xwpfRun ,and I want to know How to deal with this and how does paragraph.getRuns() works?

推荐答案

有时docx文件的文本被分成运行任意数量。虽然不方便,这并不是很难对付的。

Sometimes text in DOCX files gets broken up into an arbitrary number of runs. While inconvenient, it's not to difficult to deal with.

的解决方案是迭代段落中所有运行,并连接从每个文本的字符串。然后,更新日期,并将其存储作为第一个运行的文本。最后,您可以删除或设置文本中的其他奔跑,

The solution is to iterate all runs in the paragraph, and concatenate the text from each to a string. Then, update the date and store it as the text of the first run. Lastly, you can remove or set the text in the other runs to "".

这篇关于paragraph.getRuns(),以单独段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆