We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Applying Underline over a range


I have to apply Underline (typically Font Style) over a range [startRow, startCol, endRow, endCol]. Is there any way other than the cell by cell operations for which I can apply it over the range?

Attached is the current code that is being used for applying underline…
private void Underline(Aspose.Cells.Workbook workBook, int startRow, int startColumn, int endRow, int endColumn, string sheetName, FontUnderlineType underLine)


if (endRow < startRow || endColumn < startColumn)

if (string.IsNullOrEmpty(sheetName))
sheetName = workBook.Worksheets[workBook.Worksheets.ActiveSheetIndex].Name;

for (int rowIndex = startRow; rowIndex <= endRow; rowIndex++)
for (int colIndex = startColumn; colIndex <= endColumn; colIndex++)
Aspose.Cells.Style style = workBook.Worksheets[sheetName].Cells[rowIndex, colIndex].GetStyle();
style.Font.Underline = underLine;
workBook.Worksheets[sheetName].Cells[rowIndex, colIndex].SetStyle(style);

Thanks & Regards,.


Yes, you may create a range based on your desired cells area and specify the style for range. Lastly apply the style to the range, see the sample code below:

Workbook workbook = new Workbook();

//Define a style object adding a new style
//to the collection list.
Style stl5 = workbook.Styles[workbook.Styles.Add()];
//Set underline type.
stl5.Font.Underline = FontUnderlineType.Double;
StyleFlag flag = new StyleFlag();
flag.FontUnderline = true;

//Create a named range of cells (A1:B10)in the first worksheet.
//Range range = workbook.Worksheets[0].Cells.CreateRange(“A1:B10”);
//Range range = workbook.Worksheets[0].Cells.CreateRange(0,0,10,2);
Range range = workbook.Worksheets[0].Cells.CreateRange(“A1”, “B10”);
//Apply the style to cells in the named range.
range.ApplyStyle(stl5, flag);


Also, check the document for reference:

Thank you.