Thanks for replying.
But this'll set the format for the whole cell. In my case format for
different words  in the cell may be different.



Lee, Jun S. wrote:
> 
> I'm very new to POI but when I was looking through the API,
> I saw you can do:
> 
> HSSFCell.getHSSFCellStyle() and HSSFCellStyle class has setFont.
> That looks like changing style for a single cell.
> 
> Best,
> Jun
> 
> 
> 
> -----Original Message-----
> From: thomas908 [mailto:[EMAIL PROTECTED] 
> Sent: Monday, August 13, 2007 1:11 PM
> To: [email protected]
> Subject: Set character formatting in Excel using POI
> 
> 
> I want to set some values in the excel sheet using POI. These values
> must
> have the required character formatting like bold, italics and underline.
> 
> Say, the value that I need to set in some cell in the excel could be
> something like
> 
> italics plain boldItalics allThree<u> plain</u>
> 
> 
> Whatever is there inside
> .. should be set as italics
> .. should be set as bold
> <u>..</u> should be set as underline
> 
> I was trying to set this formatting by harcoding the indexes (for the
> time
> being) using the following code
> 
> String str="italics plain boldItalics allThree<u> plain</u>";
>       
>       HSSFWorkbook wb;
>       
>       void func()
>       {
>              try{
>                       File writeXcel=new File("C:/newOUT.xls");
>                         FileOutputStream fileOut = new
> FileOutputStream(writeXcel);
>                         wb=new HSSFWorkbook();
>                         HSSFSheet sheet=wb.createSheet("Sheet 1");
>                         HSSFRow row=sheet.createRow(0);
>                         HSSFCell cell=row.createCell((short)0);
>                   
>                         HSSFRichTextString rts=new
> HSSFRichTextString(str);
>                         HSSFFont font=wb.createFont();
>                         
>                         font.setItalic(true);
>                         font.setUnderline((byte)1);
>                         font.setBoldweight((short)700);
> 
>                         rts.applyFont(0,5,font);
>                         
>                         font.setItalic(false);
>                         font.setUnderline((byte)0);
>                         font.setBoldweight((short)400);
> 
>                         rts.applyFont(6,11,font);
>                         
>                         font.setItalic(false);
>                         font.setUnderline((byte)0);
>                         font.setBoldweight((short)700);
>                         rts.applyFont(12,16,font);
>                         
>                         cell.setCellValue(rts);
>                         wb.write(fileOut);
>                         fileOut.close();
>              }catch(Exception e) {
>                   e.printStackTrace();
>              }
>                         
>       }
>       
> 
> But it seems it cannot be done, once the font is set it is set for
> everything.
> Can someone please tell me how to resolve this.
> Thank You
> -- 
> View this message in context:
> http://www.nabble.com/Set-character-formatting-in-Excel-using-POI-tf4262
> 750.html#a12131092
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> ============================================================
> The information contained in this message may be privileged
> and confidential and protected from disclosure. If the reader
> of this message is not the intended recipient, or an employee
> or agent responsible for delivering this message to the
> intended recipient, you are hereby notified that any reproduction,
> dissemination or distribution of this communication is strictly
> prohibited. If you have received this communication in error,
> please notify us immediately by replying to the message and
> deleting it from your computer. Thank you. Tellabs
> ============================================================
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Set-character-formatting-in-Excel-using-POI-tf4262750.html#a12131831
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to