Create a Spreadsheet : Excel « Windows « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows » Excel 
24.21.2.Create a Spreadsheet
public class Test
   public Shared Sub Main
        Dim objExcel As Excel.Application
        objExcel = New Excel.Application

    
        Dim objSheet As New Excel.Worksheet
        Dim objRange As Excel.Range
        Dim intRow, intCol As Integer

        objExcel.Visible = True

        'Add a worksheet and then add some content to it.
        objSheet = objExcel.Workbooks.Add.Worksheets.Add
        With objSheet
            .Cells(21).Value = "1st Quarter"
            .Cells(22).Value = "2nd Quarter"
            .Cells(23).Value = "3rd Quarter"
            .Cells(24).Value = "4th Quarter"
            .Cells(25).Value = "Year Total"
            .Cells(31).Value = 123.45
            .Cells(32).Value = 435.56
            .Cells(33).Value = 376.25
            .Cells(34).Value = 425.75
            .Range("A2:E2").Select()
            With objExcel.Selection.Font
                .Name = "Verdana"
                .FontStyle = "Bold"
                .Size = 12
            End With
        End With

        'Set the alignment.
        objSheet.Range("A2:E2").Select()
        objExcel.Selection.Columns.AutoFit()
        objSheet.Range("A2:E2").Select()
        With objExcel.Selection
            .HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
        End With

        'Format some numbers.
        objSheet.Range("A3:E3").Select()
        With objExcel.Selection.Font
            .Name = "Verdana"
            .FontStyle = "Regular"
            .Size = 11
        End With

        'Display summary information.
        objSheet.Cells(35).Value = "=Sum(A3:D3)"
        objRange = objSheet.UsedRange
        For intCol = To objRange.Columns.Count
            For intRow = To objRange.Rows.Count
                Console.WriteLine(objRange.Cells(intRow, intCol).value)
            Next
        Next

        objExcel.Workbooks.Close()
        objExcel.Quit()
        objExcel = Nothing
   End Sub
End class
24.21.Excel
24.21.1.Create function in Excel
24.21.2.Create a Spreadsheet
24.21.3.Import data
24.21.4.Sort imported data
24.21.5.Calculate Expression
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.