Essential XlsIO ASP.NET
Text length
January 31, 2012 01:47 AM by Manoj Kumar G M[Syncfusion]
Johnie Gilliland
Text length
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]
Text length
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
Text length
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]
Text length
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
::adCenter::