We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Text length

Thread ID:





102326 Jan 19,2012 08:10 PM UTC Jan 31,2012 06:47 AM UTC ASP.NET Web Forms (Classic) 3
Tags: XlsIO
Johnie Gilliland
Asked On January 19, 2012 08:10 PM UTC

I am creating an excel sheet based on data in our app. I need to add text, style that text, and then merge with other cells. How do I figure out how many cells that text will cover?

For example, if I added "this is a demo" to a cell in code and open the excel sheet that text would overlap 2 other cells, so I would need to merge 3 cells total.


Johnson Monohar M [Syncfusion]
Replied On January 20, 2012 09:44 AM UTC

Hi Johnie,
Thank you for using Syncfusion products.
XlsIO supports to format the texts and merging the cells. You can achieve the cell merging from the following code snippet.
//Creating a range
IRange range = sheet.Range["C10"];

range.Text = "Sample of merging cells";
range.CellStyle.Color = Color.Blue;
range.CellStyle.Font.Color = ExcelKnownColors.Yellow;
range.CellStyle.Font.Bold = true;

//Merging the cells

Also, we have provided a sample that illustrates the text formatting and cells merging in the following link.

Please let us know if the provided solution resolved you issue or you need any clarification.


Johnie Gilliland
Replied On January 24, 2012 02:14 PM UTC

I get how to merge cells. What I am looking for is a way to figure out how many cells any given text takes up.

Manoj Kumar G M [Syncfusion]
Replied On January 31, 2012 06:47 AM UTC

Hi Johnie,

Thank you very much for your patience.

You can calculate number of cells that given string takes up by using “MeasureStringSpecial” method in FontImpl class.

Following code snippet illustrates this:

FontImpl impl = new FontImpl(range.CellStyle.Font);

SizeF obj = impl.MeasureStringSpecial(range.Text);

double numberOfCells = Math.Ceiling((obj.Width) / value);

Please try the below sample and let us know if this helps you.

Please let us know if you need any clarifications




This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon