Foxtable(狐表)用户栏目专家坐堂 → 移动开发时 上传了excel文件 怎么写代码后台自动将excel文件的数据导入到对应的表中呢?


  共有2779人关注过本帖平板打印复制链接

主题:移动开发时 上传了excel文件 怎么写代码后台自动将excel文件的数据导入到对应的表中呢?

帅哥哟,离线,有人找我吗?
cnsjroom
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
移动开发时 上传了excel文件 怎么写代码后台自动将excel文件的数据导入到对应的表中呢?  发帖心情 Post By:2021/2/25 16:12:00 [只看该作者]

Select Case e.Path
    Case "upload.htm"
        Dim sb As New StringBuilder
        sb.appendLine("<form enctype='multipart/form-data' action='accept.htm' method='post' id='form1' name='form1'>")
        sb.appendLine(
"
单文件上传: <input type='file' name='up1' id='up1'><br/><br/>")
        sb.appendLine(
"
多文件上传: <input type='file' name='up2' id='up2' multiple><br/><br/>")
        sb.appendLine(
"<input Type='submit' name='Sumbit' id='Sumbit' value='
确定'>")
        sb.appendLine("</form>")
        e.WriteString(sb.ToString)
    Case "accept.htm"
        Dim sb As New StringBuilder
        For Each key As String In e.Files.Keys
            sb.AppendLine(key &
"
上传" & e.Files(key).Count & "个文件,分别是:</br>")
            For Each fl As String In e.Files(key)
                sb.AppendLine(fl & "<br>")
                e.SaveFile(key,fl,"d:\web\uploadfiles\" & fl)
'
保存接收到的文件
           
Next
            sb.AppendLine("</br>")
        Next
        sb.AppendLine("以上文件服务器已正确接收并保存!")
        e.WriteString(sb.ToString)

End
Select

移动开发时  上传了excel文件 怎么写代码后台自动将excel文件的数据导入到对应的表中呢?
参照帮助中的列子  采用上面的代码实现了上传excel等文件

现在假定选择了两个文件  一个是a名单。xls  一个是b名单。xls   
怎么写代码在后台自动将这两个表(直接判断名字中有名单两个字,就自动实现多个文件表一起导入)的数据合并到数据库中的  名单  表里面呢?

下面的代码怎么变通呢?如果直接使用,在页面端无法出现选择,在服务端可以弹出对话框进行操作

示例八

下面是一个批量合并的例子,假定目录c:\data下有多个Excel文件,这些文件都有一个名为订单的表,需要将这些表中的数据批量并到Foxtable的订单表中:

For Each fl As String In FileSys.GetFiles("c:\Data")
    Dim
mg As
New Merger
    mg.SourcePath = fl
    mg.Format =
"excel" '指定格式
    mg.SourceTableName =
"订单" '指定要合并的表
    mg.DataTableName =
"订单" '指定接收数据的表
    mg.Merge()
'开始合并
Next

示例九

也可以利用打开文件对话框一次选择多个文件来批量合并,例如:

Dim dlg As New OpenFileDialog
dlg
.Filter = "Access文件|*.mdb"
dlg
.MultiSelect = True '允许选择多个文件
If
dlg.ShowDialog =DialogResult.OK Then
    For Each
fl As String In dlg.FileNames
        Dim
mg As New Merger
       
mg.SourcePath = fl
       
mg.SourceTableName = "订单"
       
mg.DataTableName = "订单"
       
mg.Merge()
    Next
End If

[此贴子已经被作者于2021/2/25 16:14:38编辑过]

 回到顶部
总数 15 1 2 下一页