aspose file tools*
The moose likes JDBC and the fly likes How to set the text in bold in word file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to set the text in bold in word file using java" Watch "How to set the text in bold in word file using java" New topic
Author

How to set the text in bold in word file using java

upanshu vaid
Ranch Hand

Joined: Sep 07, 2012
Posts: 73

Hi
I am creating the word doc file using java io package but i want to some text to be in bold how can i accomplish that.
Thanks
My code is below

String Customer_Name1 = null,EmailID1 = null;
File myDir=new File("C:\\Users\\DELL\\Desktop\\Bank");
myDir.mkdir();
Transaction_History =new File("C:\\Users\\DELL\\Desktop\\Bank\\Tranasction_History.doc");
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter(Transaction_History)));
} catch (IOException ex) {
Logger.getLogger(HomePage.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
pstmnt = con.prepareStatement("Select Customer_Name,EmailID from LoginInformation where UserId='"+UserId1+"'");
rs_name=pstmnt.executeQuery();
while(rs_name.next())
{
Customer_Name1=rs_name.getString(1);
Customer_Name1=Customer_Name1.toUpperCase();
EmailID1=rs_name.getString(2);
}
try{
out.print("Customer-Name:"+""+Customer_Name1+"\t\t");
out.print("Email-ID:"+""+EmailID1);
out.flush();
out.println();
out.println();
}
catch (Exception e){
e.printStackTrace();
}
}
catch (Exception e){
e.printStackTrace();
}
try {
pstmnt = con.prepareStatement("Select * from Transaction_History where UserId='"+UserId1+"'");
rs=pstmnt.executeQuery();
out.print("Deposit"+"\t"+"WithDraw"+"\t"+"Balance"+"\t"+"Date_History");
out.println();
while(rs.next())
{
String Deposit=rs.getString("Deposit");
String WithDraw=rs.getString("WithDraw");
String Balance=rs.getString("Closing_Balance");
String Date_History=rs.getString("Date_History");
try{

out.print(Deposit+"\t"+WithDraw+"\t\t"+Balance+"\t\t"+Date_History);
out.flush();
out.println();
// Transaction_History.setReadOnly();

}
catch(Exception e){
e.printStackTrace();
}
}

out.close();
try{
Runtime.getRuntime().exec("C:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.EXE "
+"C:\\Users\\DELL\\Desktop\\Bank\\Tranasction_History.doc");

}
catch(Exception e)
{
e.printStackTrace();
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
I am creating the word doc file using java io package

You can't create a DOC file using the java.io package. It's a bit hard to tell, but it looks like you're creating a tab-delimited flat file - text files have no concept of styles at all.

You will either have to use an API that can create DOC files -like the Apache POI library-, or resort to some other solution. One option would be to create an RTF file, which is a text file and can be created much easier than a DOC file.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set the text in bold in word file using java