Friday, 31 August 2012

VB.NET - Excel - How to modify cell/row height

also check http://howtodomssqlcsharpexcelaccess.blogspot.ca/2012/08/vbnet-how-to-creae-excel-file-simple.html   

    Dim fileTest As String = "C:\Temp\ExcelTest\test.xlsx"
        If File.Exists(fileTest) Then
            File.Delete(fileTest)
        End If

        Dim oExcel As Object
        oExcel = CreateObject("Excel.Application")
        Dim oBook As Excel.Workbook
        Dim oSheet As Excel.Worksheet

        oBook = oExcel.Workbooks.Add
        oSheet = oExcel.Worksheets(1)

        oSheet.Name = "no name"
        oSheet.Range("A1").Value = "FirstName"
        oSheet.Range("B1").Value = "Year"
        oSheet.Range("C1").Value = "Salary"

        oSheet.Range("A2").Value = "Frank"
        oSheet.Range("B2").Value = "2012"
        oSheet.Range("C2").Value = "20000"

        oSheet.Range("A3").Value = "John"
        oSheet.Range("B3").Value = "2012"
        oSheet.Range("C3").Value = "30000"

        oSheet.Range("A4").Value = "Bob"
        oSheet.Range("B4").Value = "2012"
        oSheet.Range("C4").Value = "40000"

        oSheet.Range("A5").Value = "Elvis"
        oSheet.Range("B5").Value = "2012"
        oSheet.Range("C5").Value = "60000"

        osheet.Range("A1").RowHeight = 100
        osheet.Range("A1").EntireRow.WrapText = True
        osheet.Range("A1").EntireRow.AutoFit()


        oBook.SaveAs(fileTest)
        oBook.Close()
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing

YouTube - Create simple Excel file with VB.NET

No comments:

Post a Comment