Question : How to Add formatting to Excel Spreadsheet from VB.NET

Hi

I have a VB.NET application that creates an Excel file in code, creates a dataset from a SQL server database and populates the new spreadsheet with the the data

I need to Format the  title of the new spreadsheet and create gridlines around the data I have added.

I will know the cell coordinates of the data range and the title

Can somebody help with the synatax from VB.Net to format the cells/ranges for:

Bold text
Centre accross selection
Top, bottom, left, right border (with weight)

Thanks for your help



Answer : How to Add formatting to Excel Spreadsheet from VB.NET

Hello, DavidHannen,

The attached snippet shows some examples that may help.

You can often find clues to the properties and methods that you need by performing the steps manually in Excel while recording a macro.  The resulting macro is rarely of any direct use, but provides clues about the properties and methods that can be used.

Cheers,
Randy
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
        Dim ApExcel As New Excel.Application
        ApExcel.Visible = True ' So you can see Excel
        Dim ExcelWorkbook As Excel.Workbook = CType(ApExcel.Workbooks.Add, Excel.Workbook)
        Dim ExcelSheet1 As Excel.Worksheet = CType(ExcelWorkbook.Sheets(1), Excel.Worksheet)

        ExcelSheet1.Range("A1:BZ3").Font.Size = "12"
        ExcelSheet1.Range("A1:BZ3").Font.Bold = True
        ExcelSheet1.Range("B8:E12").BorderAround(, Excel.XlBorderWeight.xlMedium)
        ExcelSheet1.Range("C5:F5").HorizontalAlignment = 3 'center
        ExcelSheet1.Range("C5:F5").Merge()
Random Solutions  
 
programming4us programming4us