Skip to main content Skip to footer

Space Char in Spread for ASP.NET

The space char is reserved in HTML, if page content has more than two space chars between two words, HTML only shows one space. It is same in the cell of Spread for ASP.NET in default, because Spread for ASP.NET uses HTML to render in client side browser. Sometime we really need to keep space chars to show in the cell, how to do it? As we know, in HTML we can use entity " " to instead of the space char, if we want to show two spaces between "A" and "B", we can do like this: "A  B". Is it possible Spread for ASP.NET cell renders the HTML tag? Answer is yes, Spread for ASP.NET cell has a property "EncodeValue", if set it to false, Spread for ASP.NET will render cell value as HTML tag. Code is like this:

FpSpread1.Sheets[0].RowCount = 4;  
FpSpread1.Sheets[0].Cells[1, 1].EncodeValue = false;  
FpSpread1.Sheets[0].Cells[1, 1].Value = "Hello<B>World</B>";   
FpSpread1.Sheets[0].Rows[2].EncodeValue = false;   
FpSpread1.Sheets[0].Cells[2, 1].Value = "<a href='http://gcpowertools.com'>gcpowertools.com</a>";   
FpSpread1.Sheets[0].Columns[2].EncodeValue = false;   
FpSpread1.Sheets[0].Cells[3, 2].Value = "Break&nbsp;here<BR>to&nbsp;anew&nbsp;line";

There are more information in the doc about EncodeValue property Sometime we can't set HTML tag to cell value, for example maybe the data is from database, or it is inputted by end-user, there is another way can make it. CSS3 has a "white-space" property, if set it to "pre-wrap", the browser will preserved the space chars. And Spread for ASP.NET uses Table to layout and render cells, so we only need to do is set "white-space" to "pre-wrap" for the Table element in the page header, then space chars will be preserved in cells, code like this:

        table {  
            white-space: pre-wrap;  
        }

Go to Spread for ASP.NET web page to get more information about the product.

MESCIUS inc.

comments powered by Disqus