Get the App
SLTechnology News&Howtos  ›  Development  › 

How VB.NET operates Excel

Shulou Source: shulou.com Published: 2022-06-02 08:51:35 10月02日 Update

This article mainly shows you "VB.NET how to operate Excel", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.NET how to operate Excel" this article.

VB.NET operation Excel code

Public Sub Printer () Sub Printer

(ByVal pid As Int16, ByVal dbhlp

As DBHelper, ByVal objds As ploy)

Dim sqlstr As String

Sqlstr = "select * from Ploy"

Where ployID= "& pid

Dbhlp.FillDataTable (sqlstr

Objds, "Ploy")

Sqlstr = "select * from PForeign"

Where ployID= "& pid

Dbhlp.FillDataTable (sqlstr

Objds, "PForeign")

Dim exl As New Excel.Application

Exl.Visible = True

Exl.DisplayAlerts = True

Exl.WindowState = Excel.XlWindow

State.xlMaximized

'Dim wb As Excel.Workbook =

Exl.Workbooks.Open (Application.

StartupPath & "\ print.xls")

'Dim ws As Excel.Worksheet =

Wb.Worksheets ("prt")

Dim wb As Excel.Workbook =

Exl.Workbooks.Add ()

Dim ws As Excel.Worksheet =

Wb.Worksheets.Item (1)

Dim Rng As Excel.Range

Rng = ws.Columns (1)

Rng.ColumnWidth = 16

Rng = ws.Columns (2)

Rng.ColumnWidth = 46

Rng = ws.Columns (3)

Rng.ColumnWidth = 16

Dim dr As ploy.PloyRow

Dr = objds.Ploy.Rows (0)

Try

Rng = ws.Range ("A1:A1", "C1:C1")

Rng.Cells.Merge () 'merge cells

Rng.Font.Name = "boldface"

Rng.Font.Size = "22"

Rng.HorizontalAlignment =-4108

Rng.VerticalAlignment =-4108

Rng.Value = dr.PSubject

Catch ex As Exception

End Try

Try Rng = ws.Range ("A2:A2", "C2:C2") Rng.Cells.Merge () Rng.Font.Name = "boldface" Rng.Font.Size = "14" Rng.HorizontalAlignment =-4108 Rng.VerticalAlignment =-4108 Rng.Value = "time:" & dr.PTime Catch ex As Exception End TryTry Rng = ws.Range ("A3:A3" "C3:C3") Rng.Cells.Merge () Rng.Font.Name = "boldface" Rng.Font.Size = "14" Rng.HorizontalAlignment =-4108 Rng.VerticalAlignment =-4108 Rng.Value = "location:" & dr.Place Catch ex As Exception End Try

Dim drF As ploy.PForeignRow

Dim i, rngi As Integer

Dim rngs, cellB, cellE As String

Rngi = 5 + objds.PForeign.Rows.Count

CellB = "A5:A5"

CellE = "C" & rngi.ToString &

": C" & rngi.ToString

Rng = ws.Range (cellB, cellE)

Rng.Font.Name = "imitating Song _ GB2312"

Rng.Font.Size = "16"

Rng.Borders.LineStyle = 1

Rng.HorizontalAlignment =-4108

Rng.VerticalAlignment =-4108

Rng = ws.Range ("A5")

Rng.Value = "Consulate"

Rng = ws.Range ("B5")

Rng.Value = "attendees"

Rng = ws.Range ("C5")

Rng.Value = "title"

Rngi = 6

For I = 0 To objds.PForeign.

Rows.Count-1

DrF = objds.PForeign.Rows (I)

Rng = ws.Range ("A" & rngi.ToString)

Rng.Value = drF.PConsulate

Rng = ws.Range ("B" & rngi.ToString)

Rng.Value = drF.PName

Rng = ws.Range ("C" & rngi.ToString)

Rng.Value = drF.PRank

Rngirngi = rngi + 1

Next

'wb.Save ()

'If Not exl Is Nothing Then

'exl.Workbooks.Close ()

'exl.Quit ()

'System.Runtime.InteropServices.

Marshal.ReleaseComObject (exl)

'End If

'If Not ws Is Nothing Then

'System.Runtime.InteropServices.

Marshal.ReleaseComObject (ws)

'End If

'ws = Nothing

'exl = Nothing

'GC.Collect ()

End Sub

End Class

The above is all the contents of the article "how VB.NET operates Excel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Content article boldface learning help personnel code unit place time easy to understand more organization knowledge ribbon job title industry information information channel consulate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology Xiaomi Shulou Tech Info Huawei