Powershell Excel Automation - Save/Open fails in Scheduled Task

后端 未结 2 1499
长发绾君心
长发绾君心 2021-01-13 14:10

I created a simple powershell script that will create an excel instance and save a workbook:

$excel = New-Object -ComObject Excel.Application
$workbook = $ex         


        
相关标签:
2条回答
  • 2021-01-13 14:44

    I remember having to do something similar in a C# application, which went well when you build it on Visual Studio, but running under a service on the CI server failed. This I believe is the limitation of Office Automation itself and Microsoft doesn't recommend / support doing this at all Look at Considerations for server-side Automation of Office here - http://support.microsoft.com/kb/257757. It shows the problems and the alternatives.

    In my case, I had to give up Office Interop, and use EPPlus ( http://epplus.codeplex.com/ ) to work with excel. It worked great and was much faster as well.

    0 讨论(0)
  • 2021-01-13 14:56

    I've been burned by this and didn't want to rewrite the code. I saw your post and several others which made me about to give up. However, my persistence paid off. I was trying to have Jenkins run a script to inventory our production environment and output to Excel. I didnt want a text doc because I was highlighting software versions that didnt match in RED, so needed Excel.

    Here is the answer that worked for me:

    You have to create a folder (or two on a 64bit-windows):

    (32Bit, always)

    C:\Windows\System32\config\systemprofile\Desktop

    (64Bit)

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    Link that someone provided as the source:

    http://www.patton-tech.com/2012/05/printing-from-scheduled-task-as.html

    My source was:

    http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/aede572b-4c1f-4729-bc9d-899fed5fad02

    0 讨论(0)
提交回复
热议问题