在c#中创建Excel对象时发生0x8001010A(RPC_E_SERVERCALL_RETRYLATER))异常

时间:2017-12-10 07:41:35

标签: c# .net excel com-interop

我正在编写一个用C#编写的excutable,它基本上打开一个现有的Excel文件(在C#中使用Microsoft.Office.Interop.Excel dll)并对它进行一些操作。 代码适用于我的用户帐户,但当我在不同的用户(管理员角色)下运行相同的代码时,它会在<!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-html --> <?php /** * PHPMailer SPL autoloader. * PHP Version 5 * @package PHPMailer * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk> * @author Jim Jagielski (jimjag) <jimjag@gmail.com> * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net> * @author Brent R. Matzelle (original founder) * @copyright 2012 - 2014 Marcus Bointon * @copyright 2010 - 2012 Jim Jagielski * @copyright 2004 - 2009 Andy Prevost * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @note This program is distributed in the hope that it will be useful - WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ /** * PHPMailer SPL autoloader. * @param string $classname The name of the class to load */ function PHPMailerAutoload($classname) { //Can't use __DIR__ as it's only in PHP 5.3+ $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php'; if (is_readable($filename)) { require $filename; } } if (version_compare(PHP_VERSION, '5.1.2', '>=')) { //SPL autoloading was introduced in PHP 5.1.2 if (version_compare(PHP_VERSION, '5.3.0', '>=')) { spl_autoload_register('PHPMailerAutoload', true, true); } else { spl_autoload_register('PHPMailerAutoload'); } } else { /** * Fall back to traditional autoload for old PHP versions * @param string $classname The name of the class to load */ function __autoload($classname) { PHPMailerAutoload($classname); } }

行引发异常
_excel = new Application();

以下是例外情况 -

_excel = new Application(); // throws an exception
_excel.Visible = _showExcel;

在任务管理器中,我可以在发生此异常后看到Excel进程。

使用计算机管理&gt; 系统工具&gt; 本地用户和群组&gt; 群组&gt; < kbd>管理员,我确认用户是管理员角色。

我使用powershell命令提示符(以其他用户身份打开)运行Exe文件

我已经搜索了很多与此错误相关的网页,但我没有获得与我的具体问题相关的任何成功。

1 个答案:

答案 0 :(得分:1)

抛出此异常,因为Excel正忙,不会为任何对象模型调用提供服务。 尝试以下代码:

 xlWorkSheet.EnableSelection = xlWorkSheet.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection;

如果无效,请关注microsoft solution

相关问题