由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005访问被拒绝。 (HRESULT的例外情况:0x80070005 ...... [英] Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005...

查看:98
本文介绍了由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005访问被拒绝。 (HRESULT的例外情况:0x80070005 ......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个包含> 3000条记录的excelsheet,我需要逐个单元格读取excelsheet。它给出了以下错误。





检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂由于以下错误而失败:80070005访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))。



您能否建议并提供C#代码以逐个单元格阅读Excel。尽快



谢谢



代码:

protected void btnImport_Click(object sender,EventArgs e)

{





int CreatedBy = Convert.ToInt32(Session [UsID]。ToString());

OdbcConnection连接;

SqlBulkCopy bulkCopy;

string errordesc = null;

lblError.Text =;

try < br $>
{



// Loc&DEPt&PAyperiod

DateTime payFDate1;

string PayFrom1,PayTo1;

payFDate1 = Convert.ToDateTime(cmbpayperiod.SelectedValue.ToString()。Trim());

PayFrom1 = payFDate1.ToShortDateString()。ToString( ).Trim();

PayTo1 = payFDate1.AddDays(13).ToShortDateString()。Trim();

string LocID = ddlLocation.SelectedValue;

string DIVID = ddlDivision.SelectedValue;





fn1 =系统。 IO.Path.GetFileName(fyle.PostedFile.FileName);

if((fyle.PostedFile!= null)&&(fyle.PostedFile.ContentLength> 0))

{

string fn = System.IO.Path.GetFileName(fyle.PostedFile.FileName);

string [] ext = fn.Split(new char [] {'。'});

int count = ext.Length;

string strExt = ext [count - 1] .ToString ();

if(strExt.Trim()==xls|| strExt.Trim()==xlsx)

{

fn2 = ext [0] .ToString()。Trim()+ - + String.Format({0:ddMMyyyyHHmmss},DateTime.Now)+。 + ext [count - 1] .ToString()。Trim();



fn1 = System.IO.Path.GetFileName(fyle.PostedFile.FileName); < br $>


//文件保存

字符串SaveLocation = Server.MapPath(Incentives)+\\+ fn2;

path = SaveLocation;

fyle.PostedFile.SaveAs(SaveLocation);





//批量导入

DataTable dt = new DataTable();

// DataRow行;

dt = GetDataTableFromExcel(path,ext [ count - 1] .ToString());



//按单元格读取每个单元格

Excel.Application xlApp;

Excel.Workbook xlWorkBook;

Excel.Worksheet xlWorkSheet;

Excel.Range range;



int rCnt = 0;

// int cCnt = 0;

string strPeriod =;

string StrName =;







试试

{

// opn excel

// CallWithTimeout(FiveSecondMethod,6000);



xlApp = new Excel.ApplicationClass();

// xlWorkBook = xlApp.Workbooks.Open(SaveLocation,0,true,5,,,true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,\ t ,false,false,0,true,1,0);

xlWorkBook = xlApp.Workbooks.Open(SaveLocation,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing .Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);

xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

range = xlWorkSheet.UsedRange;



for(rCnt = 1; rCnt< = range.Rows.Count; rCnt ++)

{



if(rCnt == 7){strPeriod =(string) (range.Cells [7,1]作为Excel.Range) 。文本; } //期间

if(rCnt> 7)

{

//名称

string strVAL = (string)(range.Cells [rCnt,2] as Excel.Range).Text;

if(strVAL.Trim()==){strVAL = StrName; } else {StrName = strVAL; }

dt.Rows [rCnt - 2] [1] = strVAL;



//日期

string strDate =(string)(range.Cells [rCnt,4] as Excel.Range).Text;

dt.Rows [rCnt - 2] [3] = strDate;



}

}



//关闭excel

xlWorkBook .Close(true,null,null);

xlApp.Quit();



//清除内存

releaseObject(xlWorkSheet);

releaseObject(xlWorkBook);

releaseObject(xlApp);

}

catch(Exception ex)

{

责任e.Write(ex.Message);

}

//删除最后一个和第一个

dt.Columns.RemoveAt(17);

dt.Columns.RemoveAt(0);

Hi,

I have an excelsheet wich containes >3000 records and I need to read that excelsheet each cell by cell. it is giving below error.


Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Could you please suggest and also give the C# code to read excel cell by cell.. ASAP

Thanks

CODE:
protected void btnImport_Click(object sender, EventArgs e)
{


int CreatedBy = Convert.ToInt32(Session["UsID"].ToString());
OdbcConnection connection;
SqlBulkCopy bulkCopy;
string errordesc = null;
lblError.Text = "";
try
{

//Loc & DEPt & PAyperiod
DateTime payFDate1;
string PayFrom1, PayTo1;
payFDate1 = Convert.ToDateTime(cmbpayperiod.SelectedValue.ToString().Trim());
PayFrom1 = payFDate1.ToShortDateString().ToString().Trim();
PayTo1 = payFDate1.AddDays(13).ToShortDateString().Trim();
string LocID = ddlLocation.SelectedValue;
string DIVID = ddlDivision.SelectedValue;


fn1 = System.IO.Path.GetFileName(fyle.PostedFile.FileName);
if ((fyle.PostedFile != null) && (fyle.PostedFile.ContentLength > 0))
{
string fn = System.IO.Path.GetFileName(fyle.PostedFile.FileName);
string[] ext = fn.Split(new char[] { '.' });
int count = ext.Length;
string strExt = ext[count - 1].ToString();
if (strExt.Trim() == "xls" || strExt.Trim() == "xlsx")
{
fn2 = ext[0].ToString().Trim() + "-" + String.Format("{0:ddMMyyyyHHmmss}", DateTime.Now) + "." + ext[count - 1].ToString().Trim();

fn1 = System.IO.Path.GetFileName(fyle.PostedFile.FileName);

//File Save
string SaveLocation = Server.MapPath("Incentives") + "\\" + fn2;
path = SaveLocation;
fyle.PostedFile.SaveAs(SaveLocation);


//Bulk Import
DataTable dt = new DataTable();
//DataRow row;
dt = GetDataTableFromExcel(path, ext[count - 1].ToString());

//Read each cell by cell
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;

int rCnt = 0;
//int cCnt = 0;
string strPeriod = "";
string StrName = "";



try
{
//opn excel
// CallWithTimeout(FiveSecondMethod, 6000);

xlApp = new Excel.ApplicationClass();
//xlWorkBook = xlApp.Workbooks.Open(SaveLocation, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkBook = xlApp.Workbooks.Open(SaveLocation, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;

for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{

if (rCnt == 7) { strPeriod = (string)(range.Cells[7, 1] as Excel.Range).Text; } //Period
if (rCnt > 7)
{
//Name
string strVAL = (string)(range.Cells[rCnt, 2] as Excel.Range).Text;
if (strVAL.Trim() == "") { strVAL = StrName; } else { StrName = strVAL; }
dt.Rows[rCnt - 2][1] = strVAL;

//Date
string strDate = (string)(range.Cells[rCnt, 4] as Excel.Range).Text;
dt.Rows[rCnt - 2][3] = strDate;

}
}

//Close excel
xlWorkBook.Close(true, null, null);
xlApp.Quit();

//clear memory
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
//Remove last and first
dt.Columns.RemoveAt(17);
dt.Columns.RemoveAt(0);

推荐答案

我想到了两件事。首先是检查是否在托管代码的机器上安装了Office。



第二个,安装了哪个版本的Office,它是32-或64-位办公室?您的代码必须编译才能匹配。使用AnyCPU的平台目标编译代码真的很好。这意味着在64位O / S上,您的代码以64位运行,在32位O / S上运行,它以32位运行。当您开始使用外部库时,这是一个问题。如果在64位操作系统上安装了32位Office,则代码将以64位运行,但尝试使用32位Office代码。您不能在同一进程中混合使用32位和64位代码,因此您可以获得上述错误消息。
Two things come to mind. The first is check to see if Office is installed on the machine hosting your code.

The second, which version of Office is installed and is it 32- or 64-bit Office? Your code has to be compiled to match. Chances are really good that your code is compiled with a Platform Target of AnyCPU. This means that on a 64-bit O/S, your code runs as 64-bit and on a 32-bit O/S, it runs as 32-bit. This is a problem when you start using external libraries. If you have 32-bit Office installed on a 64-bit O/S, your code will run as 64-bit but try to use 32-bit Office code. You cannot mix 32- and 64-bit code in the same process, so you can get the above error message.


这篇关于由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005访问被拒绝。 (HRESULT的例外情况:0x80070005 ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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