翻譯|使用教程|編輯:胡濤|2022-08-23 15:06:27.750|閱讀 217 次
概述:本文將給您介紹在spire.doc下如何在 Word 中將文本大小寫更改為全部大寫,希望能對您有所幫助!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。下面將給您介紹在spire.doc下如何在 Word 中將文本大小寫更改為全部大寫,希望能對您有所幫助!
大寫字母非常適合強調 Word 中的文本。用大寫字母寫的段落很容易注意到,大寫字母暗示了段落的重要性。本文教您使用Spire.Doc for .NET通過編程將現有文本的大小寫更改為全部大寫的方法。
首先,您需要將 Spire.Doc for.NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。
PM> Install-Package Spire.Doc
詳細步驟如下:
注:AllCaps 表示將所有字母大寫并設置為相同大小,IsSmallCaps 表示將所有字母大寫但將原始大寫設置為大于小寫。
【C#】
using System; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace changecase { class Program { static void Main(string[] args) { //Create a new document and load from file string input = @"D:\testp\test.docx"; ; Document doc = new Document(); doc.LoadFromFile(input); TextRange textRange; //Get the second paragraph and set its characters to AllCaps Paragraph para1 = doc.Sections[0].Paragraphs[2]; foreach (DocumentObject obj in para1.ChildObjects) { if (obj is TextRange) { textRange = obj as TextRange; textRange.CharacterFormat.AllCaps = true; } } //Get the third paragraph and set its characters to IsSmallCaps Paragraph para2 = doc.Sections[0].Paragraphs[3]; foreach (DocumentObject obj in para2.ChildObjects) { if (obj is TextRange) { textRange = obj as TextRange; textRange.CharacterFormat.IsSmallCaps = true; } } //Save the document to a new Word file string output = "ChangeCase.docx"; doc.SaveToFile(output, FileFormat.Docx2013); } } }
【VB.NET】
Imports System Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Module Program Sub Main(args As String()) ' Create a new document and load from file Dim input As String = "D:\testp\test.docx" Dim doc As New Document() doc.LoadFromFile(input) Dim textRange As TextRange 'Get the second paragraph and set its character to AllCaps Dim para1 As Paragraph = doc.Sections(0).Paragraphs(2) For Each obj As DocumentObject In para1.ChildObjects If TypeOf obj Is TextRange Then textRange = TryCast(obj, TextRange) textRange.CharacterFormat.AllCaps = True End If Next obj 'Get the third paragraph and set its character to IsSmallCaps Dim para2 As Paragraph = doc.Sections(0).Paragraphs(3) For Each obj As DocumentObject In para2.ChildObjects If TypeOf obj Is TextRange Then textRange = TryCast(obj, TextRange) textRange.CharacterFormat.IsSmallCaps = True End If Next obj 'Save the document to a new Word file Dim output As String = "ChangeCase.docx" doc.SaveToFile(output, FileFormat.Docx2013) End Sub End Module
以上便是在spire.doc中如何在 Word 中將文本大小寫更改為全部大寫,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn