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


Java HWPFDocument类代码示例

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


HWPFDocument类属于org.apache.poi.hwpf包,在下文中一共展示了HWPFDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handleHeaderFooter

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的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");
  }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:25,代码来源:WordExtractor.java

示例3: 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

示例4: 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"));
	List<Picture> pics = doc.getPicturesTable().getAllPictures();
	
	for (int i = 0; i < pics.size(); i++)
	{
		Picture pic = (Picture) pics.get(i);
	
		FileOutputStream outputStream = new FileOutputStream(
				"data/apacheImages/" + "Apache_"
						+ pic.suggestFullFileName());
		outputStream.write(pic.getContent());
		outputStream.close();
	}
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:18,代码来源:ApacheExtractImages.java

示例5: readDoc

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
private String readDoc(String path) {
    String content = "";
    try {
        File file = new File(path);
        FileInputStream fis = new FileInputStream(file.getAbsolutePath());

        HWPFDocument doc = new HWPFDocument(fis);

        WordExtractor we = new WordExtractor(doc);
        String[] paragraphs = we.getParagraphText();
        for (String para : paragraphs) {
            content += para.toString();
        }
        fis.close();
        return content;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return content;
}
 
开发者ID:jatanrathod,项目名称:Idea-Plagiarism,代码行数:21,代码来源:checkPlagiarism.java

示例6: 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

示例7: readDocFile

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
public String readDocFile(File file){
	FileInputStream fis = null;
	String text = null;
	try {
		fis = new FileInputStream(file);
	} catch (FileNotFoundException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	try {
		HWPFDocument hwpf = new HWPFDocument(fis);
		text = hwpf.getText().toString();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return text;
}
 
开发者ID:piiiiq,项目名称:Black,代码行数:19,代码来源:ioThread.java

示例8: parseDoc2Html

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
public static String parseDoc2Html(InputStream input, String charset) throws Exception {
  HWPFDocument wordDocument = new HWPFDocument(input);
  Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
  WordToHtmlConverter converter = new WordToHtmlConverter(doc);
  converter.processDocument(wordDocument);

  ByteArrayOutputStream output = new ByteArrayOutputStream();
  try {
    DOMSource domSource = new DOMSource(converter.getDocument());
    StreamResult streamResult = new StreamResult(output);
    Transformer serializer = TransformerFactory.newInstance().newTransformer();
    // TODO 有乱码
    serializer.setOutputProperty(OutputKeys.ENCODING, charset);
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.setOutputProperty(OutputKeys.METHOD, "html");
    serializer.transform(domSource, streamResult);
  } finally {
    input.close();
    output.close();
  }

  return new String(output.toByteArray());
}
 
开发者ID:xsocket,项目名称:job,代码行数:24,代码来源:WordUtils.java

示例9: 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

示例10: 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"));
	SummaryInformation summaryInfo = doc.getSummaryInformation();
	System.out.println(summaryInfo.getApplicationName());
	System.out.println(summaryInfo.getAuthor());
	System.out.println(summaryInfo.getComments());
	System.out.println(summaryInfo.getCharCount());
	System.out.println(summaryInfo.getEditTime());
	System.out.println(summaryInfo.getKeywords());
	System.out.println(summaryInfo.getLastAuthor());
	System.out.println(summaryInfo.getPageCount());
	System.out.println(summaryInfo.getRevNumber());
	System.out.println(summaryInfo.getSecurity());
	System.out.println(summaryInfo.getSubject());
	System.out.println(summaryInfo.getTemplate());
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:19,代码来源:ApacheDocumentProperties.java

示例11: main

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithdocuments/getdocumentproperties/data/";
	
	HWPFDocument doc = new HWPFDocument(new FileInputStream(
			dataPath + "document.doc"));
	SummaryInformation summaryInfo = doc.getSummaryInformation();
	System.out.println(summaryInfo.getApplicationName());
	System.out.println(summaryInfo.getAuthor());
	System.out.println(summaryInfo.getComments());
	System.out.println(summaryInfo.getCharCount());
	System.out.println(summaryInfo.getEditTime());
	System.out.println(summaryInfo.getKeywords());
	System.out.println(summaryInfo.getLastAuthor());
	System.out.println(summaryInfo.getPageCount());
	System.out.println(summaryInfo.getRevNumber());
	System.out.println(summaryInfo.getSecurity());
	System.out.println(summaryInfo.getSubject());
	System.out.println(summaryInfo.getTemplate());
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:21,代码来源:ApacheDocumentProperties.java

示例12: main

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithimages/extractimagesfromdocument/data/";

	HWPFDocument doc = new HWPFDocument(new FileInputStream(
			dataPath + "document.doc"));
	List<Picture> pics = doc.getPicturesTable().getAllPictures();
	
	for (int i = 0; i < pics.size(); i++)
	{
		Picture pic = (Picture) pics.get(i);
	
		FileOutputStream outputStream = new FileOutputStream(
				dataPath + "Apache_"
						+ pic.suggestFullFileName());
		outputStream.write(pic.getContent());
		outputStream.close();
	}
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:20,代码来源:ApacheExtractImages.java

示例13: processOle2

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
private boolean processOle2( HWPFDocument doc, CharacterRun characterRun,
        Element block )
{
    Entry entry = doc.getObjectsPool().getObjectById(
            "_" + characterRun.getPicOffset() );
    if ( entry == null )
    {
        logger.log( POILogger.WARN, "Referenced OLE2 object '",
                Integer.valueOf( characterRun.getPicOffset() ),
                "' not found in ObjectPool" );
        return false;
    }

    try
    {
        return processOle2( doc, block, entry );
    }
    catch ( Exception exc )
    {
        logger.log( POILogger.WARN,
                "Unable to convert internal OLE2 object '",
                Integer.valueOf( characterRun.getPicOffset() ), "': ", exc,
                exc );
        return false;
    }
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:27,代码来源:AbstractWordConverter.java

示例14: processNote

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
protected void processNote( HWPFDocument wordDocument, Element block,
        Range noteTextRange )
{
    final int noteIndex = noteCounters.getAndIncrement();
    block.appendChild( textDocumentFacade
            .createText( UNICODECHAR_ZERO_WIDTH_SPACE + "[" + noteIndex
                    + "]" + UNICODECHAR_ZERO_WIDTH_SPACE ) );

    if ( notes == null )
        notes = textDocumentFacade.createBlock();

    Element note = textDocumentFacade.createBlock();
    notes.appendChild( note );

    note.appendChild( textDocumentFacade.createText( "^" + noteIndex
            + "\t " ) );
    processCharacters( wordDocument, Integer.MIN_VALUE, noteTextRange, note );
    note.appendChild( textDocumentFacade.createText( "\n" ) );
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:20,代码来源:WordToTextConverter.java

示例15: dumpBookmarks

import org.apache.poi.hwpf.HWPFDocument; //导入依赖的package包/类
private void dumpBookmarks()
{
    if ( !( _doc instanceof HWPFDocument ) )
    {
        System.out.println( "Word 95 not supported so far" );
        return;
    }

    HWPFDocument document = (HWPFDocument) _doc;
    Bookmarks bookmarks = document.getBookmarks();
    for ( int b = 0; b < bookmarks.getBookmarksCount(); b++ )
    {
        Bookmark bookmark = bookmarks.getBookmark( b );
        System.out.println( "[" + bookmark.getStart() + "; "
                + bookmark.getEnd() + "): " + bookmark.getName() );
    }
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:18,代码来源:HWPFLister.java


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