We are using Aspose Cells.Net.
Hi,
I like the example given by Amjad, here is another approach.
I have used System.Windows.Forms.TextRenderer class to measure the text size in pixels. Given the font name and font size, TextRenderer.MeasureText method will return the size of the string in unit of pixels.
We will then compare both cell’s column width and cell’s string width and decide if the cell is overflowing or not.
Please see the code below.
C#
string filePath = @“C:\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet.Cells[“A1”];
Style style = cell.GetStyle();
Size sz = TextRenderer.MeasureText(cell.StringValue, new System.Drawing.Font(style.Font.Name, style.Font.Size));
int ADJUSTMENT=3; //fine tune it
if (sz.Width + ADJUSTMENT > worksheet.Cells.GetColumnWidthPixel(cell.Column))
{
//Text Over Flows the width of the cell’s column
}
Thanks Shakeel. I will definitely look into this.
Amjad, Although we have not tested it, your solution is fantastic.