以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 导入带图片的Excel,总是提示错误 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=191920) |
-- 作者:a2704g -- 发布时间:2024/5/15 16:38:00 -- 导入带图片的Excel,总是提示错误 Dim tbmc As String = "公安未带头盔_预警列表" Dim fl As String Dim dlg As New OpenFileDialog dlg.Filter = "Excel2003文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 If MessageBox.Show("是否导入?","请确认!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) = DialogResult.OK Then DataTables(tbmc).StopRedraw Dim App As New MSExcel.Application try Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName) Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) Dim Rg As MSExcel.Range = Ws.UsedRange Dim ary = rg.value Forms("导数进度条").Open Dim prb As WinForm.ProgressBar =Forms("导数进度条").Controls("ProgressBar1") prb.Maximum = rg.Rows.Count Dim nms() As String = {"地市", "层级", "预警地址", "设备编码", "预警类型", "告警时间", "布控名称", "状态", "告警图片"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 Dim r As Row For n As Integer = 2 To rg.Rows.Count prb.Value = n r = Tables(tbmc).AddNew For m As Integer = 0 To Tables(tbmc).Cols.Count - 4 \'减去相对-excel列多出列数-1 If m = 8 Then fl= ProjectPath & "Attachments\\" & r("设备编码") & n & ".jpg" \'MessageBox.Show(fl) If ary(n, m + 1).SaveImage(fl) Then \'如果照片保存成功 r("告警图片") = fileSys.GetName(fl) End If Else r(nms(m)) = ary(n, m + 1) End If Next Next DataTables(tbmc).Save Forms("导数进度条").Close MessageBox.Show("导入成功!","恭喜!") catch ex As exception msgbox(ex.message) MessageBox.Show("导入失败!","恭喜!") finally DataTables(tbmc).ResumeRedraw app.quit End try Else Return End If End If
[此贴子已经被作者于2024/5/16 9:33:21编辑过]
|
-- 作者:有点蓝 -- 发布时间:2024/5/15 16:47:00 -- 没见过1楼的用法,换种方式试试:http://www.foxtable.com/webhelp/topics/2492.htm 或者:http://foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=107390&replyID=734188&skin=1
|
-- 作者:a2704g -- 发布时间:2024/5/15 17:07:00 -- 按方法1提升这样的错误 按方法1提升这样的错误 [此贴子已经被作者于2024/5/15 17:06:50编辑过]
|
-- 作者:a2704g -- 发布时间:2024/5/15 18:01:00 -- 蓝版,能否根据我那个Excel写一个简单例子 |
-- 作者:有点蓝 -- 发布时间:2024/5/15 20:32:00 -- Dim Book As New XLS.Book("d:\\问题\\202405041636543400100 (2).xls") Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count - 1 Dim r As Row = Tables("表A").AddNew() r("地市") = sheet(n, 0).Text r("设备编码") = sheet(n, 3).Text Dim s As String = ProjectPath & "Attachments\\" & r("设备编码") & n & ".jpg" If Sheet(n, 8).SaveImage(fl) Then \'如果照片保存成功 dr("告警图片") = fileSys.GetName(fl) End If Next |
-- 作者:a2704g -- 发布时间:2024/5/16 9:20:00 -- 如果数据多,提示内存不足 用蓝版上面的代码可以解决导入问题, 但是又有新问题了,如果数据多,提示内存不足,怎样解决这个问题
[此贴子已经被作者于2024/5/16 9:27:48编辑过]
|
-- 作者:有点蓝 -- 发布时间:2024/5/16 9:37:00 -- 处理图片一向都是很费内存的,可以拆分为几个文件处理 |