要将一个工作簿中有多个sheet的表格中内容导入系统,针对单个工作表导入此代码没有问题,但如果有一定数量以上的话,导入的时候会出现以下的错误,请问是什么问题
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:窗口,A-01资质导入,Button2,Click
详细错误信息:
已添加了具有相同键的项。
此主题相关图片如下:qq截图20240807170749.png
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls"
Dim nms() As String = {"领域序号", "领域", "类别序号", "类别", "对象序号", "检测对象", "项目参数序号", "项目参数名称", "依据的标准名称及编号", "限制范围", "说明"}
If dlg.ShowDialog = DialogResult.OK Then
Dim Book As New XLS.Book(dlg.FileName)
For Each sheet As XLS.Sheet In Book.Sheets
Tables("资质能力清单").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim ym As String
For p As Integer = 0 To 20
If sheet(0, p).Text <> "" Then
ym = sheet(0, p).Text.Replace(" ", "")
Exit For
End If
Next
Dim y As Integer = ym.IndexOf("共")
ym = ym.Substring(0, y)
Dim k As Integer
For k = 0 To Sheet.Rows.Count - 1
Dim lyxh As String = sheet(k, 0).Text
If lyxh <> "" Then
lyxh = lyxh.Replace(vbCrLf, "")
If lyxh = "领域序号" Then
k = k + 1
Exit For
End If
End If
Next
For n As Integer = k To Sheet.Rows.Count - 1
Dim bh As String = sheet(n, 0).Text
If bh <> "" Then
Dim r As Row = Tables("资质能力清单").AddNew()
For m As Integer = 0 To nms.Length - 1
Dim txt As String = Sheet(n, m).Value
txt = txt.Replace(vbCrLf, "")
r(nms(m)) = txt
r("页码") = ym
r("页码标记") = ym & "序号" & r("项目参数序号")
r.Save
Next
End If
Next
Tables("资质能力清单").ResumeRedraw()
Next
End If
就在代码 Dim Book As New XLS.Book(dlg.FileName) 选择文档之后就提示错误,
只能用wps将每一个工作表导出为工作簿,然后再批量导入工作簿。。。
以下是引用benwong2015在2024/8/7 18:13:00的发言:
就在代码 Dim Book As New XLS.Book(dlg.FileName) 选择文档之后就提示错误,
下一局代码是For Each sheet As XLS.Sheet In Book.Sheets,这个不看可能有问题的,请定位到具体哪一句代码出错