• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic