用VS2015,创建的VB.NET应用程序,如何同时操作两个EXCEL工作簿
用VS2015,创建的VB.NET应用程序,如何同时操作两个EXCEL工作簿,如何在第二个工作簿中创建新的sheet并重命名?程序如下:在SUBAI()中:FileNam...
用VS2015,创建的VB.NET应用程序,如何同时操作两个EXCEL工作簿,如何在第二个工作簿中创建新的sheet并重命名?
程序如下:在SUB AI()中 :FileName2文件中新建一个sheet表,并命名为工作表1.
求各位大神帮忙写一下,非常感谢。
Public Class Form1
Dim AppXls = New Microsoft.Office.Interop.Excel.Application '实例化Excel对象
Dim AppWokBook As Microsoft.Office.Interop.Excel.Workbook
Dim AppSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim AIChannelNum, AOChannelNum, DIChannelNum, DOChannelNum, AIModleNum, AOModleNum, DIModleNum, DOModleNum, InM_N As UInt32
Dim FileName1, FileName2 As String
Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("数据库路径不能为空", "警告")
Exit Sub
End If
Dim ProDocumentNum, ProNum, ProUnit, ProName, ProDesingName, ProEnduserName, ProLoction, ProRev, ProDate, ProPrep, ProChk, ProApr, ProDescription As String
Dim NowTime As String
Dim n1 As UInt32
FileName1 = My.Computer.FileSystem.GetParentPath(TextBox1.Text)
NowTime = Format(Now, "yyyy-MM-dd hhmmss")
FileName2 = FileName1 & "\" & "IO接线表 A版 " & NowTime & ".xlsx"
My.Computer.FileSystem.CopyFile(FileName1 & "\" & "工作表模板" & "\" & "接线表.xlsx", FileName2) '文件不能复制到C盘根目录
AppWokBook = AppXls.Workbooks.Open(TextBox1.Text) '打开加载的EXCEL文件
AppXls.Visible = False '使Excel不可见
AppWokBook = AppXls.Workbooks.Open(FileName2)
AppXls.Visible = False
With AppXls.Workbooks(1).Sheets("Coversheet")
ProDocumentNum = .Cells(1, 9).Value
ProDescription = .Cells(24, 10).Value
End With
With AppXls.Workbooks(2).Sheets("首页")
.Cells(1, 7).Value = ProDocumentNum
End With
Call AI()
end sub
Private Sub AI()
'在FileName2文件中新建一个sheet表,并命名为工作表1.
end sub
end class 展开
程序如下:在SUB AI()中 :FileName2文件中新建一个sheet表,并命名为工作表1.
求各位大神帮忙写一下,非常感谢。
Public Class Form1
Dim AppXls = New Microsoft.Office.Interop.Excel.Application '实例化Excel对象
Dim AppWokBook As Microsoft.Office.Interop.Excel.Workbook
Dim AppSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim AIChannelNum, AOChannelNum, DIChannelNum, DOChannelNum, AIModleNum, AOModleNum, DIModleNum, DOModleNum, InM_N As UInt32
Dim FileName1, FileName2 As String
Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("数据库路径不能为空", "警告")
Exit Sub
End If
Dim ProDocumentNum, ProNum, ProUnit, ProName, ProDesingName, ProEnduserName, ProLoction, ProRev, ProDate, ProPrep, ProChk, ProApr, ProDescription As String
Dim NowTime As String
Dim n1 As UInt32
FileName1 = My.Computer.FileSystem.GetParentPath(TextBox1.Text)
NowTime = Format(Now, "yyyy-MM-dd hhmmss")
FileName2 = FileName1 & "\" & "IO接线表 A版 " & NowTime & ".xlsx"
My.Computer.FileSystem.CopyFile(FileName1 & "\" & "工作表模板" & "\" & "接线表.xlsx", FileName2) '文件不能复制到C盘根目录
AppWokBook = AppXls.Workbooks.Open(TextBox1.Text) '打开加载的EXCEL文件
AppXls.Visible = False '使Excel不可见
AppWokBook = AppXls.Workbooks.Open(FileName2)
AppXls.Visible = False
With AppXls.Workbooks(1).Sheets("Coversheet")
ProDocumentNum = .Cells(1, 9).Value
ProDescription = .Cells(24, 10).Value
End With
With AppXls.Workbooks(2).Sheets("首页")
.Cells(1, 7).Value = ProDocumentNum
End With
Call AI()
end sub
Private Sub AI()
'在FileName2文件中新建一个sheet表,并命名为工作表1.
end sub
end class 展开
展开全部
首先定义
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook Public xlSheet As Excel.Worksheet然后创建对象
xlApp = CreateObject("Excel.Application") '创建EXCEL对象
xlBook = xlApp.Workbooks.Open("文件路径") '打开已经存在的EXCEL工件簿文件
xlSheet = xlBook.Worksheets("sheet1")
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook Public xlSheet As Excel.Worksheet然后创建对象
xlApp = CreateObject("Excel.Application") '创建EXCEL对象
xlBook = xlApp.Workbooks.Open("文件路径") '打开已经存在的EXCEL工件簿文件
xlSheet = xlBook.Worksheets("sheet1")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询