Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共5 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:EXCEL表多工作表导入错误

1楼
benwong2015 发表于:2024/8/7 17:09:00
要将一个工作簿中有多个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
2楼
有点蓝 发表于:2024/8/7 17:24:00
调试技巧:http://www.foxtable.com/webhelp/scr/1485.htm,看哪一句代码出错

检查一下"资质能力清单"表事件代码
3楼
benwong2015 发表于:2024/8/7 18:13:00
 就在代码    Dim Book As New XLS.Book(dlg.FileName) 选择文档之后就提示错误,
4楼
benwong2015 发表于:2024/8/7 19:09:00
只能用wps将每一个工作表导出为工作簿,然后再批量导入工作簿。。。
5楼
有点蓝 发表于:2024/8/8 8:35:00
以下是引用benwong2015在2024/8/7 18:13:00的发言:
 就在代码    Dim Book As New XLS.Book(dlg.FileName) 选择文档之后就提示错误,

下一局代码是For Each sheet As XLS.Sheet In Book.Sheets,这个不看可能有问题的,请定位到具体哪一句代码出错
共5 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02734 s, 2 queries.