惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
The Last Watchdog
The Last Watchdog
T
Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
D
Docker
V
Vulnerabilities – Threatpost
Attack and Defense Labs
Attack and Defense Labs
Hugging Face - Blog
Hugging Face - Blog
W
WeLiveSecurity
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Cloudflare Blog
博客园_首页
P
Privacy International News Feed
Scott Helme
Scott Helme
N
News and Events Feed by Topic
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
T
Tenable Blog
H
Hacker News: Front Page
N
News and Events Feed by Topic
罗磊的独立博客
Google Online Security Blog
Google Online Security Blog
S
Security @ Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
有赞技术团队
有赞技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
G
GRAHAM CLULEY
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - Candyxiaoqiang

使用 ADO.NET 访问 Oracle 9i 存储过程(转) 使用 ADO.NET 和 Oracle 进行高级数据访问 (转自) HttpRequest, HttpRuntime, AppDomain and friends() 在showModalDialog窗体里,单击服务端Button产生新页面解决方法 - Candyxiaoqiang - 博客园 asp.net按钮 button的onclick事件 与oncommand 事件的区别 汇总 SQL 连接字符串的说明(转) JavaScript相关资料( 收集中.......) - Candyxiaoqiang - 博客园 Visual Studio常用小技巧 觉得不错 转一下 Web开发中用的工具(不断更新) C#实现Web文件上传的两种方法 (转) document,event javascript中常用对象介绍 带中文说明的 (转) ASP.Net实现将Word转换PDF格式 (转自:思绪随风~~~) 用C#实现生成PDF文档和将WORD转换为PDF (转自海东的技术资料) C# 拆分word(根据标题或书签拆分) (转自zrx401558287) 完成类似QQ邮箱中‘HTML方式查看’功能查看Office文件 (转自zellzhang) 利用.net替换Word的内容(从数据库中取数据来替换word里面的书签)(转) 在IIS上启用Gzip压缩(HTTP压缩) (转自子秋的博客) 如何采用Local方式连接到ArcGIS Server(转) VS2005 直接调试网页不能显示
如何:将文档发送到打印机(转)
Candyxiaoqiang · 2009-05-21 · via 博客园 - Candyxiaoqiang

文档出自:http://www.cnblogs.com/hone/archive/2005/12/29/307302.html

可以使用 PrintOut 方法将 Microsoft Office Word 文档(或文档的一部分)发送到打印机。可以从 ApplicationDocument 对象调用 PrintOut()

打印文档

  • 下面的代码用所有默认选项打印活动文档:
    ThisDocument.PrintOut()

PrintOut 方法有多个可选参数,允许您微调打印文档的方式,下表概括了这些参数。

参数 说明
Background 设置为 True 可允许在 Word 打印文档时继续处理。
Append OutputFileName 参数一起使用。设置为 True 可将指定的文档名称追加到由 OutputFileName 参数指定的文件名后。设置为 False 将重写 OutputFileName 的内容。
Range 页面范围。可以为任何 WdPrintOutRange 枚举:wdPrintAllDocumentwdPrintCurrentPagewdPrintFromTowdPrintRangeOfPageswdPrintSelection
OutputFileName 如果 PrintToFile 为 True,此参数指定输出文件的路径和文件名。
From Range 设置为 wdPrintFromTo 时的起始页码。
To Range 设置为 wdPrintFromTo 时的结束页码。
Item 要打印的项。可以是任何 WdPrintOutItem 枚举:wdPrintAutoTextEntrieswdPrintCommentswdPrintDocumentContentwdPrintKeyAssignmentswdPrintPropertieswdPrintStyles
Copies 要打印的份数。
Pages 要打印的页码和页码范围,由逗号分隔。例如,“2, 6-10”意为打印第 2 页和第 6、7、8、9、10 页。
PageType 要打印的页面的类型。可以是任何 WdPrintOutPages 常量:wdPrintAllPageswdPrintEvenPagesOnlywdPrintOddPagesOnly
PrintToFile 设置为 True 可将打印机指令发送到文档。确保使用 OutputFileName 指定一个文件名。
Collate 打印一个文档的多个副本时使用此参数。设置为 True 则在打印下一个副本前将打印此文档的所有页面。
FileName 仅适用于 Application 对象。要打印的文档的路径和文件名。如果不用此参数,Word 将打印活动文档。
ManualDuplexPrint 设置为 True 可在打印机上没有双面打印装置的情况下打印双面文档。

常用的 PrintOut 参数。

