以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]统计表导出时报错? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=175937) |
-- 作者:cqlpjks -- 发布时间:2022/3/24 15:41:00 -- [求助]统计表导出时报错? 统计表导出时报错: 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 -- 发布时间:2022/3/24 15:50:00 -- 解决了。谢谢! |