以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 老师这是我的示例代码,可以帮我看一下导出吗 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=171542) |
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 13:48:00 -- 老师这是我的示例代码,可以帮我看一下导出吗 在第一个窗口里面,类似于这样
|
||||
-- 作者:有点蓝 -- 发布时间:2021/9/2 13:56:00 -- 学号是第2个列 Dim bh As String = sheet(n,1).Text
|
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 14:22:00 -- 老师怎么会空这么多格的 此主题相关图片如下:wechat 圖片_20210902142058.png |
||||
-- 作者:有点蓝 -- 发布时间:2021/9/2 14:27:00 -- execl里本身就有空行 在说代码有没有判断编号值是不是空的,自己加个判断
|
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 14:30:00 -- Dim bh As String = sheet(n,1).Text 第一个是0是吧 |
||||
-- 作者:有点蓝 -- 发布时间:2021/9/2 14:33:00 -- 是 |
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 15:00:00 -- 那如果每个人的学号列都不一样应该如何识别呢 |
||||
-- 作者:有点蓝 -- 发布时间:2021/9/2 15:15:00 -- 遍历第一行标题行,看哪个列的名称叫学号的,把列索引使用变量记下来 |
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 16:38:00 -- Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xlsx|Word文件|*.doc|Access文件|*.mdb" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim nms() As String = {"单号","状态","记录时间","店铺名称","产品类别","产品SKU","责任方","状况描述 原因","客户姓名","联系方式","寄送地址","处理方式","寄送SKU","配件SKU","数量","备注","发货仓库","系统单号","追踪号","物流公司","发货日期","收货日期","下单日期","回访","记录日期","结束日期","赠送SKU","处理时间"} Dim nms2() As String ={"单号", "状态","记录时间","店铺名称","产品类别","产品SKU","责任方","状况描述 原因","客户姓名","联系方式","寄送地址","处理方式","寄送SKU","配件SKU","数量","备注","发货仓库","系统单号","追踪号","物流公司","发货日期","收货日期","下单日期","回访","记录日期","结束日期","赠送SKU","处理时间"} Dim dict As new Dictionary(of String,String) For m As Integer = 0 To nms.Length - 1 dict.add(nms2(m),nms(m)) Next Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("table_3").StopRedraw() \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count -1 Dim bh As String = sheet(n,4).Text If DataTables("table_3").Find("单号 = \'" & bh & "\'")Is Nothing Then Dim r As Row = Tables("table_3").AddNew() For m1 As Integer = 0 To Sheet.Cols.Count - 1 If dict.ContainsKey(Sheet(0,m1).Value) r(dict(Sheet(0,m1).Value)) = Sheet(n,m1).Value End If Next r("处理人") = user.name End If Next Tables("table_3").ResumeRedraw() msgbox("导入成功") End If
|
||||
-- 作者:aaa1234 -- 发布时间:2021/9/2 16:39:00 -- 少了个单号 |