[英]creating excel file from an c# application
我正在嘗試創建一個Excel文件形式的C#應用程序。
我的代碼如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
public class ExcelFileCreation
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
***xlApp = new Excel.ApplicationClass();***
xlWorkBook = xlApp.Workbooks.Add(misValue);
//and further lines of code.....
}
我在上面突出顯示的行中收到以下錯誤,
無法嵌入互操作類型'Microsoft.Office.Interop.Excel.ApplicationClass'。 請改用適用的界面。
請幫我解決這個問題!
使用Excel.Application
而不是Excel.ApplicationClass
xlApp = new Excel.Application();
更新:您所引用的互操作程序集的“嵌入互操作類型”設置為true
。 根據這篇文章, Class
類型包含元數據和代碼,而接口僅包含元數據。 嵌入元數據是安全的,但不能嵌入任何可能包含可執行代碼的內容。
更換
xlApp = new Excel.ApplicationClass();
與
xlApp = new Excel.Application();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.