Example usage for org.apache.poi.hwpf.usermodel Range insertBefore

List of usage examples for org.apache.poi.hwpf.usermodel Range insertBefore

Introduction

In this page you can find the example usage for org.apache.poi.hwpf.usermodel Range insertBefore.

Prototype

public CharacterRun insertBefore(String text) 

Source Link

Document

Inserts text into the front of this range.

Usage

From source file:File.DOC.WriteDoc.java

/**
 * @param args the command line arguments
 *//*ww w  .ja  v  a2s  . c om*/
public void Write(String path, String namafile, String content) {
    File file = new File("D:\\xyz.doc");
    try {
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
        HWPFDocument doc = new HWPFDocument(fs);
        Range range = doc.getRange();
        CharacterRun run = range.insertBefore(content.replace("\n", "\013"));
        run.setBold(true);
        OutputStream outa = new FileOutputStream(new File(path + namafile + ".doc"));
        doc.write(outa);
        out.close();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}