VS C#-Microsoft Excel对象库参考

VS C#-Microsoft Excel对象库参考,c#,C#,编辑: 我正在尝试在Visual Studio C#中使用Microsoft Excel 代码: 错误: System.Runtime.InteropServices.COMException:“无法访问'examplewrite.xlsx'。 我正在使用VS Community 2017。是的,它要求所有客户端计算机都安装了相同版本的Microsoft Excel 更多信息请参见此处:是的,它要求所有客户端计算机安装相同版本的Microsoft Excel 更多信息请参见此处:我已经解决了这个

编辑:

我正在尝试在Visual Studio C#中使用Microsoft Excel

代码:

错误:

System.Runtime.InteropServices.COMException:“无法访问'examplewrite.xlsx'。


我正在使用VS Community 2017。

是的,它要求所有客户端计算机都安装了相同版本的Microsoft Excel


更多信息请参见此处:

是的,它要求所有客户端计算机安装相同版本的Microsoft Excel


更多信息请参见此处:

我已经解决了这个问题。现在我得到了第二个错误。请看,一切都解决了,我已经解决了。现在我得到了第二个错误。请看。解决了所有问题。除非您的程序使用UAC提升运行,否则无法写入C:\目录。选择一个更好的目录,用户的文档文件夹将是一个合乎逻辑的选择。获取其路径。除非程序使用UAC提升运行,否则无法写入C:\目录。选择一个更好的目录,用户的文档文件夹将是一个合乎逻辑的选择。获取其路径。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;

namespace write_data_to_excel
{
    class Program
    {
        static void Main(string[] args)
        {
            Excel.Application xlApp = new Excel.Application();

            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            xlWorkSheet.Cells[1, 1] = "ID";
            xlWorkSheet.Cells[1, 2] = "Name";
            xlWorkSheet.Cells[2, 1] = "1";
            xlWorkSheet.Cells[3, 1] = "2";
            xlWorkSheet.Cells[3, 2] = "Two";

            xlWorkBook.SaveAs("C:\\examplewrite.xlsx", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();


        }
    }
}