从现有Excel文件创建XML文件时出错 [英] Error while creating an XML File from existing Excel File

查看:97
本文介绍了从现有Excel文件创建XML文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下c#源代码中执行时显示错误消息:

An error message displays while executing below c# source code:

using System.Xml;
Excel = Microsoft.Office.Interop.Excel;

  System.Data.OleDb.OleDbConnection MyConnection;
            System.Data.DataSet ds;
            System.Data.OleDb.OleDbDataAdapter MyCommand;
            MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=''d:\\Mail_ids.xls'';Extended Properties=Excel 8.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
            MyCommand.TableMappings.Add("Table", "Product2");
            ds = new System.Data.DataSet();
            MyCommand.Fill(ds);   // this line shows error
            MyConnection.Close();
            ds.WriteXml("Product2.xml");



错误消息是:

"Microsoft Jet数据库引擎找不到对象"Sheet1 $".请确保对象存在,并且您正确拼写了它的名称和路径名."

确认指定的Excel文件存在于该位置的位置.
错误的原因是什么,正确的代码应该是什么?



And the error message is :

"The Microsoft Jet database engine could not find the object ''Sheet1$''. Make sure the object exists and that you spell its name and the path name correctly."

Where its confirmed that the specified Excel file exists at the said location.
What is the reason for the error and what should be the right code?

推荐答案

,MyConnection); MyCommand.TableMappings.Add("Table","Product2"); ds = new System.Data.DataSet(); MyCommand.Fill(ds); //此行显示错误 MyConnection.Close(); ds.WriteXml("Product2.xml");
", MyConnection); MyCommand.TableMappings.Add("Table", "Product2"); ds = new System.Data.DataSet(); MyCommand.Fill(ds); // this line shows error MyConnection.Close(); ds.WriteXml("Product2.xml");



错误消息是:

"Microsoft Jet数据库引擎找不到对象"Sheet1



And the error message is :

"The Microsoft Jet database engine could not find the object ''Sheet1


".请确保该对象存在,并且您正确拼写了其名称和路径名."

确认指定的Excel文件存在于该位置的位置.
错误的原因是什么,正确的代码应该是什么?
''. Make sure the object exists and that you spell its name and the path name correctly."

Where its confirmed that the specified Excel file exists at the said location.
What is the reason for the error and what should be the right code?


验证excel文件中的工作表名称&编码,确保两者相同.

运行时错误"-2147217865(80040e37)":Microsoft Jet数据库引擎找不到对象"Sheet1
Verify the sheet name in your excel file & the coding, ensure both are same.

Runtime error ''-2147217865 (80040e37)'': The Microsoft Jet database engine could not find the object ''Sheet1


这篇关于从现有Excel文件创建XML文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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