3

I want to bold particular word of a particular cell. I have successfully exported the the excel sheet from VF page and applied styles on individual cells. Now I want to bold a specific word from controller.

<Cell ss:StyleID="someStyleId">
     <Data ss:Type="String">
          <apex:outputText value="In this statement i want **california** to be bold." escape="false"   />  
     </Data>
</Cell>

Output

In this statement i want california to be bold. There can be more data but i want only few words to be bold.

7
  • Yeah.. i want just a part of a cell to be bold. As given in example code @adrian Commented Jan 17, 2017 at 12:16
  • Can you at least clarify rules around what should be bold? Always the word california? State names? The sixth word? Words with ten characters?
    – Adrian Larson
    Commented Jan 17, 2017 at 12:18
  • no. i want to bold a particular word irrespective of its position and length. Commented Jan 17, 2017 at 12:22
  • To be more specific , In a cell I have first line as project title and then in second line I have details about that project. I want only project title(first line) to be bold in that cell. Commented Jan 17, 2017 at 12:24
  • I am stuck in this since last 2 days. Any help would be greatfull. Commented Jan 17, 2017 at 12:53

2 Answers 2

4

An excel cell row which have partial worlds in bold should look like this:

    <Cell>
       <Data ss:Type="String">
         <Font html:Color="#000000" xmlns="http://www.w3.org/TR/REC-html40">ABC</Font>
         <B xmlns="http://www.w3.org/TR/REC-html40">
          <Font html:Color="#000000">**This is bold**</Font>
         </B>
         <Font html:Color="#000000" xmlns="http://www.w3.org/TR/REC-html40">RTT</Font>
       </Data>
    </Cell>

Look at the styles applied for "This is bold" string.

So, simply pass on the html in <Data/> tag into the <outputText/>. It will work.

1
-1

<apex:outputText> tag have a attribute called escape takes boolean value which you have already used without knowing its use.

A Boolean value that specifies whether sensitive HTML and XML characters should be escaped in the HTML output generated by this component. If you don’t specify escape="false", the character escape sequence displays as written. Be aware that setting this value to "false" may be a security risk because it allows arbitrary content, including JavaScript, that could be used in a malicious manner.

So you have to provide the html tags for bold inside the body of the outputText tag with escape="false" and it will display it for you.

<apex:outputText value="In this statement i want <br>california</br> to be bold." escape="false"   />

Hope it helps.

4
  • Does this work in Excel?
    – javanoob
    Commented Jan 17, 2017 at 14:09
  • Well i have tried using the below statement but bold text was not reflecting in excel sheet generated. **<apex:outputText value="In this statement i want <b>california</b> to be bold." escape="false" /> ** Do i have to use <br> for bold? Commented Jan 17, 2017 at 15:49
  • @max, <br> is for line break right? I am also trying from last 2 hrs but could not get it working. I will post if I get some solution. Thanks!
    – javanoob
    Commented Jan 17, 2017 at 15:59
  • yeah <br> is for line break. Commented Jan 17, 2017 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .