在我的WPF应用程序中,我试图使用Microsoft.Office.Interop.Excel读取excel文件。它工作正常。但突然间它给出了[system .__ comobject]而不是excel对象。我不知道现在发生了什么。你的帮助将节省我的一整天。谢谢。我的代码如下,
public class ReadExcelDataModel
{
Excel.Application excelApp = new Excel.Application();
Excel.Workbook workbook;
Excel.Worksheet worksheet;
Excel.Range range;
private int row = 0;
public ResponceModel ReadWorksheet(string FileName, string FilePath, ResponceModel ResponceResult)
{
Error error = new Error();
//workbook = Excel.Workbook;
//worksheet = new Excel.Worksheet();
object misValue = System.Reflection.Missing.Value;
List<Task<ResponceModel>> TaskList = new List<Task<ResponceModel>>();
try
{
string excelFilePath = string.Format("{0}\\{1}", FilePath, FileName);
workbook = excelApp.Workbooks.Open(excelFilePath);
for (int i = 1; i <= workbook.Sheets.Count; i++)
{
worksheet = (Excel.Worksheet)workbook.Sheets[i];
ResponceResult.SheetName = worksheet.Name;
ResponceResult.dataTable.Add(SwitchTheTables(worksheet, ResponceResult).TempDataTable);
}
workbook.Close(true, Missing.Value, Missing.Value);
excelApp.Quit();
ResponceResult.Responce = "OK";
return ResponceResult;
}
catch
{
error.ErrorCode = 405;
error.ErrorDescription = string.Format("The worksheet name not found.");
ResponceResult.Responce = "Error";
ResponceResult.ErrorList.Add(error);
return ResponceResult;
}
}
}
workbook = excelApp.Workbooks.Open(excelFilePath);在这里工作簿中将[system .__ comobject]作为值。以前它得到了excel对象。