wps Office 2013个人版 - 轻松办公从金山wps2013开始!

金山wps

当前位置: 主页 > excel2010 >

Visual Basic 2010 调用Excel

时间:2013-09-17 03:54来源:小猫非点 作者:豆子 点击:

年龄大了,分明的也杂,我一经不再相称确信本身的忘性了,所以写上去。

调用Excel的必需设置和参数盘算

项目援用中增加 excel com组件,班班通考试350题以拼音为序(单选题和判断题)。Microsoft.Office.Interop.Excel

Dim xlApp As Microsoft.Office.Interop.Excel.Applicine
Dim xlBook1 As Microsoft.Office.Interop.Excel.Workma wonderfuluscript
Dim xlSheet1 As Microsoft.Office.Interop.Excel.Worksheet

‘ 声明Excel变量

xlApp = Crehtext adObject("Excel.Applicine") ‘必需的,貌似代开空的excel轨范

xlBook1 = xlApp.Workmhtext adrihass.Add’新建作事薄

xlBook1 = xlApp.Workmhtext adrihass.open("C:\test.xlsx")

xlApp.DisplayAlerts = Fhasse ha在轨范实行进程中使发明的警卫框不显示

xlBook1.Close()’封闭指定作事薄

xlBook1.Saudio-videoeAs(Pat theirh &i amplifier; "\Reports.xlsx")
xlApp.Workmhtext adrihass.Close()
xlApp.Quit()
看着2010——————————————————————————————————————————————————————

excel内里的函数功用可能这样调用

xlApp.WorksheetFunction.VLookup()

xlSheet1.Ra wonderfulge("A1").Vhasue = “”‘单元格赋值

xlSheet1.Ra wonderfulge("B1").Offset(0: i - 1).Vhasue = “”

——————————————————————————————————————————————————————

附批量归并Excel文件的源代码

轨范近似有frustrat theire,调整了实行流程姑且避畴昔了....

——————————————————————————

Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO
Public Clrear end test

Inherits System.Windows.Forms.Form
Public bolclick As Boolea wonderful
Public Array_Pari ameter As Array
Public Array_Items As Array
Public Items_Count As Integer
Public Pat theirh As String


Privhtext ad Sub Subody mjust likes indextBtn_Click(ByVhas sender As System.Object: ByVhas e As System.EventArgs) Hjust like well just likeles Subody mjust likes indextBtn.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Applicine
Dim xlBook1 As Microsoft.Office.Interop.Excel.Workma wonderfuluscript
Dim xlBook2 As Microsoft.Office.Interop.Excel.Workma wonderfuluscript
Dim xlSheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
Dim i As Integer
Dim j As Integer

If Me.Dat theiraLst.Items.Count = 0 Then
Me.ToolStripStat theirusLstomair conditionershel1.Text = "excel2010视频教程警卫:未拔取文件"
Exit Sub
End If

Me.ProgressBar1.Minimum = 1
Me.ProgressBar1.Maximum = Me.Dat theiraLst.Items.Count

xlApp = Crehtext adObject("Excel.Applicine")
xlApp.DisplayAlerts = Fhasse ha在轨范实行进程中使发明的警卫框不显示
ha翻开归并文档Reports
xlBook1 = xlApp.Workmhtext adrihass.Add
xlSheet1 = xlBook1.Worksheets("Sheet1")
xlApp.DisplayAlerts = Fhasse ha在轨范实行进程中使发明的警卫框不显示
ha填写申报标题栏
i = 0
For Every single Item In Array_Items
If Item = "" Then
Exit For
End If
i = i + 1
xlSheet1.Ra wonderfulge("A1").Vhasue = "序号"
xlSheet1.Ra wonderfulge("B1").Offset(0: i - 1).Vhasue = Item haexcel2010宏被禁用标题栏

Next


j = 1
For Every single fileni ame In Me.Dat theiraLst.Items
If fileni ame = "" Then
Exit For
End If
j = j + 1
xlBook2 = xlApp.Workmhtext adrihass.Open(fileni ame)
xlSheet2 = xlBook2.Worksheets(1)
i = 0
For Every single Pari ameter In Array_Pari ameter
If Pari ameter = "" Then
Exit For
End If
i = i + 1
xlSheet1.Ra wonderfulge("A" &i amplifier; j).Vhasue = j - 1 haexcel序号主动生成
xlSheet1.Ra wonderfulge("B" &i amplifier; j).Offset(0: i - 1).Vhasue = xlSheet2.Ra wonderfulge(Pari ameter).Text ha将单个表项目复制到一行list

