|
楼主 |
发表于 2012-12-2 16:55
|
显示全部楼层
Guardian·F·冰 发表于 2012-11-30 22:47
我想问一下,多线程是不是只能计算数据,不能用多线程对Excel进行操作?比如说同时对两个页面中的数据进行填 ...
没有问题啊 为了严谨我亲自测试了一下
建立文档级的Excel项目
在Sheet1中添加一个button控件 相关代码如下- Imports System.Threading
- Public Class Sheet1
- Private Sub Sheet1_Startup() Handles Me.Startup
- End Sub
- Private Sub Sheet1_Shutdown() Handles Me.Shutdown
- End Sub
- Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim rng() As Microsoft.Office.Interop.Excel.Range
- Dim num, i As Integer
- num = Application.InputBox("请输入需要同时填充几个区域", Type:=1)
- ReDim rng(num - 1)
- Dim s() As sA : ReDim s(num - 1)
- Dim Td() As Thread : ReDim Td(num - 1)
- For i = 0 To num - 1
- rng(i) = Application.InputBox("请输入需要填充的区域", Type:=8)
- s(i) = New sA(rng(i))
- Next
- For i = 0 To num - 1
- Td(i) = New Thread(New ThreadStart(AddressOf s(i).SumeOfNum))
- Td(i).Start()
- Next
- End Sub
- End Class
- Public Class sA
- Private sRng As Microsoft.Office.Interop.Excel.Range
- Public Sub New(ByVal rng As Microsoft.Office.Interop.Excel.Range)
- sRng = rng
- End Sub
- Public Sub SumeOfNum()
- sRng.Value = "OK"
- End Sub
- End Class
复制代码 一点问题都没有呢 多线程完成任务.....
但是你说的两个页面中的数据填充 是否是在两个工作簿中同时填充数据呢?
如果是的话也不会有问题 不过应该制作的应该是EXCEL的外接程序 或者 窗体应用程序 那样比较方便 |
|