-- 作者:langtu
-- 发布时间:2016/4/7 15:59:00
-- 关于用控件传递值得问题
如下面的帮助示例代码:怎样设计成通用的导出窗口呢?表名和保存文件名都可以指定的那种。
设计方法很简单:
1、将窗口的AfterLoad事件代码设置为:
Dim
ckl
As
WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") For
Each
dc
As
DataCol
In
DataTables("订单").DataCols ckl.Items.Add(dc.name) Next
2、将导出按钮的Clik事件代码设置为:
Dim
ckl
As
WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") Dim
nms
As
New
List(of
String) For
i
As
Integer = 0
To
ckl.Items.count - 1 \'获取已经勾选的列 If
ckl.GetItemChecked(i) Then nms.Add(ckl.Items(i)) End
If Next If
nms.Count = 0
Then MessageBox.Show("至少要选择一列","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Return End
If \'生成Excel表 Dim
dt
As
Table = Tables("订单") Dim
Book
As
New
XLS.Book
Dim
Sheet
As
XLS.Sheet = Book.Sheets(0) For
i
As
Integer = 0
To
nms.count -1 Sheet(0, i).Value = nms(i) Next For
r
As
Integer = 0
To
dt.Rows.Count - 1
\'填入数据 For
i
As
Integer = 0
To
nms.count -1 Sheet(r + 1, i).Value = dt.rows(r)(nms(i)) Next Next \'保存并打开excel文件 Book.Save("c:\\reports\\test.xls") Dim
Proc
As
New
Process Proc.File = "c:\\reports\\test.xls" Proc.Start() 此主题相关图片如下:1839.gif
|