這篇文章主要為大家展示了“VB.NET如何操作Excel”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“VB.NET如何操作Excel”這篇文章吧。
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比寧陜網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式寧陜網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋寧陜地區(qū)。費(fèi)用合理售后完善,10年實(shí)體公司更值得信賴。
VB.NET操作Excel代碼
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()'合并單元格
Rng.Font.Name = "黑體"
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 = "黑體" Rng.Font.Size = "14" Rng.HorizontalAlignment = -4108 Rng.VerticalAlignment = -4108 Rng.Value = "時(shí)間:" & dr.PTime Catch ex As Exception End Try
Try Rng = ws.Range("A3:A3", "C3:C3") Rng.Cells.Merge() Rng.Font.Name = "黑體" Rng.Font.Size = "14" Rng.HorizontalAlignment = -4108 Rng.VerticalAlignment = -4108 Rng.Value = "地點(diǎn):" & 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.ToStringRng = ws.Range(cellB, cellE)
Rng.Font.Name = "仿宋_GB2312"
Rng.Font.Size = "16"
Rng.Borders.LineStyle = 1
Rng.HorizontalAlignment = -4108
Rng.VerticalAlignment = -4108
Rng = ws.Range("A5")
Rng.Value = "領(lǐng)館"
Rng = ws.Range("B5")
Rng.Value = "出席人員"
Rng = ws.Range("C5")
Rng.Value = "職銜"
rngi = 6
For i = 0 To objds.PForeign.
Rows.Count - 1drF = 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
以上是“VB.NET如何操作Excel”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!