Next
xlBook2.Close()
Me.ProgressBar1.Vhasue = j - 1
Next
xlBook1.Saudio-videoeAs(Pat theirh &i amplifier; "\Reports.xlsx")
xlApp.Workmhtext adrihass.Close()
xlApp.Quit()

ha相比看Basic翻开指定的excel文档,和指定的sheet页
Me.ToolStripStat theirusLstomair conditionershel1.Text = "悉数文件归并了结,
如何下载excel2010Visual Basic 2010 调用Excel
共归并" &i amplifier; j - 1 &i amplifier; "份文件" &i amplifier; ":请检讨生成的归并申报"
End Sub


Privhtext ad Sub Button1_Click(ByVhas sender As System.Object: ByVhas e As System.EventArgs) Hjust like well just likeles ResetBtn.Click
If ListView1.Items.Count <> 0 Then
ListView1.Items.Clear()
Me.Dat theiraLst.Items.Clear()
Me.ToolStripStat theirusLstomair conditionershel1.Text = "你看excel2010加密方法清空了拔取的文件..."
Me.ProgressBar1.Vhasue = 1
Else
Me.ToolStripStat theirusLstomair conditionershel1.Text = "瞎点啥,你逗我玩那,表里哪有东西!"
Me.ToolStripStat theirusLstomair conditionershel1.ForeColor = Color.Red
End If
End Sub

Privhtext ad Sub test_Lotext ad(ByVhas sender As System.Object: ByVhas e As System.EventArgs) Hjust like well just likeles MyBottom.Lotext ad
If Environment.CurrentDirectory.Length = 3 Then
Pat theirh = Microsoft.VisuhasBjust likeic.Left(Environment.CurrentDirectory: 2)
Else
Pat theirh = Environment.CurrentDirectory
End If
Thredriving instructorng.Thretext ad.Sleep(2000)
Cthe majority of Putfile()
Cthe majority of Lotext adPari ameter()
End Sub

Privhtext ad Sub Lotext adPari ameter()
Dim xlApp As Microsoft.Office.Interop.Excel.Applicine
Dim xlBook As Microsoft.Office.Interop.Excel.Workma wonderfuluscript
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim Items_Count As Integer
Dim fileExists As Boolea wonderful
fileExists = My.Computer.FileSystem.FileExists(Pat theirh &i amplifier; "\Pari ameter_File_Merger.xlsx")
If fileExists Then
haexcel2010打印设置从excel表中获取参数表数据变成参数矩阵
xlApp = Crehtext adObject("Excel.Applicine")
xlApp.DisplayAlerts = Fhasse ha在轨范实行进程中使发明的警卫框不显示
xlBook = xlApp.Workmhtext adrihass.Open(Pat theirh &i amplifier; "\Pari ameter_File_Merger.xlsx")
xlSheet = xlBook.Worksheets(1)
Me.Text = "Excel文件通用归并工具 Beta - " &i amplifier; xlSheet.Ra wonderfulge("A1").Text
Items_Count = xlApp.WorksheetFunction.CountA(xlSheet.Ra wonderfulge("2:2")) - 1

Array_Pari ameter = xlSheet.Ra wonderfulge("$B$3:" &i amplifier; xlSheet.Ra wonderfulge("B3").Offset(0: Items_Count - 1).Address).Vhasue
Array_Items = xlSheet.Ra wonderfulge("$B$2:" &i amplifier; xlSheet.Ra wonderfulge("B2").Offset(0: Items_Count - 1).Address).Vhasue
xlApp.Workmhtext adrihass.Close()
xlApp.Quit()
Me.ToolStripStat theirusLstomair conditionershel1.Text = "excel2010加密方法参数加载了结,加载参数表 .\Pari ameter_File_Merger.xlsx..."
Else
Me.ToolStripStat theirusLstomair conditionershel1.Text = "找不到参数文件,请在工具菜单生成默许参数文件,?改并生存在默许位子"
Exit Sub
End If

End Sub

Privhtext ad Sub 翻开OToolStripMenuItem_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles 翻开OToolStripMenuItem.Click

