请教:连接Execl文件
    Dim g_Cnn_Execl As ADODB.Connection
    Dim rs_Execl As ADODB.Recordset
    Set g_Cnn_Execl = New ADODB.Connection
    Set rs_Execl = New ADODB.Recordset    g_ExeclFileName = App.Path & "\a3.xls"
    g_ExeclHdr = "NO"                      '有两个值:YES/NO,表示第一行是否字段名,默认是YES,第一行是字段名
    g_ExeclImex = "1"                       '1 解决数字与字符混合时,识别不正常的情况    g_Cnn_Execl.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & g_ExeclFileName & ";Extended Properties='Excel 8.0;HDR=" & g_ExeclHdr & ";IMEX=" & g_ExeclImex & "'"    '从EXECL文件中写入内容
    vsql_Execl = "select * from [sheet1$]"    rs_Execl.Open vsql_Execl, g_Cnn_Execl, adOpenDynamic, adLockOptimistic
        If rs_Execl.State = adStateOpen Then
            rs_Execl.AddNew
            
            rs_Execl(0) = "服务单号"
            rs_Execl(1) = "报修时间"
            rs_Execl(2) = "区域号"
            rs_Execl(3) = "门店性质"
            rs_Execl(4) = "磁卡号"
            rs_Execl(5) = "门店名称"
            rs_Execl(6) = "门店地址"
            rs_Execl(7) = "报修内容"
            rs_Execl(8) = "解决方法"
            rs_Execl(9) = "难度等级"
            rs_Execl(10) = "指派人员"
            rs_Execl(11) = "设备名称"
            rs_Execl(12) = "设备型号"
            rs_Execl(13) = "收费金额"
            
            rs_Execl.Update
       End If
 
        rs_Execl.Close
        Set rs_Execl = Nothing
        
        g_Cnn_Execl.Close
        Set g_Cnn_Execl = Nothing
        
End Sub
出现错误为:不能更新。数据库或对象为只读

解决方案 »

  1.   

    似乎以前我也遇到过这个问题,数据库方式打开EXCEL只能读不能写的.
    将EXCEL导入ACCESS操作,完成后再导出来就好了.
    用ACCESS对象导入导出EXCEL也是非常快速的.
      

  2.   

    连接串试试改为: 
    "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & g_ExeclFileName & ";Extended Properties=Excel 8.0;"
      

  3.   


    我装连接串改了后,运行到 rs_Execl(1) = "报修时间"时已报错了,这次报的错是 在对应所需名称或序数的集合中,未找到项目。