Shaitan00 Posted October 2, 2005 Posted October 2, 2005 Given an Excel File [Tasks.xls] that I create (as a kind of template) which has a Header row [row1, the first row in the Excel File] So obviously I want to make that rows font BOLD, problem is when I use my current code (as shown below) it seems to make the entire range BOLD so the actual rows of information I add afterwards [row2+] are all BOLD also - not just the header row as I wanted. oSheet.get_Range("A1", "G1").Font.Bold = true; [/Code] Is there a way maybe to set the Font cell by cell? [very easy to just manually set cells [1, 1-6] bold, I just don't want every subsequent row to also be bold. Is there a way to set it only for row1? (cell by cell basis? row by row basis? of setting Font.Bold = true?) Thanks, Quote
*Experts* DiverDan Posted October 2, 2005 *Experts* Posted October 2, 2005 There a a few different ways to accomplish this. assuming o.Sheet is the Excel.Worksheet reference. 1. using the Range properity - oSheet.Range("A1:G1").Font.Bold = True 2. using a cell by cell loop For i = 1 to 6 oSheet.Cells(1, i).Font.Bold = True End For 3. specific cell referencing oSheet.Cells(1, 1).Font.Bold = True I hope this gives you an idea how to solve your task. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Shaitan00 Posted October 30, 2005 Author Posted October 30, 2005 This is how I generate my oSheet Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Sheets["Sheet1"]; [/Code] Sadly none of your 3 suggestions seem to work... 1. There is no oSheet.Range property (doesn't exist) 2/3. There is no .Cells().Font property (doesn't exist) AND it is .Cells[] not .Cells() Any clues as to why? What I am doing wrong? Other ideas? I find it really hard to beleive that there is no way to BOLD only certain rows or cells ... Thanks, Quote
*Experts* DiverDan Posted October 30, 2005 *Experts* Posted October 30, 2005 Here's a suggestion for establishing an Excel worksheet. Dim excelApp As New Excel.Application If excelApp Is Nothing Then MessageBox.Show("Excel Installation Error", "Microsoft Excel must be installed on this computer for this feature to operate.") End If Cursor.Current = Cursors.AppStarting Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet) Dim row as Integer = 1 With excelWorksheet .Cells(row, 1).Value = "Add Something Here" .Cells(row, 1).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft .Cells(row, 1).Font.Bold = True End With 'OR With excelWorksheet .Cells(row, 1).Value = "Add Something Here" .Cells(row, 1).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft .Range(row & "1:L1").Font.Bold = True 'you can write a function here to convert a numeric column number to a letter End With excelWorksheet.Columns.AutoFit() Cursor.Current = Cursors.Default excelApp.Visible = True I hope this helps. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts