zoukankan      html  css  js  c++  java
  • PowerShell 操作 OFFICE

     

    UiPath操作Office软件的方式,这里说一下用PowerShell调用Office的COM组件的方式

    老生常谈~每个程序员都要至少掌握一门脚本编程语言。。。

    EXCEL:

    1 $excel = New-Object -ComObject Excel.Application;
    2 $excel.DisplayAlerts = $False;
    3 $wb=$excel.Workbooks.Open("oldexcelpath");
    4 $wb.SaveAs("newexcelpath",51,"password");
    5 $wb.Close();
    6 $excel.Quit();
    View Code

    在ISE上运行正常,但移植到UiPath中就报错了 类似Old Format or Invalid Type Library

    将地域重新设置下就可以了。

    1 $currentThread = [System.Threading.Thread]::CurrentThread;
    2 $culture = [System.Globalization.CultureInfo]::GetCultureInfo("en-us");
    3 $currentThread.CurrentCulture = $culture;
    4 $currentThread.CurrentUICulture = $culture;
    View Code

    WORD:

    1 $Word=NEW-Object –ComObject Word.Application;
    2 $Document=$Word.documents.open("oldpath");
    3 $Document.SaveAs([ref]"newpath",[ref]12,[ref][Type].Missing,[ref]"password");
    4 $Document.Close();
    5 $Word.Quit();
    View Code

    详细参数列表,请参见MSDN

    workbooks-open-method-excel

  • 相关阅读:
    Redis 思维导图 (解析版)
    一张图片了解redis
    Redis 思维导图
    计算机网络协议
    IT笔面试题
    Hadoop集群搭建
    天涯论坛只看楼主
    齐秦&r大约在冬季现场版
    郁可唯茶汤现场版
    MTK平台电路设计01
  • 原文地址:https://www.cnblogs.com/mxue/p/UiPath_CodeOfficeByPowerShell.html
Copyright © 2011-2022 走看看