首页 > 解决方案 > 任务计划程序问题和读取 Excel 文件

问题描述

我有一个应用程序可以读取 Excelfiles 并将它们转换为文本文件(制表符分隔)。它首先将文件从源目录复制到同一台机器(我的笔记本电脑或它所在的服务器)上的临时文件夹中。在本地,应用程序可以正常工作。我将应用程序迁移到 Windows 2012R2 服务器并使用我的帐户进行了测试,它也可以正常工作当我安排它时,应用程序无法访问文件 c:\temp\tmp.xls。异常信息:

An exception occurred in class ExcelWorkbook, method SaveAsText_Tab. Exception info below:
    Microsoft Excel cannot access the file C:\TEMP\LUXINTRANET_JET_CUSTOMERS.xlsx. There are multiple reasons:

• The name of the file or path does not exist.
• The file is in use by another program.
• The workbook you are trying to save has the same name as a workbook that is opened already.

       at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
   at ExcelHandler.Concrete.ExcelWorkbook.SaveAsText_Tab(String filename)

我已经找到了异常点,它就在这一行:

clsWorkbook = clsExcel.Workbooks.Open(filename);

奇怪的是,只有当我通过任务调度程序而不是通过我自己的帐户运行应用程序时才会发生这种情况。

日程安排是使用我的凭据和高权限设置的。

几天以来,我一直在思考这个问题,但这似乎不合逻辑,因为我使用同一个用户在本地、服务器上和通过任务计划程序运行它。

有什么建议么?

标签: c#excelscheduled-tasks

解决方案


推荐阅读