Foxtable(狐表)用户栏目专家坐堂 → [求助]统计表导出时报错?


  共有3138人关注过本帖树形打印复制链接

主题:[求助]统计表导出时报错?

帅哥哟,离线,有人找我吗?
cqlpjks
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:407 积分:3194 威望:0 精华:0 注册:2011/2/28 11:57:00
[求助]统计表导出时报错?  发帖心情 Post By:2022/3/24 15:41:00 [只看该作者]

统计表导出时报错:

图片点击可在新窗口打开查看此主题相关图片如下:运行报错.png
图片点击可在新窗口打开查看
如何修改
代码?请指教!谢谢!
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    If e.Form.Controls("年级1").value Is Nothing Then
        MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
    Else
        Dim xks() As String = {"考号","化","生","政","地"}
        Dim nj As String = e.Form.Controls("年级1").text
        For Each xk As String In xks
            If DataTables.Contains(nj & xk &"考号条码汇总") Then
                Tables(nj & xk &"考号条码汇总").SaveExcel(dlg.FileName,nj & xk &"考号条码汇总") '保存文件
                DataTables.Delete(nj & xk &"考号条码汇总") '删除原文件
            End If
            Dim book As new XLS.Book(dlg.FileName) '保存为Excel文件
            Dim sheet As XLS.Sheet = book.Sheets(nj & xk &"考号条码汇总") '保存为Excel文件中的一个工作表
            Dim Style As Xls.Style = book.NewStyle '新建一个样式
            Style.WordWrap = XLS.LineStyleEnum.Thin '单元格内容自动换行
            Style.AlignHorz = XLS.AlignHorzEnum.Center '居中
            Style.AlignVert = XLS.AlignVertEnum.Center '居中
            Style.BorderTop = XLS.LineStyleEnum.Thin
            Style.BorderBottom = XLS.LineStyleEnum.Thin
            Style.BorderLeft = XLS.LineStyleEnum.Thin
            Style.BorderRight = XLS.LineStyleEnum.Thin
            Style.BorderColorTop = Color.Black
            Style.BorderColorBottom = Color.Black
            Style.BorderColorLeft = Color.Black
            Style.BorderColorRight = Color.Black
            For i As Integer = 0 To sheet.Rows.count -1
                For n As Integer = 0 To sheet.Cols.count -1
                    sheet(i,n).Style = Style
                Next
            Next
            Book.Save(dlg.FileName) '保存文件
        Next
    End If
    e.Form.Controls("Label1").Text = "考号条码汇总已导出并删除!"
End If


Dim xks() As String = {"考号","化","生","政","地"} 只有“考号”存在,"化","生","政","地"不存在时就出现报错,"考号","化","生","政","地"都存在时没问题。
[此贴子已经被作者于2022/3/24 15:45:34编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
cqlpjks
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:407 积分:3194 威望:0 精华:0 注册:2011/2/28 11:57:00
  发帖心情 Post By:2022/3/24 15:50:00 [只看该作者]

解决了。谢谢!

 回到顶部