本文整理汇总了Java中org.apache.poi.hwpf.usermodel.Range.getParagraph方法的典型用法代码示例。如果您正苦于以下问题:Java Range.getParagraph方法的具体用法?Java Range.getParagraph怎么用?Java Range.getParagraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hwpf.usermodel.Range
的用法示例。
在下文中一共展示了Range.getParagraph方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleHeaderFooter
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
private void handleHeaderFooter(Range[] ranges, String type,
HWPFDocument document, PicturesSource pictures,
PicturesTable pictureTable, XHTMLContentHandler xhtml)
throws SAXException, IOException, TikaException {
if (countParagraphs(ranges) > 0) {
xhtml.startElement("div", "class", type);
for (Range r : ranges) {
if (r != null) {
for (int i = 0; i < r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
String text = p.text();
if (text.replaceAll("[\\r\\n\\s]+", "").isEmpty()) {
// Skip empty header or footer paragraphs
} else {
i += handleParagraph(p, 0, r, document,
FieldsDocumentPart.HEADER, pictures, pictureTable, xhtml);
}
}
}
}
xhtml.endElement("div");
}
}
示例2: getParagraphText
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
protected static String[] getParagraphText( Range r )
{
String[] ret;
ret = new String[r.numParagraphs()];
for ( int i = 0; i < ret.length; i++ )
{
Paragraph p = r.getParagraph( i );
ret[i] = p.text();
// Fix the line ending
if ( ret[i].endsWith( "\r" ) )
{
ret[i] = ret[i] + "\n";
}
}
return ret;
}
示例3: processParagraphRequest
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
/**
* Processing of text requests.
*
* @param doc word document
* @param paragraphRef reference to paragraphs
* @return list of text values as {@code LinkedList<Value>}
*/
private LinkedList<Value> processParagraphRequest(HWPFDocument doc, String paraRef) {
LinkedList<Value> valList = new LinkedList<Value>();
Range docRange = doc.getRange();
setStartEndParagraph(paraRef, "*");
if (this.startPara == -1 || this.endPara == -1) {
this.startPara = 0;
this.endPara = docRange.numParagraphs() - 1;
}
// -1 => all paragraphs requested
if (this.startPara < docRange.numParagraphs()) {
if (!(this.endPara < docRange.numParagraphs())) {
this.endPara = docRange.numParagraphs() - 1;
}
for (Integer pPos = this.startPara; pPos <= this.endPara; pPos++) {
Paragraph p = docRange.getParagraph(pPos);
Integer subURI = pPos + 1;
valList.add(getParagraph(p, subURI.toString()));
}
}
return valList;
}
示例4: readList
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
/**
* 读列表
*
* @param range
*/
private void readList(Range range) {
int num = range.numParagraphs();
Paragraph para;
for (int i = 0; i < num; i++) {
para = range.getParagraph(i);
if (para.isInList()) {
System.out.println("list: " + para.text());
}
}
}
示例5: getWordParagraphText
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
/**
* Get the text from the word file, as an array with one String
* per paragraph
*/
public static String[] getWordParagraphText(HWPFDocument doc) {
String[] ret;
// Extract using the model code
try {
Range r = doc.getRange();
ret = new String[r.numParagraphs()];
for(int i=0; i<ret.length; i++) {
Paragraph p = r.getParagraph(i);
ret[i] = p.text();
// Fix the line ending
if(ret[i].endsWith("\r")) {
ret[i] = ret[i] + "\n";
}
}
}
catch(Exception e) {
// Something's up with turning the text pieces into paragraphs
// Fall back to ripping out the text pieces
ret = new String[1];
ret[0] = getWordTextFromPieces(doc);
}
return ret;
}
示例6: dumpParagraphsDom
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
public void dumpParagraphsDom( boolean withText )
{
Range range = _doc.getOverallRange();
for ( int p = 0; p < range.numParagraphs(); p++ )
{
Paragraph paragraph = range.getParagraph( p );
System.out.println( p + ":\t" + paragraph.toString() );
if ( withText )
System.out.println( paragraph.text() );
}
}
示例7: writePDFFromDoc
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
public static void writePDFFromDoc(
final String docFilePath,
final String pdfFilePath) throws SSErr{
try{
final Document document = new Document();
final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath));
final HWPFDocument word = new HWPFDocument (fs);
final WordExtractor we = new WordExtractor (word);
final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath);
final PdfWriter writer = PdfWriter.getInstance(document, out);
final Range range = word.getRange();
document.open();
writer.setPageEmpty(true);
document.newPage();
writer.setPageEmpty(true);
String[] paragraphs = we.getParagraphText();
for (int i = 0; i < paragraphs.length; i++) {
org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i);
// CharacterRun run = pr.getCharacterRun(i);
// run.setBold(true);
// run.setCapitalized(true);
// run.setItalic(true);
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
System.out.println("Length:" + paragraphs[i].length());
System.out.println("Paragraph" + i + ": " + paragraphs[i].toString());
// add the paragraph to the document
document.add(new Paragraph(paragraphs[i]));
}
document.close();
}catch(Exception error){
SSServErrReg.regErrThrow(error);
}
}
示例8: processParagraphes
import org.apache.poi.hwpf.usermodel.Range; //导入方法依赖的package包/类
protected void processParagraphes( HWPFDocumentCore wordDocument,
Element flow, Range range, int currentTableLevel )
{
final int paragraphs = range.numParagraphs();
for ( int p = 0; p < paragraphs; p++ )
{
Paragraph paragraph = range.getParagraph( p );
if ( paragraph.isInTable()
&& paragraph.getTableLevel() != currentTableLevel )
{
if ( paragraph.getTableLevel() < currentTableLevel )
throw new IllegalStateException(
"Trying to process table cell with higher level ("
+ paragraph.getTableLevel()
+ ") than current table level ("
+ currentTableLevel
+ ") as inner table part" );
Table table = range.getTable( paragraph );
processTable( wordDocument, flow, table );
p += table.numParagraphs();
p--;
continue;
}
if ( paragraph.text().equals( "\u000c" ) )
{
processPageBreak( wordDocument, flow );
}
boolean processed = false;
if ( paragraph.isInList() )
{
try
{
HWPFList hwpfList = paragraph.getList();
String label = AbstractWordUtils.getBulletText(
numberingState, hwpfList,
(char) paragraph.getIlvl() );
processParagraph( wordDocument, flow, currentTableLevel,
paragraph, label );
processed = true;
}
catch ( Exception exc )
{
log.log(
POILogger.WARN,
"Can't process paragraph as list entry, will be processed without list information",
exc );
}
}
if ( processed == false )
{
processParagraph( wordDocument, flow, currentTableLevel,
paragraph, AbstractWordUtils.EMPTY );
}
}
}