读取.xlsm文件时,外部表未处于预期格式错误 [英] External table not in expected format error while reading .xlsm file

查看:107
本文介绍了读取.xlsm文件时,外部表未处于预期格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个要读取的.xlsm文件.这是我使用的连接字符串:

I have one .xlsm file to read in my project. This is my connection string used:

If strExtension = ".xls" Then
                    MyConnection = New System.Data.OleDb.OleDbConnection _
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath & ";Extended Properties=""Excel 8.0;IMEX=1;;HDR=YES""")
                ElseIf strExtension = ".xlsx" Then
                    MyConnection = New System.Data.OleDb.OleDbConnection _
                    ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFilePath & ";Extended Properties=""Excel 12.0;IMEX=1;;HDR=YES""")
                ElseIf strExtension = ".xlsm" Then
                    MyConnection = New System.Data.OleDb.OleDbConnection _
                    ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFilePath & ";Extended Properties=""Excel 12.0 Macro;IMEX=1;;HDR=YES""")
                End If


Dim MyCommand As OleDbCommand = New OleDbCommand _
                    ("select * from [UserDetails$]", MyConnection)

                Dim dsChangedValues As New DataSet()
                Dim obj As OleDbDataAdapter = New OleDbDataAdapter(MyCommand)
                obj.Fill(dsChangedValues)




如果我要上传.xlsx文件,则效果很好.但是我必须上传一个.xlsm文件.

中给出了外部表未采用预期格式"的异常 obj.Fill(dsChangedValues)行. :(

有解决方案吗?

提前谢谢..
Ami




It works fine if I am uploading a .xlsx file. But I have to upload a .xlsm file.
Its giving ''External table not in the expected format'' exception in the
obj.Fill(dsChangedValues) line. :(

Any solutions?

Thanks in advance..
Ami

推荐答案

",MyConnection) Dim dsChangedValues As New DataSet() Dim obj As OleDbDataAdapter = 新建 OleDbDataAdapter( MyCommand) obj.Fill(dsChangedValues)
", MyConnection) Dim dsChangedValues As New DataSet() Dim obj As OleDbDataAdapter = New OleDbDataAdapter(MyCommand) obj.Fill(dsChangedValues)




如果我要上传.xlsx文件,则效果很好.但是我必须上传一个.xlsm文件.

中给出了外部表未采用预期格式"的异常 obj.Fill(dsChangedValues)行. :(

有解决方案吗?

提前谢谢..
阿米




It works fine if I am uploading a .xlsx file. But I have to upload a .xlsm file.
Its giving ''External table not in the expected format'' exception in the
obj.Fill(dsChangedValues) line. :(

Any solutions?

Thanks in advance..
Ami


这篇关于读取.xlsm文件时,外部表未处于预期格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