打印活动文档的第一页

  • 下面的过程打印活动文档的第一页:
    ' Visual Basic
        Friend Sub PrintOutDoc()
        ThisDocument.PrintOut( _
        Background:=True, _
        Append:=False, _
        Range:=Word.WdPrintOutRange.wdPrintCurrentPage, _
        Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
        Copies:="1", _
        Pages:="1", _
        PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
        PrintToFile:=False, _
        Collate:=True, _
        ManualDuplexPrint:=False)
        End Sub
        // C#
        internal void PrintOutDoc()
        {
        object myTrue = true;
        object myFalse = false;
        object missingValue = Type.Missing;
        object range = Word.WdPrintOutRange.wdPrintCurrentPage;
        object items = Word.WdPrintOutItem.wdPrintDocumentContent;
        object copies = "1";
        object pages = "1";
        object pageType = Word.WdPrintOutPages.wdPrintAllPages;
        ThisDocument.PrintOut(ref myTrue, ref myFalse, ref range,
        ref missingValue, ref missingValue, ref missingValue,
        ref items, ref copies, ref pages, ref pageType, ref myFalse,
        ref myTrue, ref missingValue,  ref myFalse, ref missingValue,
        ref missingValue, ref missingValue, ref missingValue);
        }
        

    如何:在 Word 文档中搜索文本

    Find 对象既是 Selection 的成员,又是 Range 对象的成员,您可以使用这两者中的任意一个来搜索文本。“替换”命令是“查找”命令的扩展。

    使用 Selection 对象查找文本时,指定的所有搜索条件只适用于当前选择的文本。如果 Selection 是插入点,则搜索整个文档。如果找到匹配搜索条件的项,选择将自动更改以突出显示找到的项。

    使用 Selection 对象查找文本

    • 下面的过程搜索字符串“find me”。找到第一个后,它突出显示该词并显示一个消息框。
      ' Visual Basic
              Friend Sub SelectionFind()
              Dim strFind As String = "find me"
              With ThisApplication.Selection.Find
              .ClearFormatting()
              .Text = strFind
              If .Execute = True Then
              MessageBox.Show("Text found.")
              Else
              MessageBox.Show("The text could not be located.")
              End If
              End With
              End Sub
              // C#
              internal void SelectionFind()
              {
              string strFind = "find me";
              Word.Find fnd = ThisApplication.Selection.Find;
              fnd.ClearFormatting();
              fnd.Text = strFind;
              object missingValue = Type.Missing;
              if (fnd.Execute(ref missingValue, ref missingValue,
              ref missingValue, ref missingValue, ref missingValue,
              ref missingValue, ref missingValue, ref missingValue,
              ref missingValue, ref missingValue, ref missingValue,
              ref missingValue, ref missingValue, ref missingValue,
              ref missingValue))
              {
              MessageBox.Show("Text found.");
              }
              else
              {
              MessageBox.Show("The text could not be located.");
              }
              }

    需要注意的是,Find 条件是累积的,这意味着一个条件会与前面的搜索条件累加起来。在搜索前可使用 .ClearFormatting() 方法清除上一次搜索的格式设置。

    使用 Range 对象查找文本可以使您在用户界面不显示任何内容的情况下搜索文本。如果找到匹配搜索条件的文本,Find 方法将返回 True,否则返回 False。如果找到了文本,该方法还会重新定义 Range 对象以匹配搜索条件。

    使用 Range 对象查找文本

    1. 定义一个由文档的第二段组成的 Range 对象。
      ' Visual Basic
              Dim rng As Word.Range = ThisDocument.Paragraphs(2).Range
              // C#
              Word.Range rng = ThisDocument.Paragraphs[2].Range;
    2. 使用 Find 方法,首先清除任何现有的格式设置选项,然后搜索字符串“find me”。
      ' Visual Basic
              With rng.Find
              .ClearFormatting()
              If .Execute(FindText:="find me") Then
              // C#
              Word.Find fnd = rng.Find;
              fnd.ClearFormatting();
              object missingValue = Type.Missing;
              object findStr = "find me";
              if (fnd.Execute(
    3. 在消息框中显示搜索结果,最后选择 Range 以使其可见。
      ' Visual Basic
              MessageBox.Show("Text found.")
              Else
              MessageBox.Show("Text not found.")
              End If
              End With
              rng.Select()
              // C#
              {
              MessageBox.Show("Text found.");
              }
              else
              {
              MessageBox.Show("Text not found.");
              }
              rng.Select();

      如果搜索失败,则第二段被选中;如果搜索成功,则显示搜索条件。

    完整的方法如下所示:

    ' Visual Basic
        Friend Sub RangeFind()
        Dim rng As Word.Range = _
        ThisDocument.Paragraphs(2).Range
        With rng.Find
        .ClearFormatting()
        If .Execute(FindText:="find me") Then
        MessageBox.Show("Text found.")
        Else
        MessageBox.Show("Text not found.")
        End If
        End With
        rng.Select()
        End Sub
        // C#
        internal void RangeFind()
        {
        Word.Range rng = ThisDocument.Paragraphs[2].Range;
        Word.Find fnd = rng.Find;
        fnd.ClearFormatting();
        object missingValue = Type.Missing;
        object findStr = "find me";
        if (fnd.Execute(ref findStr, ref missingValue, ref missingValue,
        ref missingValue, ref missingValue, ref missingValue,
        ref missingValue, ref missingValue, ref missingValue,
        ref missingValue, ref missingValue, ref missingValue,
        ref missingValue, ref missingValue, ref missingValue))
        {
        MessageBox.Show("Text found.");
        }
        else
        {
        MessageBox.Show("Text not found.");
        }
        rng.Select();
        }