How to Set the column of excel as bold while importing from datatable
-
I am exporting a datatable to EXCEL . i want to set the font of excel columns as bold and some colour. i was using something like Excel.Application Obj_Excel_App = new Excel.ApplicationClass(); Excel.Workbook Obj_Excel_ExcelWork = Obj_Excel_App.Workbooks.Add(Type.Missing); Excel.Range obj_Range; obj_Range = Obj_Excel_App.get_Range("A1", "E1"); obj_Range.Font.Bold = true; but here i have to hardcode the range , i dont want to do that.plz help
-
I am exporting a datatable to EXCEL . i want to set the font of excel columns as bold and some colour. i was using something like Excel.Application Obj_Excel_App = new Excel.ApplicationClass(); Excel.Workbook Obj_Excel_ExcelWork = Obj_Excel_App.Workbooks.Add(Type.Missing); Excel.Range obj_Range; obj_Range = Obj_Excel_App.get_Range("A1", "E1"); obj_Range.Font.Bold = true; but here i have to hardcode the range , i dont want to do that.plz help
-
I am exporting a datatable to EXCEL . i want to set the font of excel columns as bold and some colour. i was using something like Excel.Application Obj_Excel_App = new Excel.ApplicationClass(); Excel.Workbook Obj_Excel_ExcelWork = Obj_Excel_App.Workbooks.Add(Type.Missing); Excel.Range obj_Range; obj_Range = Obj_Excel_App.get_Range("A1", "E1"); obj_Range.Font.Bold = true; but here i have to hardcode the range , i dont want to do that.plz help
You can refer to a specific column, or set of columns, using the Columns collection and set its properties
========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================
-
You can refer to a specific column, or set of columns, using the Columns collection and set its properties
========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================
Actually i want to get the range of excel and set it colour and font currently i am doing like this Microsoft.Office.Interop.Excel.Range last = excelApp.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing); Microsoft.Office.Interop.Excel.Range range = excelApp.get_Range("A1", last); range.Font.Bold = true; range.Font.Size = 12; range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White); range.Cells.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue); but it actually set the colour of all the rows , i just want to do it for first row which is my column header
-
Actually i want to get the range of excel and set it colour and font currently i am doing like this Microsoft.Office.Interop.Excel.Range last = excelApp.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing); Microsoft.Office.Interop.Excel.Range range = excelApp.get_Range("A1", last); range.Font.Bold = true; range.Font.Size = 12; range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White); range.Cells.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue); but it actually set the colour of all the rows , i just want to do it for first row which is my column header
Your original post said that you wanted to set the attributes of a column, not the row headers. To find the last used cell in a row, I have used this code (VBA, but you should be able to work out what it is doing.
Dim WS As Worksheet
Dim LastCell As Range
Dim LastCellRowNumber As LongSet WS = Worksheets("Sheet1")
With WS
Set LastCell = .Cells(.Rows.Count, "C").End(xlUp)
LastCellRowNumber = LastCell.Row
End With========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================