workbook.SaveAs(文件路径)在暂存环境中不工作
workbook.SaveAs(Filepath) Not working in Staging env
我试图在读取 Excel sheet 时从 excel 中删除空行和空列。
在我的本地环境中工作 fine.In 暂存环境不工作 workbook.SaveAs() functionality.I 已经放置了一些日志来读取该日志以获取跟踪和错误方法,在 workbook.SaveAs() 行之后下一个日志不是 reading.let 我知道解决这个问题的方法是什么。Code image
出现以下错误:
由于以下错误,为 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件检索 COM class 工厂失败:80080005 服务器执行失败(HRESULT 异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))。
[HttpPost]
public ActionResult ImportPartNumbersFromexcel()
{
DataSet ds = new DataSet();
string UserID = Convert.ToString(Session["userID"]);
ds = dbOperations.GetPartNumbers(UserID);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "GetPartNumbers", null);
DataTable partnums = ds.Tables[0];
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
HttpPostedFileBase file = null;
string extension = string.Empty;
string fname = "";
string NewPath = string.Empty;
for (int i = 0; i < files.Count; i++)
{
file = files[i];
// Checking for Internet Explorer
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
FileInfo fi = new FileInfo(fname);
extension = fi.Extension;
fname = UserID + "_" + fname + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension;
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/EOrderImports/"), fname);
file.SaveAs(fname);
}
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname, null);
string connString = "";
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(fname);
Microsoft.Office.Interop.Excel.Worksheet worksheet = workbook.Worksheets["Sheet1"];
Microsoft.Office.Interop.Excel.Range usedRange = worksheet.UsedRange;
object[,] allValues = (object[,])usedRange.Cells.Value;
int totalRows = usedRange.Rows.Count;
if (totalRows == 1)
{
return Json("InvalidTemplate", JsonRequestBehavior.AllowGet);
}
#region Delete Empty Rows and Cols from Template
DeleteEmptyRowsCols(worksheet);
#endregion
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "DeleteEmptyRowsCols", null);
string filename = file.FileName;
FileInfo fii = new FileInfo(filename);
fname = Path.GetFileNameWithoutExtension(fii.Name);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname, null);
string fname1 = string.Empty;
fname = fname + "_Removed" + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension;
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/EOrderImports/"), fname);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname1, null);
//workbook.SaveAs(fname1);
try
{
workbook.SaveAs(fname, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange);
}
catch (Exception ex)
{
Logger.WriteLog("Public", "ImportPartNumbersFromexcel", ex, null);
}
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "SaveAS", null);
}
请参考Retrieving the COM class factory for component failed
我只是把修复的内容粘贴在这里。
在 DCOMCNFG 中,右键单击我的电脑和 select 属性。
选择 COM 证券选项卡。
在访问权限中,单击编辑默认值并将网络服务添加到
它并给它允许本地访问权限。对<做同样的事情
Machine_name >\Users.
在启动和激活权限中,单击编辑默认值并添加
为其提供网络服务并为其提供本地启动和本地激活
允许。对 < Machine_name >\Users.
做同样的事情
我试图在读取 Excel sheet 时从 excel 中删除空行和空列。 在我的本地环境中工作 fine.In 暂存环境不工作 workbook.SaveAs() functionality.I 已经放置了一些日志来读取该日志以获取跟踪和错误方法,在 workbook.SaveAs() 行之后下一个日志不是 reading.let 我知道解决这个问题的方法是什么。Code image
出现以下错误: 由于以下错误,为 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件检索 COM class 工厂失败:80080005 服务器执行失败(HRESULT 异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))。
[HttpPost]
public ActionResult ImportPartNumbersFromexcel()
{
DataSet ds = new DataSet();
string UserID = Convert.ToString(Session["userID"]);
ds = dbOperations.GetPartNumbers(UserID);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "GetPartNumbers", null);
DataTable partnums = ds.Tables[0];
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
HttpPostedFileBase file = null;
string extension = string.Empty;
string fname = "";
string NewPath = string.Empty;
for (int i = 0; i < files.Count; i++)
{
file = files[i];
// Checking for Internet Explorer
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
FileInfo fi = new FileInfo(fname);
extension = fi.Extension;
fname = UserID + "_" + fname + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension;
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/EOrderImports/"), fname);
file.SaveAs(fname);
}
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname, null);
string connString = "";
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(fname);
Microsoft.Office.Interop.Excel.Worksheet worksheet = workbook.Worksheets["Sheet1"];
Microsoft.Office.Interop.Excel.Range usedRange = worksheet.UsedRange;
object[,] allValues = (object[,])usedRange.Cells.Value;
int totalRows = usedRange.Rows.Count;
if (totalRows == 1)
{
return Json("InvalidTemplate", JsonRequestBehavior.AllowGet);
}
#region Delete Empty Rows and Cols from Template
DeleteEmptyRowsCols(worksheet);
#endregion
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "DeleteEmptyRowsCols", null);
string filename = file.FileName;
FileInfo fii = new FileInfo(filename);
fname = Path.GetFileNameWithoutExtension(fii.Name);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname, null);
string fname1 = string.Empty;
fname = fname + "_Removed" + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension;
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/EOrderImports/"), fname);
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", fname1, null);
//workbook.SaveAs(fname1);
try
{
workbook.SaveAs(fname, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange);
}
catch (Exception ex)
{
Logger.WriteLog("Public", "ImportPartNumbersFromexcel", ex, null);
}
Logger.TestWriteLog("Public", "ImportPartNumbersFromexcel", "SaveAS", null);
}
请参考Retrieving the COM class factory for component failed
我只是把修复的内容粘贴在这里。
在 DCOMCNFG 中,右键单击我的电脑和 select 属性。
选择 COM 证券选项卡。
在访问权限中,单击编辑默认值并将网络服务添加到 它并给它允许本地访问权限。对<做同样的事情 Machine_name >\Users.
在启动和激活权限中,单击编辑默认值并添加 为其提供网络服务并为其提供本地启动和本地激活 允许。对 < Machine_name >\Users.
做同样的事情