当前位置: 首页>>代码示例>>Java>>正文


Java HWPFDocument.getRange方法代码示例

本文整理汇总了Java中org.apache.poi.hwpf.HWPFDocument.getRange方法的典型用法代码示例。如果您正苦于以下问题:Java HWPFDocument.getRange方法的具体用法?Java HWPFDocument.getRange怎么用?Java HWPFDocument.getRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.hwpf.HWPFDocument的用法示例。


在下文中一共展示了HWPFDocument.getRange方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replaceWordDoc

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void replaceWordDoc(String inPath, String outPath, Map<String, String> context) {
	Validate.notBlank(inPath);
	Validate.notBlank(outPath);
	Validate.notNull(context);
	try (FileInputStream in = new FileInputStream(new File(inPath));
			FileOutputStream out = new FileOutputStream(outPath, false)) {
		HWPFDocument hdt = new HWPFDocument(in);
		Range range = hdt.getRange();
		for (Map.Entry<String, String> entry : context.entrySet()) {
			range.replaceText(entry.getKey(), entry.getValue());
		}
		hdt.write(out);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:17,代码来源:Replacer.java

示例2: saveDoc

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
/**
 * Method to save the file by parameters in doc format
 *
 * @param toSave The file where the information will be saved
 */
private void saveDoc(File toSave) {
  try {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("down/empty.doc"));
    HWPFDocument doc = new HWPFDocument(fs);
    Range range = doc.getRange();
    Paragraph parContainer = range.insertAfter(new ParagraphProperties(), 0);
    for (String para : paragraphs) {
      parContainer.setSpacingAfter(200);
      parContainer.insertAfter(para);
      parContainer = range.insertAfter(new ParagraphProperties(), 0);
    }
    FileOutputStream fos = new FileOutputStream(toSave);
    doc.write(fos);
    fos.close();
  } catch (Exception e) {
    Logger.getGlobal().log(Level.SEVERE, e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
  }
}
 
开发者ID:ames89,项目名称:clippyboard,代码行数:24,代码来源:FileExportCreator.java

示例3: CreateDocFromTemplate

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
/**
 * 创建Doc并保存
 *
 * @param templatePath 模板doc路径
 * @param parameters   参数和值
 *                     //* @param imageParameters 书签和图片
 * @param savePath     保存doc的路径
 * @return
 */
public static void CreateDocFromTemplate(String templatePath,
                                         HashMap<String, String> parameters,
                                         //HashMap<String, String> imageParameters,
                                         String savePath)
        throws Exception {
    @Cleanup InputStream is = DocProducer.class.getResourceAsStream(templatePath);
    HWPFDocument doc = new HWPFDocument(is);
    Range range = doc.getRange();

    //把range范围内的${}替换
    for (Map.Entry<String, String> next : parameters.entrySet()) {
        range.replaceText("${" + next.getKey() + "}",
                next.getValue()
        );
    }

    @Cleanup OutputStream os = new FileOutputStream(savePath);
    //把doc输出到输出流中
    doc.write(os);
}
 
开发者ID:izhangzhihao,项目名称:OfficeProducer,代码行数:30,代码来源:DocProducer.java

示例4: testReadByDoc

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
@Test
	public void testReadByDoc() throws Exception {
		InputStream is = new FileInputStream("E://video/doc/xiuParty/90Xiu-NEW/oss/90秀--oss与服务器端接口文档.doc");
		POIFSFileSystem pfilesystem = new POIFSFileSystem(is);
		HWPFDocument doc = new HWPFDocument(pfilesystem);
//		// 输出书签信息
//		this.printInfo(doc.getBookmarks());
//		// 输出文本
//		System.out.println(doc.getDocumentText());
		Range range = doc.getRange();
		// this.insertInfo(range);
		this.printInfo(range);
		// 读表格
		this.readTable(range);
		// 读列表
		this.readList(range);
		// 删除range
		Range r = new Range(2, 5, doc);
		r.delete();// 在内存中进行删除,如果需要保存到文件中需要再把它写回文件
		// 把当前HWPFDocument写到输出流中
		doc.write(new FileOutputStream("D:\\test.doc"));
		IOUtils.closeQuietly(is);
	}
 
开发者ID:East196,项目名称:maker,代码行数:24,代码来源:HwpfTest.java

示例5: processParagraphRequest

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的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;
}
 
开发者ID:chsatgithub,项目名称:PANDA-DEEPLINKING,代码行数:33,代码来源:DataWordResource.java

示例6: read

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public  ArrayList<TableData> read(String path) throws IOException {
		FileInputStream in = new FileInputStream(new File(path));  
        HWPFDocument hwpf = new HWPFDocument(in);  
        Range range = hwpf.getRange();// 得到文档的读取范围  
        TableIterator it = new TableIterator(range);  
        ArrayList<TableData> list=new ArrayList<TableData>();
        int count=0;
        // 迭代文档中的表格  
        while (it.hasNext()) {  
            Table tb = (Table) it.next();  
            TableData data=new TableData();
            // 迭代行,默认从0开始  
            for (int i = 0; i < tb.numRows(); i++) {  
                TableRow tr = tb.getRow(i);  
                // 迭代列,默认从0开始  
                for (int j = 0; j < tr.numCells(); j++) {  
                    TableCell td = tr.getCell(j);// 取得单元格  
                    // 取得单元格的内容  
                    StringBuffer sb=new StringBuffer();
                    for (int k = 0; k < td.numParagraphs(); k++) {  
                        Paragraph para = td.getParagraph(k);  
                        sb.append(para.text());  
                    } 
                    String string=sb.toString().trim();
                    if(i==0&&j==1)
                    {
                    	data.setClazz(string);
                    }
                    else if(i==1&&j==1)
                    {
                    	data.setName(string);
                    }
                    else if(i==2&&j==1)
                    {
                    	data.setLifeCircle(string);
                    }
                    else if(i==2&&j==3)
                    {
                    	data.setTheme(string);
                    }
                    else if(i==3&&j==3)
                    {
                    	data.setForm(string);
                    }
                    else if(i==4&&j==1)
                    {
                    	data.setKeywords(string);
                    }
                    else if(i==9&&j==1)
                    {
                    	data.setContent(string);
                    }
                }  
            }
//            show("第"+count+"条:"+data.toString());
            count+=1;
            list.add(data);
        }
		return list;
	}
 
开发者ID:wanxu,项目名称:ReadTableFromWord,代码行数:61,代码来源:TableReader.java

示例7: main

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	HWPFDocument doc = new HWPFDocument(new FileInputStream(
			"data/document.doc"));

	Range range = doc.getRange();
	String text = range.text();
	
	System.out.println("Range: " + text);
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:11,代码来源:ApacheRanges.java

示例8: main

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithranges/accessranges/data/";
	
	HWPFDocument doc = new HWPFDocument(new FileInputStream(
			dataPath + "document.doc"));

	Range range = doc.getRange();
	String text = range.text();
	
	System.out.println("Range: " + text);
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:13,代码来源:ApacheRanges.java

示例9: getWordParagraphText

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的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;
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:32,代码来源:MSOfficeBox.java

示例10: writePDFFromDoc

import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的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);
  }
}
 
开发者ID:learning-layers,项目名称:SocialSemanticServer,代码行数:41,代码来源:SSFileU.java


注:本文中的org.apache.poi.hwpf.HWPFDocument.getRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。