winform 以管理员身份运行程序,操作EXCEL就会报错。
在打开程序路径下的EXCEL模板时就出错。
如果不是管理员身份运行则不会有这个问题。
这个问题不知道如何,请教。
你必须在Winfroms中使用管理员权限运行Excel,如下代码:
private void RunExcelWithAdminPrivileges()
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "excel.exe", // Path to Excel executable
Verb = "runas", // Specifies to run the process with administrator privileges
UseShellExecute = true
};
try
{
Process.Start(startInfo);
}
catch (System.ComponentModel.Win32Exception)
{
}
}
excel也要以管理员身份运行