Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners POI Word document (Letter Template)
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shashi Kanth Karnati
POI Word document (Letter Template)
5 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


Dear Team,

  • i need code for generating word document(letter format).
  • i am unable to get the code for formats, font settings, letter type settings.

    please help me for the same.

Thanks in Advance.


Advertisement
View Answers

July 20, 2011 at 4:07 PM


import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class WriteInDocument{
public static void main(String[] args)throws IOException{
File file = new File("C:/sample.doc");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
CharacterRun run = range.insertAfter("Hello World!");
run.setFontSize(2 * 18);
run.setBold(true);
run.setItalic(true);
run.setCapitalized(true);
OutputStream out = new FileOutputStream(new File("C:/new.doc"));
doc.write(out);
out.flush();
out.close();
 }
}


July 21, 2011 at 12:47 PM


HI, Thank you for you reply,

  • Here Presently downloaded the jar file "poi-scratchpad-3.5-FINAL " from POI site.
  • This jar file doesn't having the package "poifs.filesystem"
  • Which jar file i need to consider from where ??
  • I am also generating the Excels, with this jar file, package "poi.hssf.usermodel" , here i don't have any problem

Regards, Shashi Kanth



July 21, 2011 at 4:28 PM


File sample_file = new File("sample.doc");
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(sample_file));
    HWPFDocument doc = new HWPFDocument(fs);"
--am getting following error at web page : 


      cannot access org.apache.poi.POIDocument file org\apache\poi\POIDocument.class not found 
HWPFDocument doc = new HWPFDocument(fs); ^ 1


July 22, 2011 at 11:15 AM


Hi , System still showing the same error,

**POIDocument file org\apache\poi\POIDocument.class not found HWPFDocument**

Eclipse not showing any cause/error , am getting this error while running my application, control not even entering in to the first jsp line too.

I think here am using the wrong jar file(Version difference), please let me know, Which jar file we need to put in our application to Use the above code and to avoid this error ?

Thanks in Advance ,

Shashi



April 6, 2012 at 12:06 PM


Hi, I am getting following Exception when trying to run this code.

java.lang.NoSuchMethodError: org.apache.poi.POIDocument.< init >

Code Snippet:

try {

            File file = new File(externalPath + "/abc.doc");
            POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
            HWPFDocument doc = new HWPFDocument(fs);
            Range range = doc.getRange();
            CharacterRun run = range.insertAfter("Hello World!");
            run.setFontSize(2 * 18);
            run.setBold(true);
            run.setItalic(true);
            run.setCapitalized(true);
            OutputStream out = new FileOutputStream(new File(externalPath + "/agnew.doc"));
            doc.write(out);
            out.flush();
            out.close();

        } catch (Exception ex) {
            Log.e("Exception==","=="+ex.toString());
              ex.printStackTrace();
        }

Logcat : FATAL EXCEPTION: main : java.lang.NoSuchMethodError: org.apache.poi.POIDocument. : at org.apache.poi.hwpf.HWPFDocumentCore.(HWPFDocumentCore.java:145) : at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:218) : at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:186) : at com.vikas.prudent.CreateDocument.onCreate(CreateDocument.java:45) : at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) : at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) : at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) : at android.app.ActivityThread.access$2300(ActivityThread.java:125) : at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) : at android.os.Handler.dispatchMessage(Handler.java:99) : at android.os.Looper.loop(Looper.java:123) : at android.app.ActivityThread.main(ActivityThread.java:4627) : at java.lang.reflect.Method.invokeNative(Native Method) : at java.lang.reflect.Method.invoke(Method.java:521) : at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) : at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) : at dalvik.system.NativeStart.main(Native Method)



