• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >PowerShell > powershell操作word详解

powershell操作word详解

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了powershell word,powershell,windows powershell,powershell是什么,powershell下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

powershell操作word

我假设许多读者用PowerShell生成服务器、事件以及Windows网络上各种数据的报表。您也许创建过纯文本文件,甚至漂亮的HTML报表。但是您也可以用上Microsoft Word,当然,前提是您已经安装了Word。在这个系列的第二部分,我将会向您演示如何用PowerShell为Word文档套用样式。

创建Word应用程序对象
PowerShell可以通过COM接口控制Word应用程序。有趣的地方是,虽然您可以交互式地做所有的操作,但我希望您最终能够用脚本操作一切。我们从创建一个Word程序对象开始。

下一步,我们创建一个文档对象。

这些就是要做的所有事情。最终生成的Word文档是可用的,虽然可能不太漂亮。在我的例子中发现一个问题:Word用的事非等宽字体,而PowerShell的输出格式假设用的是等宽字体。(译者注:可能会造成输出的结果对不整齐)。

第二个示例

$objDocument = $objWord.Documents.Add($objMissingValue, $objMissingValue, $objMissingValue, $objMissingValue)
$objParaHeader = $objDocument.Paragraphs.Add($objMissingValue)
$objParaHeader.Range.Style = "Heading 1"
$objParaHeader.Range.Text = "The power of Microsoft Windows PowerShell"
$objParaHeader.Range.InsertParagraphAfter()

$objParaText = $objDocument.Paragraphs.Add($objMissingValue)
$objParaText.Range.Text = "I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison."
$objParaText.Range.InsertParagraphAfter()

$filename = 'C:\\Script\\PowerShell-Example.doc'
$objDocument.SaveAs($filename,
$objMissingValue, $objMissingValue,
$objMissingValue, $objMissingValue,
$objMissingValue, $objMissingValue,
$objMissingValue, $objMissingValue,
$objMissingValue, $objMissingValue)

##Once the script has added all of the required content the document should be closed:
$objDocument.Close()
$objWord.Quit()
</div>

</div>

您可能想查找下面的文章:

  • powershell操作word详解

相关文章

  • Windows Powershell 执行外部命令
  • WMI入门教程之WMI中的类在哪里?
  • Windows 8 中的 PowerShell 3.0
  • PowerShell小技巧之True和False的类型转换
  • PowerShell中使用PrintManagement管理打印机示例
  • 探索PowerShell(十五) 引号与转义字符
  • Powershell中定义常量的方法
  • Powershell实现编写和运行脚本
  • PowerShell设置文件只读、隐藏属性的方法
  • PowerShell中正则表达式使用例子

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • PowerShell实现的文件同步脚本分享
    • PowerShell函数参数使用智能提示功能例子
    • PowerShell面向对象编程基础知识总结
    • PowerShell ISE自动化简单示例
    • PowerShell查询和删除打印任务操作代码实例
    • 在cmd中直接运行PowerShell脚本文件的方法
    • PowerShell中终止管道的方法
    • Windows PowerShell是啥?看完本文你就懂它了
    • Powershell ISE的抽象语法树编程示例
    • Powershell改变脚本执行优先权的代码分享

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有