S elect Case e.Sender.Name
Case "导出"
If Tables(maintable.Name).Rows.Count = 0 Then
MessageBox.Show("无可导出数据,请重新确认!", "提示")
Else
Dim cmd As New SQLCommand
cmd.C
Dim nms() As String = {"打印", "结算单号", "承运单位", "台数", "下游金额", "下游调整金额", "下游考核金额", "借款金额", "运费余款", "汇款信息", "备注", "操作员", "操作日期", "打印人", "打印日期", "打印次数"}
If Filter > "" Then
cmd.CommandText = "S elect 打印, 结算单号, 承运单位, 台数, 下游金额, 下游调整金额, 下游考核金额, 借款金额, ISNULL(下游金额, 0)+ ISNULL(下游调整金额, 0)- ISNULL(下游考核金额, 0)- ISNULL(借款金额, 0) AS 运费余款, 汇款信息, 备注, 操作员, 操作日期, 打印人, 打印日期, 打印次数 From {外协单位结算} W here " & Filter
Else
cmd.CommandText = "S elect 打印, 结算单号, 承运单位, 台数, 下游金额, 下游调整金额, 下游考核金额, 借款金额, ISNULL(下游金额, 0)+ ISNULL(下游调整金额, 0)- ISNULL(下游考核金额, 0)- ISNULL(借款金额, 0) AS 运费余款, 汇款信息, 备注, 操作员, 操作日期, 打印人, 打印日期, 打印次数 F rom {外协单位结算}"
End If
MessageBox.Show("1")
Dim dt As DataTable = cmd.ExecuteReader()
MessageBox.Show("2")
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)
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
MessageBox.Show("3")
For c As Integer = 0 To nms.Count - 1
Sheet(0, c).Value = nms(c)
Next
MessageBox.Show("4")
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
MessageBox.Show("5")
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
End If
End If
MessageBox.Show("6")
End Select
第二段代出现以下错误提示:
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:
详细错误信息:
“)”附近有语法错误。