Related Tutorials/Questions & Answers:
POI Word document (Letter Template)
POI Word document (Letter Template)  Dear Team, i need code for generating word document(letter format). i am unable to get the code for formats, font settings, letter type settings. please help me for the same. Thanks
Edit word document Headers and Footers using POI Library in java?
Edit word document Headers and Footers using POI Library in java?  Hi All, I need code to modify the Header and Footer contents of a ms-word template using POI or JACOB libraries. Could any one help me? Thanks Advance
Advertisements
Using poi hwpf,how to create table in word document. - Java Beginners
Using poi hwpf,how to create table in word document.  Can you please tell me how to create a table in the word document in java using Apache poi hwpf.its very urgent.Please send some sample code.Thanks in advance
How to hide text in Word Document using Apache POI library
How to hide text in Word Document using Apache POI library  Is it possible to hide text in MS Word Document using Apache POI library? If yes, please let me know how. I am able to create and read the document using POI library
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
Write String in Word document
Write String in Word document  How to read and write strings in word document
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated PDFs also. I got a code like the below, and i am unable to download the office
store form data into word document
store form data into word document  i want form page data, ex username phone number.. to store it in a word document file
word document reading - Development process
word document reading  I am in the midst of reading a word document while reading charts(EMF or WMF) pictures i am not able to do so can u suggest one class for this to accomplish
letter counting for the smallest word
letter counting for the smallest word  How do I program my java... and it works EXCEPT that it counts all of the letters not just the smallest word...(); int count=ch.length; System.out.println("Count of smallest word
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
How to merge two word document using java
How to merge two word document using java   how to merge two word document using java
Java Read .doc file using POI library
Java Read .doc file using POI library In this section, you will learn how to read the word document file using POI library. The class HWPFDocument throw all... the Word Document. The method  getParagraphText() of WordExtractor class
JTextArea to Word Document
JTextArea to Word Document Jakarta POI has provided several classes... to write the data into word document file through a swing component. You can... saved in the word file using POI classes. And you can view your file by clicking
export to word document - Java Beginners
export to word document  hi sir,when i am click on a button under the jtable,for example (print button),then i want to print that jtable in word document,automatically,plz provide program sir  Hi Friend, Try
java code to open and display MS-word document
java code to open and display MS-word document  java code to open and display MS-word document
Creating MS Word document in java - Struts
Creating MS Word document in java  I have one template in MS Word which has some content. Now i want to read this doc file and wants to add some content and also i need to set header and footer in doc file. That is, reading
APACHE.POI -- Create word Document - Development process
APACHE.POI -- Create word Document  Hi, Could any one please post the code which creates the word document having different paragraphs and two... this code everywhere. But i need to write more to the document like Table inserting
upload and retrieve a word document - JSP-Servlet
upload and retrieve a word document  Hi, I have a problem with uploading a word document to My sql database to a BLOB data type variable. And also unable to retrieve the word document from database. I am writing the code
Display first letter of every word in uppercase
Display first letter of every word in upper case In this Java tutorial section, you will learn how to display the first letter of every word in uppercase...;inputString = br.readLine(); FirstLetter letter=new FirstLetter
Open Text or Word Document on JButton Click in Java - Java Beginners
Open Text or Word Document on JButton Click in Java  How to open Word document or Text File on JButton Click in java  Hi Friend, Try the following code: import java.io.*; import java.util.*; import javax.swing.
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?   How to set a microsoft word document PASSWORD by using Visual Basic 2008 express
open document
open document  open a word document using jsp   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
create , edit MS WORD like document file using Java Swing - Swing AWT
create , edit MS WORD like document file using Java Swing   In my..., font style etc. I want this text in JTextArea to be saved to MS WORD like document file. Then how should I create, edit , retrieve this document file
Create Excel(.xlsx) document using Apache POI
Create Excel(.xlsx) document using Apache POI In this section, you will learn how to create a Excel sheet having .xlsx extension using Apache POI library. In the given below example, we will going to create excel document having one
Read Excel(.xlsx) document using Apache POI
Read Excel(.xlsx) document using Apache POI In this section, you will learn how to read Excel file having .xlsx extension using Apache POI library. In the below example, we will read excel document having one sheet named as "new
Advertisements
 

 

 

DMCA.com