2014-10-08 143 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

相關問題