2014-10-08 147 views
-1

我想为我的excel工作表单元格文本部分着色,所以我使用richtextstring为此,但它不工作......没有error.i无法找出什么是错的。 这是我的代码。RichtextString不工作在hssfworkbook单元格

在这个答案是字符串..我要的颜色字符串到最后(,)以红色和留在黑色

if (answer.contains(",")) { 

           String s = ","; 

           int second = answer.lastIndexOf(s); 


           HSSFCell cell7 = thisRow.createCell((short) i); 
           cell7.setCellStyle(style2); 
           HSSFRichTextString richTextString = new HSSFRichTextString(
             answer); 
           richTextString.applyFont(0, second, style5.getFontIndex()); 

           cell7.setCellValue("" + richTextString); 

When i try to use        cell7.setCellValue(richTextString); 
it says : 
The method setCellValue(String) in the type HSSFCell is not applicable for the arguments (HSSFRichTextString) 

回答

3

你用串联不慎转换RichTextStringString一个空字符串""。这有效地消除了所有格式。

请勿与""连接,因为直接存在重载的setCellValue method that takes a RichTextString

cell7.setValue(richTextString); 
+0

cell7.setValue(richTextString);没有采取richtextstring这就是为什么我已经连接“” – kirti 2014-10-09 04:09:27

相关问题