Thursday, April 12, 2012

how to format an excel cell in asp.net

Is there any properties to make changes dynamically to the cells of excel sheet in asp.net?i would say we can do dynamically any changes.The creation of an excel sheet in asp.net is pretty simple.Here i have used Microsoft Interop dll to create excel.if we want change the width ,text align,color etc of cell ,The below example will show how simple it is.
//column width
 ((Excel.Range)xlWorkSheet.Cells[2, 3]).EntireColumn.ColumnWidth = 45;
//Align center for text
 xlWorkSheet.get_Range("c11", dstrowcount).Columns.HorizontalAlignment = 3;
//merging cells
 xlWorkSheet.get_Range("e2", "j2").Cells.Merge();
//color chage for selected text
 Excel.Range range = xlWorkSheet.get_Range("d5");
 range.get_Characters(1, 5).Font.ColorIndex = 14;
//border color & lines settings
xlWorkSheet.get_Range("c11", dstrowcount).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
xlWorkSheet.get_Range("c11", dstrowcount).Borders.ColorIndex = 15;
//font setting
((Excel.Range)xlWorkSheet.Cells[8, 4]).Cells.Font.Bold = true;

No comments:

Bel