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.
Unfortunately, activation email could not send to your email. Please try again.

Text length

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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.

Johnie




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

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
sheet.UsedRange["C10:E10"].Merge(false);

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

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




Merging_Cells_41069c9b.zip

Johnie Gilliland
Replied On January 24, 2012 09:14 AM

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 01:47 AM

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:

[C#]
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


Regards,
Manojkumar.






Merging_Cells_63b00029.zip

CONFIRMATION

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.

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.

;