无法创建抽象类或接口“Excel.Application”的实例

crecrecre 2009-08-20 06:02:57
如何解决?
...全文
608 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weimeishuxi 2012-04-27
[Quote=引用 3 楼 的回复:]

引用 2 楼 lcl_data 的回复:
用Excel.ApplicationClass

记错了,好像word是ApplicationClass


C# code
static void Main(string[] args)
{

string strConnection = "Provider=Microsoft.AC……
[/Quote]
回复
pc_funning 2009-08-20
[Quote=引用 5 楼 wuyq11 的回复:]
Microsoft.Office.Interop.Excel.Application  app= new  Microsoft.Office.Interop.Excel.Application();
[/Quote]
就是这个
回复
wuyq11 2009-08-20
Microsoft.Office.Interop.Excel.Application app= new Microsoft.Office.Interop.Excel.Application();
回复
vwxyzh 2009-08-20
应该没问题的呀
Excel.Application接口有CoclassAttribute的,可以直接new的
回复
十八道胡同 2009-08-20
[Quote=引用 2 楼 lcl_data 的回复:]
用Excel.ApplicationClass
[/Quote]
记错了,好像word是ApplicationClass


static void Main(string[] args)   
{

string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";
strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\couse.xlsx;";
strConnection += "Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from [Sheet1$]", objConnection);
DataSet ds = new DataSet();
myCommandd.Fill(ds, "[Sheet1$]");
System.Data.DataTable dt = ds.Tables["[Sheet1$]"];
Console.WriteLine(dt.Columns[0].ToString());
Console.WriteLine(dt.Columns[1].ToString());
DataRow drDisplay = dt.Rows[0];
int[] num = new int[dt.Columns.Count];
for (int j = 0; ; )
{
for (int i = 0; i < dt.Columns.Count; i++)
{

if (drDisplay[i] is DBNull) ;
else
num[i] += Convert.ToInt32(drDisplay[i]);

}
if (++j >= dt.Rows.Count) break;
drDisplay = dt.Rows[j];
}
objConnection.Close();
object MissingValue = Type.Missing;
Microsoft.Office.Interop.Excel.Application app = new Application();
Microsoft.Office.Interop.Excel.Workbook wbook = app.Workbooks.Open(@"C:\Documents and Settings\v-changl\My Documents\couse.xlsx", MissingValue,
MissingValue, MissingValue, MissingValue,
MissingValue, MissingValue, MissingValue,
MissingValue, MissingValue, MissingValue,
MissingValue, MissingValue, MissingValue,
MissingValue);
Microsoft.Office.Interop.Excel.Worksheet wsheet = wbook.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
for (int i = 0; i < dt.Columns.Count; i++)
{
//注意下面是i+1,,excel小标默认从1开始
wsheet.Cells[dt.Rows.Count + 2, i + 1] = num[i].ToString();
}

wbook.Save();
wbook.Close(true, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wsheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
wsheet = null;
wbook = null;
app = null;
GC.Collect();


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2009/05/06/4154784.aspx

我的可以的啊
回复
十八道胡同 2009-08-20
用Excel.ApplicationClass
回复
CsToD 2009-08-20
Excel.ApplicationClass
回复
发动态
发帖子
C#
创建于2007-09-28

10.4w+

社区成员

.NET技术 C#
申请成为版主
社区公告

全世界最好的语言,没有之一.