Skip to content

Adding multi-style text in a XLS Cell using POI

December 13, 2011

HSSFCell firstRowCell0=firstRow.createCell(0);

 

String welcomeMessage = “Welcome to JASOKAN.WORDPRESS.COM”;
int wcMessageLength = welcomeMessage.length();
HSSFRichTextString richTextSample= new HSSFRichTextString(welcomeMessage);
HSSFFont underlinedFont = testWorkBook.createFont();
underlinedFont.setFontHeightInPoints((short) 10);
underlinedFont.setFontName(“MS Mincho”);
underlinedFont.setUnderline(HSSFFont.U_SINGLE);
richTextSample.applyFont(11,wcMessageLength,underlinedFont);
firstRowCell0.setCellValue(richTextSample);

The HSSFRichTextString makes the magic of underlining the content. So, this can be replicated to other formats <b>, <i> etc.,

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: