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



Home Answers Viewqa Java-Beginners writing document (.doc) file from java with format such as font type, font style
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ayuugyi
writing document (.doc) file from java with format such as font type, font style
2 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


Can anyone help me how can i write a java code to write a string with format such as font type and style to a document file? Thanks in advance.


Advertisement
View Answers

March 14, 2011 at 4:48 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();
 }
}

For the above code, poi-scratchpad-3.7-20101029.jar is needed.



September 22, 2012 at 3:42 PM


its not working correctly..font style is not getting changed. any1 tell me right method



Related Tutorials/Questions & Answers:
writing document (.doc) file from java with format such as font type, font style
writing document (.doc) file from java with format such as font type, font... with format such as font type and style to a document file? Thanks in advance... FileInputStream(file)); HWPFDocument doc = new HWPFDocument(fs); Range range
The type Font is ambiguous where generating pdf file from jsp page - JSP-Servlet
The type Font is ambiguous where generating pdf file from jsp page  I am geeting ambiguous error .Do u want to add any jar files   Hi Friend, Import the class Font into your JSP page like the following
Advertisements
The type Font is ambiguous where generating pdf file from jsp page - JSP-Servlet
The type Font is ambiguous where generating pdf file from jsp page  i am getting the type font is ambiguous and type imgae ambiguous ? document.open(); 32: Font headFont = FontFactory.getFont(FontFactory.HELVETICA
serch document from .doc and .docx file
serch document from .doc and .docx file  how to find particular word from .doc and .docx file and that date insert into a data base
To change font in java code
To change font in java code  I am sending system generated mail through MIME message and Transport. Now i need to change the font.. Can you please help me as how to change the font of string body in java code
Embedded Font in Flex4
Embedded font in Flex4: You can embedded the font in your application. There are some file type of fonts: 1. True Type fonts (*.ttf) 2. Open Type fonts (*.otf) 3. True Type Collection (*.ttc) 4. Mac Data Fork Fonts (*.dfont
font changing
font changing  I have created a welcome page and when I try to change the font style of the label named lblCName it does not change.Indentify..., placeOrdr; Icon image; Font fnt; public void init(){ fnt=new Font("Verdana
Simple Font Paint Example
. A font is a specific style of displaying characters. It describes the design, size... is an element of writing and displaying characters in a style. Class GlyphVector... = "Java is an Object Oriented Programming Language.";         Font font = new
Java get available Font
Java get available Font   .... It returns the font name. Here is the code of GetAvailableFont .java... font. In order to retrieve all the available fonts, we have used the AWT package
Explain the parameters of Font class constructor.
the parameters of Font class constructor.   Java Font class: Font(String name,int style,int size): It creates a new Font from the specified name, style.... If name is null, the name of the new Font is set to the name "Default". style
iPhone Font Size
choose any style for your type of font. What all we need to do is select the "... iPhone Font Size In this example we are going to change the iphone font size and color. You can change the font size and font type using
doc file - Java Beginners
doc file   i want to read .doc file ?....it is a part of my project plz help. if possible , can anyone give me the code
Draw Font Using Canvas Example
, int style, int size) Font getHeight() int...;styles [style], sizes [size]);   g.setFont(font);  ... Draw Font Using Canvas Example     
HTML font tag.
for designing not for development.</font> <br/> <font style...HTML font tag. Description : It is a HTML tag, which is used for changing the view of your text. Which will display on view page. Syntax : <font
Font Derivation
(int style) creates a new font object, applying a new style... Font Derivation       In this section, you will studied about the font derivation. Font
Change font in swing?
Change font in swing?  I want to use marathi language on labels,buttons
UILabel Font Size
UILabel Font Size  Hi Developers, How to set font size of UILabel? I am creating label programmatically and I have to set the font size programatically. How I can set UILabel Font Size? Thanks   HI, Following
Font Selection
have to decide the specific font name for the specific text from the pdf content and the font name has to be mentioned in the java code during...(String input) is use to process the font on the text .Its return type
How to read a line from a doc file
How to read a line from a doc file  How to read a line from a doc file   Hi Friend, To run the following code, you need to download POI... void main(String[] args) { File file = null; WordExtractor extractor = null
Show Font Dialog and Color Dialog
and font dialog in Java. SWT allows to show Color Dialog and Font Dialog... the font dialog and allow the user to select a font from the available fonts... the color from the set of available colors. The method dialog.open() makes the font
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java.... This way you can read the .doc or .docx file in Java programming language. Thanks
Writing to and reading from a binary file in java.
Writing to and reading from a binary file in java.  I have written... the binary file from another program as follows: m_dis = new DataInputStream... having the format: 00501 40.815400 -73.045600. The entries I get in the binary file
How to display the font in center
How to display the font in center   ... the font in center. To display the font in center, the method paint() is defined. The Font class defines the font 'Monotype 'Corsiva'. The class
Embedded font with multiple typefaces in Flex4
Embedded font with multiple typefaces in Flex4: In this example you can see how we can use a type faces font in multiple form. In this example we use a three font file: simple, bold and italic font. Example: <?xml
How to set Marathi font to Label??
How to set Marathi font to Label??  Hello, I am doing one project in java-Swing Farm Management i want to set Marathi label in that so how i can? plzzzz help me its urgent
how to use marathi font in swing?
how to use marathi font in swing?  I want to use marathi language on labels,buttons
Having problem to set font and color
love to your Mom by type I love You Mom"); msgLabel.setFont(new Font("Monotype...Having problem to set font and color  Hello Sir, i have some problem to set font and color in my program.Can you take a look for the moment please
Font in Flex4
Font in Flex4: In this example you can see how we can use font in a flex application. You will use font for the appearance of the component. You will use font for give a color , size and etc. Example: <?xml version
Storing Data (Retrieved from a XML Document) to a File
Storing Data (Retrieved from a XML Document) to a File... to store data (retrieved from the XML document) to a specified file (with ..., vk.doc, vk.xls, vk.shtml etc. from the XML document. Here is the XML File
Outlining the font
Outlining the font       This section illustrates you how to outline the font. By outlining the font , we make the characters more stylish and impressive. We are providing you
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
Advertisements
 

 

 

DMCA.com