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 style

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.

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 getting the type font is ambiguous and type imgae ambiguous ? document.open(); 32: Font headFont = FontFactory.getFont(FontFactory.HELVETICA
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 geeting ambiguous error .Do u want to add any jar files   Hi Friend, Import the class Font into your JSP page like the following
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
Simple Font Paint Example
. A font is a specific style of displaying characters. It describes the design, size.... A glyph is an element of writing and displaying characters in a style. Class... Simple Font Paint Example   
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
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
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
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
Java get available Font
Java get available Font   ... font. In order to retrieve all the available fonts, we have used the AWT... the available GraphicsDevices and Font objects.ADS_TO_REPLACE_1 getAllFonts
ModuleNotFoundError: No module named 'font-font-awesome'
ModuleNotFoundError: No module named 'font-font-awesome'  Hi, My... named 'font-font-awesome' How to remove the ModuleNotFoundError: No module named 'font-font-awesome' error? Thanks   Hi, In your
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... into font selector object its return type is void. process(String
Draw Font Using Canvas Example
() int getFont(int face, int style, int size) Font... Draw Font Using Canvas Example       This example is used to draw the different types of font using
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
; The method deriveFont(int style) creates a new font object, applying a new style... Font Derivation       In this section, you will studied about the font derivation. Font
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
Change font in swing?
Change font in swing?  I want to use marathi language on labels,buttons
Maven dependency for org.webjars - font-awesome version 5.15.2 is released. Learn to use font-awesome version 5.15.2 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.15.2 ) in their Java project... and includes  org.webjars - font-awesome version 5.15.2 java library in your project...Maven dependency for  org.webjars  - Version 5.15.2 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.15.3 is released. Learn to use font-awesome version 5.15.3 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.15.3 ) in their Java project... and includes  org.webjars - font-awesome version 5.15.3 java library in your project...Maven dependency for  org.webjars  - Version 5.15.3 of font-awesome
Maven dependency for org.webjars - font-awesome version 4.0.0 is released. Learn to use font-awesome version 4.0.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 4.0.0 ) in their Java project... and includes  org.webjars - font-awesome version 4.0.0 java library in your...Maven dependency for  org.webjars  - Version 4.0.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 6.0.0 is released. Learn to use font-awesome version 6.0.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 6.0.0 ) in their Java project... and includes  org.webjars - font-awesome version 6.0.0 java library in your...Maven dependency for  org.webjars  - Version 6.0.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 6.1.0 is released. Learn to use font-awesome version 6.1.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 6.1.0 ) in their Java project... and includes  org.webjars - font-awesome version 6.1.0 java library in your...Maven dependency for  org.webjars  - Version 6.1.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 6.2.0 is released. Learn to use font-awesome version 6.2.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 6.2.0 ) in their Java project... and includes  org.webjars - font-awesome version 6.2.0 java library in your...Maven dependency for  org.webjars  - Version 6.2.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.15.4 is released. Learn to use font-awesome version 5.15.4 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.15.4 ) in their Java project... and includes  org.webjars - font-awesome version 5.15.4 java library...Maven dependency for  org.webjars  - Version 5.15.4 of font-awesome
Maven dependency for org.webjars - font-awesome version 6.1.1 is released. Learn to use font-awesome version 6.1.1 in Maven based Java projects
this version ( org.webjars - font-awesome version 6.1.1 ) in their Java project... and includes  org.webjars - font-awesome version 6.1.1 java library in your...Maven dependency for  org.webjars  - Version 6.1.1 of font-awesome
Maven dependency for org.webjars - font-awesome version 6.1.2 is released. Learn to use font-awesome version 6.1.2 in Maven based Java projects
this version ( org.webjars - font-awesome version 6.1.2 ) in their Java project... and includes  org.webjars - font-awesome version 6.1.2 java library in your...Maven dependency for  org.webjars  - Version 6.1.2 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.15.1 is released. Learn to use font-awesome version 5.15.1 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.15.1 ) in their Java project... and includes  org.webjars - font-awesome version 5.15.1 java library...Maven dependency for  org.webjars  - Version 5.15.1 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.15.0 is released. Learn to use font-awesome version 5.15.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.15.0 ) in their Java project... and includes  org.webjars - font-awesome version 5.15.0 java library...Maven dependency for  org.webjars  - Version 5.15.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.14.0 is released. Learn to use font-awesome version 5.14.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.14.0 ) in their Java project... and includes  org.webjars - font-awesome version 5.14.0 java library...Maven dependency for  org.webjars  - Version 5.14.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.13.1 is released. Learn to use font-awesome version 5.13.1 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.13.1 ) in their Java project... and includes  org.webjars - font-awesome version 5.13.1 java library...Maven dependency for  org.webjars  - Version 5.13.1 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.13.0 is released. Learn to use font-awesome version 5.13.0 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.13.0 ) in their Java project... and includes  org.webjars - font-awesome version 5.13.0 java library...Maven dependency for  org.webjars  - Version 5.13.0 of font-awesome
Maven dependency for org.webjars - font-awesome version 5.6.1 is released. Learn to use font-awesome version 5.6.1 in Maven based Java projects
this version ( org.webjars - font-awesome version 5.6.1 ) in their Java project... and includes  org.webjars - font-awesome version 5.6.1 java library in your...Maven dependency for  org.webjars  - Version 5.6.1 of font-awesome
Maven dependency for org.webjars - font-awesome version 4.6.3 is released. Learn to use font-awesome version 4.6.3 in Maven based Java projects
this version ( org.webjars - font-awesome version 4.6.3 ) in their Java project... and includes  org.webjars - font-awesome version 4.6.3 java library in your...Maven dependency for  org.webjars  - Version 4.6.3 of font-awesome
Maven dependency for org.webjars.bower - font-awesome version 4.6.1 is released. Learn to use font-awesome version 4.6.1 in Maven based Java projects
; org.webjars.bower - font-awesome version 4.6.1 in Java projects. Follow... that downloads and includes  org.webjars.bower - font-awesome version 4.6.1 java...Maven dependency for  org.webjars.bower  - Version 4.6.1 of font
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
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... Show Font Dialog and Color Dialog   
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
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... { public static void main(String[] args) { File file = null; WordExtractor
ModuleNotFoundError: No module named 'font-ttfa'
ModuleNotFoundError: No module named 'font-ttfa'  Hi, My Python... 'font-ttfa' How to remove the ModuleNotFoundError: No module named 'font... have to install padas library. You can install font-ttfa python with following
ModuleNotFoundError: No module named 'font-unicode'
ModuleNotFoundError: No module named 'font-unicode'  Hi, My Python... 'font-unicode' How to remove the ModuleNotFoundError: No module named 'font-unicode' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'maoyan-font'
ModuleNotFoundError: No module named 'maoyan-font'  Hi, My Python... 'maoyan-font' How to remove the ModuleNotFoundError: No module named 'maoyan-font' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'font-converter'
ModuleNotFoundError: No module named 'font-converter'  Hi, My... named 'font-converter' How to remove the ModuleNotFoundError: No module named 'font-converter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'font-intuitive'
ModuleNotFoundError: No module named 'font-intuitive'  Hi, My... named 'font-intuitive' How to remove the ModuleNotFoundError: No module named 'font-intuitive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'font-roboto'
ModuleNotFoundError: No module named 'font-roboto'  Hi, My Python... 'font-roboto' How to remove the ModuleNotFoundError: No module named 'font-roboto' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'Font-Sampler'
ModuleNotFoundError: No module named 'Font-Sampler'  Hi, My Python... 'Font-Sampler' How to remove the ModuleNotFoundError: No module named 'Font-Sampler' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'font-ttfa'
ModuleNotFoundError: No module named 'font-ttfa'  Hi, My Python... 'font-ttfa' How to remove the ModuleNotFoundError: No module named 'font... have to install padas library. You can install font-ttfa python with following
ModuleNotFoundError: No module named 'font-v'
ModuleNotFoundError: No module named 'font-v'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'font-v' How to remove the ModuleNotFoundError: No module named 'font-v'
ModuleNotFoundError: No module named 'font-roboto'
ModuleNotFoundError: No module named 'font-roboto'  Hi, My Python... 'font-roboto' How to remove the ModuleNotFoundError: No module named 'font-roboto' error? Thanks   Hi, In your python environment

Ads