以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助] CheckedListBox 选择项局部导出excel表 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=91984) |
||||
-- 作者:weigqing9 -- 发布时间:2016/10/23 23:21:00 -- [求助] CheckedListBox 选择项局部导出excel表 老师你好:请教CheckedListBox 选择项局部导出相应行的代码。谢谢
|
||||
-- 作者:狐狸爸爸 -- 发布时间:2016/10/24 8:12:00 -- 编程的逻辑能力你已经有了,但是有一些常识错误,要是花点时间看过两遍帮助,你可以成为高手。 Dim ckl As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") If ckl.CheckedIndices.count = 0 Then MessageBox.Show("至少要选择一个供应商","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Return End If Dim nms As String For Each i As Integer In ckl.CheckedIndices \'获取已经勾选的 nms = nms & ",\'" & ckl.Items(i) & "\'" Next nms = nms.Trim(",") \'生成Excel表 Dim dt As DataTable = DataTables("表A") Dim nm() As String = {"供应商","产品","规格","合计"} \'要导出的列名 Dim caps() As String = {"供应商","产品名称","规格/型号","合计金额"} \'对应的列标题 Dim szs() As Integer = {150,180,120,85} \'对应的列宽 Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 For c As Integer = 0 To nm.length -1 Sheet(1, c).Value = caps(c) \'指定列标题 Sheet.Cols(c).Width = szs(c) \'指定列宽 Next Sheet(0, 1).Value = e.Form.Controls("ComboBox1").value Dim drs As List(of DataRow) = dt.Select("供应商=\'" & e.Form.Controls("ComboBox1").value & "\' And 产品 in (" & nms & ")") For r As Integer = 0 To drs.count -1 \'填入数据 For i As Integer = 0 To nm.length -1 Sheet(r + 2, i).Value = drs(r)(nm(i)) Next Next \'保存并打开excel文件
Book.Save("d:\\test.xls") Dim Proc As New Process Proc.File = "d:\\test.xls" Proc.Start() e.Form().Close [此贴子已经被作者于2016/10/24 8:13:26编辑过]
|
||||
-- 作者:weigqing9 -- 发布时间:2016/10/24 10:53:00 -- 回复:(狐狸爸爸)编程的逻辑能力你已经有了,但是有... 感谢狐爸的鼓励 ,完美解决,谢谢! |