Dim Filter As String
With e.Form.Controls("上游客户")
If .text > "" Then
Filter = "上游客户 like \'%" & .text & "%\'"
End If
End With
With e.Form.Controls("品牌")
If .text > "" Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "品牌 like \'%" & .text & "%\'"
End If
End With
With e.Form.Controls("商品车")
If .text > "" Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "商品车 like \'%" & .text & "%\'"
End If
End With
With e.Form.Controls("备注")
If .text > "" Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "备注 like \'%" & .text & "%\'"
End If
End With
Dim s As String
For Each c As Col In maintable.cols
If c.Name <> "编辑" And c.Name <> "删除" Then
s = s & "," & c.name
End If
Next
Dim cmd As New SQLCommand
cmd.C
Dim nms() As String = {" & s.trim(", ") & " }
If Filter > "" Then
cmd.CommandText = "Se lect " & s.trim(",") & " From {} Where " & Filter
Else
cmd.CommandText = "Se lect " & s.trim(",") & " From {“ & maintable.NAME & ”} "
End If
Dim dt As DataTable = cmd.ExecuteReader()
Dim Book As New XLS.Book
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter = "Excel文件|*.xlsx" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
End If
Book = New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式
st.Format = "yyyy-MM-dd"
For c As Integer = 0 To nms.length - 1
If MainTable.Cols(nms(c)).IsDate Then \'如果是日期列
Sheet.Cols(c).Style = st \'设置显示格式
End If
Next
For c As Integer = 0 To nms.Count - 1
Sheet(0, c).Value = nms(c)
Next
For r As Integer = 0 To dt.DataRows.Count - 1
For c As Integer = 0 To nms.Count - 1
Sheet(r + 1, c).Value = dt.DataRows(r)(nms(c))
Next
Next
Book.Save(dlg.FileName)
Dim Result As DialogResult
Result = MessageBox.Show("导出成功,是否打开所导出文件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If