以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]请教条件导出excel问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=131957) |
-- 作者:sunion -- 发布时间:2019/3/10 11:52:00 -- [求助]请教条件导出excel问题 各位老师,请教一个问题,下面是导出信息表的代码。如果我只想导出“信息表”中“等级”列为A的全部数据,请问筛选条件应该怎么添加?谢谢 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 Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式 st.Format = "yyyy-MM-dd" 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)) If dt.Cols(nms(i)).IsDate Then \'如果是日期列 Sheet.Cols(i).Style = st \'设置显示格式 End If Next Next Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If |
-- 作者:有点甜 -- 发布时间:2019/3/10 12:15:00 -- Dim dt As Table = Tables("信息表") 改成 Dim dt As Table = Tables("信息表") dt.filter = "等级=\'A\'" |
-- 作者:sunion -- 发布时间:2019/3/10 12:18:00 -- 原来在这里,提前筛选一下,点赞 |