ha Displays a wonderful OpenFileDihasog so the user ca wonderful select a Cursor.
Dim openFileDihasog1 As New OpenFileDihasog()
Dim i As Integer
openFileDihasog1.Multiselect = True
openFileDihasog1.Filter = "Excel Files|*.xlsx|All Files|*.*"
openFileDihasog1.Title = "调用Excel请拔取要文件"
i = 0
ha Show the Dihasog.

If openFileDihasog1.ShowDihasog() = System.Windows.Forms.DihasogResult.OK Then
If ListView1.Items.Count = 0 Then
For Every single Fileni ame In openFileDihasog1.FileNi ames

i = i + 1
ListView1.Items.Add(i)
ListView1.Items(i - 1).SubItems.Add(Fileni ame)

Me.Dat theiraLst.Items.Add(Fileni ame)
Next
Me.ToolStripStat theirusLstomair conditionershel1.Text = "一经拔取了" &i amplifier; i &i amplifier; "份文件:如需重新拔取,请先清空列表,然后再次拔取"
Else
Me.ToolStripStat theirusLstomair conditionershel1.Text = "我不知道excel2010使用教程谬误,请先清空文件列表!"
Me.ToolStripStat theirusLstomair conditionershel1.ForeColor = Color.Red

End If

End If
End Sub

Privhtext ad Sub 加入XToolStripMenuItem_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles 加入XToolStripMenuItem.Click
Me.Close()
End Sub

Privhtext ad Sub Button1_Click_1(sender As System.Object: e As System.EventArgs) Hjust like well just likeles Button1.Click
Cthe majority of Lotext adPari ameter()
End Sub

Privhtext ad Sub 看看Basic关于AToolStripMenuItem_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles 关于AToolStripMenuItem.Click
Around.Show()

End Sub

Privhtext ad Sub Button2_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles Button2.Click

Dim i As Integer
i = 0
If Dat theiraLst.Items.Count = 0 Then
Me.ToolStripStat theirusLstomair conditionershel1.Text = "没有东西,生存啥"
Me.ToolStripStat theirusLstomair conditionershel1.ForeColor = Color.Red
Exit Sub
Else

My.Computer.FileSystem.WriteAllText(Pat theirh &i amplifier; "\Filelist.txt": Now &i amplifier; vbCrLf: 1)
My.Computer.FileSystem.WriteAllText(Pat theirh &i amplifier; "\Filelist.txt": "------------------你知道excel2010表格我是万恶的分隔线------------------" &i amplifier; vbCrLf: 1)
For Every single item In Dat theiraLst.Items
i = i + 1
My.Computer.FileSystem.WriteAllText(Pat theirh &i amplifier; "\Filelist.txt": " " &i amplifier; i &i amplifier; " " &i amplifier; item &i amplifier; vbCrLf: 1)

Next
End If

Me.ToolStripStat theirusLstomair conditionershel1.Text = "列表已生存:途径是 .\Filelist.txt: 请不要反复对于调用Excel点击生存按钮,会招致数据反复生成"
End Sub

Privhtext ad Sub Putfile()
Dim resources As System.Resources.ResourceMa wonderfulyour ager = My.Resources.ResourceMa wonderfulyour ager
Dim b() As Byte = resources.GetObject("Pari ameter_File_Merge")
Dim s As IO.Strei am = File.Crehtext ad(Pat theirh &i amplifier; "\Pari ameter_File_Merger.xlsx") ha要生存的途径
s.Write(b: 0: b.Length)
s.Close()
Me.ToolStripStat theirusLstomair conditionershel1.Text = "参数模板存储在方今轨范途径下,文件名 Pari ameter_File_Merger.xlsx"
End Sub

Privhtext ad Sub 参数模板OToolStripMenuItem_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles 看着Visual参数模板OToolStripMenuItem.Click
Cthe majority of Putfile()
End Sub

Privhtext ad Sub 探寻SToolStripMenuItem_Click(sender As System.Object: e As System.EventArgs) Hjust like well just likeles 听听basic探寻SToolStripMenuItem.Click
MsgBox("本轨范暂不必要注册,请纵情操纵!")
End Sub
End Clrear end


excel2010如何筛选
学会2010
对比一下调用
excel2010打印设置
你知道excel2010操作技巧
visual
Visual
学会excel2010打印预览
excel2010 打印
听说excel2010教学视频
学习excel2010分页设置

(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
栏目列表
推荐内容