Thanks Mark for trying this out. This looks like an bug with POI 3.1 which I am using.
Regards, Nilesh On Sun, Jan 23, 2011 at 7:22 PM, Mark Beardsley <[email protected]>wrote: > > This works perfectly well for me; > > File file = null; > FileOutputStream fos = null; > HSSFWorkbook workbook = null; > HSSFSheet sheet = null; > HSSFRow row = null; > HSSFCell cell = null; > HSSFCellStyle cellStyle = null; > HSSFFont font1 = null; > HSSFFont font2 = null; > HSSFRichTextString contents = null; > try { > workbook = new HSSFWorkbook(); > > // Set up the default cell style and it's associated font > cellStyle = workbook.createCellStyle(); > cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); > font1 = workbook.createFont(); > font1.setFontName(HSSFFont.FONT_ARIAL); > font1.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); > cellStyle.setFont(font1); > > // Now, set up the alternative font. This will mirror the > // font applied to the cell style but will have the underline > // attribute set. > font2 = workbook.createFont(); > font2.setFontName(HSSFFont.FONT_ARIAL); > font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); > font2.setUnderline(HSSFFont.U_SINGLE); > > // Create the workbooks sheet and a single cell at position A1. > sheet = workbook.createSheet("Font Test"); > row = sheet.createRow(0); > cell = row.createCell(0); > > // Set the cell style > cell.setCellStyle(cellStyle); > > // Now build the HSSFRichTextString object and set the font > // for just a few of it's characters > contents = new HSSFRichTextString("This is the sting to write into the > cell."); > contents.applyFont(5, 10, font2); > cell.setCellValue(contents); > > // Adjust the width of the column to ensure the cells contents are > // clearly displayed. > sheet.autoSizeColumn(0); > > // Finally, write the workbook away. > file = new File(filename); > fos = new FileOutputStream(file); > workbook.write(fos); > } > finally { > if(fos != null) { > try { > fos.flush(); > fos.close(); > fos = null; > } > catch(IOException ioEx) { > // I G N O R E > } > } > > I am using the latest version of POI. > > Yours > > Mark b > -- > View this message in context: > http://apache-poi.1045710.n5.nabble.com/Help-in-setting-underline-tp3352666p3353640.html > Sent from the POI - User mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
