国产Word .NET库组件Spire.Doc系列教程(54):将ASCII字符设置为Word中的项目符号点

翻译|使用教程|编辑:李显亮|2021-04-19 11:40:01.467|阅读 33 次

概述:本文向您展示如何使用带有C#和VB.NET的Spire.Doc在Word文档中将ASCII字符(特殊符号)设置为项目符号。

# 31款JAVA开发必备控件和工具 # 企业数字化建设合规无风险[专题]

相关链接:

Spire.Doc for .NET是一个专业的Word .NET库,设计用于帮助开发人员高效地开发创建、阅读、编写、转换和打印任何来自.NET( C#, VB.NET, ASP.NET)平台的Word文档文件的功能。

本文向您展示如何使用带有C#和VB.NET的Spire.Doc在Word文档中将ASCII字符(特殊符号)设置为项目符号。

点击下载Spire.Doc for .NET最新版

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看折扣价!想要获取更多福利的朋友可以咨询在线客服哦~

C#

using Spire.Doc;
using Spire.Doc.Documents;

namespace SetBulletCharacter
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document object and add a section
            Document doc = new Document();
            Section section = doc.AddSection();

            //Create four list styles based on different ASCII characters
            ListStyle listStyle1 = new ListStyle(doc, ListType.Bulleted);
            listStyle1.Name = "liststyle";
            listStyle1.Levels[0].BulletCharacter = "\x006e";
            listStyle1.Levels[0].CharacterFormat.FontName = "Wingdings";
            doc.ListStyles.Add(listStyle1);
            ListStyle listStyle2 = new ListStyle(doc, ListType.Bulleted);
            listStyle2.Name = "liststyle2";
            listStyle2.Levels[0].BulletCharacter = "\x0075";
            listStyle2.Levels[0].CharacterFormat.FontName = "Wingdings";
            doc.ListStyles.Add(listStyle2);
            ListStyle listStyle3 = new ListStyle(doc, ListType.Bulleted);
            listStyle3.Name = "liststyle3";
            listStyle3.Levels[0].BulletCharacter = "\x00b2";
            listStyle3.Levels[0].CharacterFormat.FontName = "Wingdings";
            doc.ListStyles.Add(listStyle3);
            ListStyle listStyle4 = new ListStyle(doc, ListType.Bulleted);
            listStyle4.Name = "liststyle4";
            listStyle4.Levels[0].BulletCharacter = "\x00d8";
            listStyle4.Levels[0].CharacterFormat.FontName = "Wingdings";
            doc.ListStyles.Add(listStyle4);

            //Add four paragraphs and apply list style separately
            Paragraph p1 = section.Body.AddParagraph();
            p1.AppendText("Spire.Doc for .NET");
            p1.ListFormat.ApplyStyle(listStyle1.Name);
            Paragraph p2 = section.Body.AddParagraph();
            p2.AppendText("Spire.PDF for .NET");
            p2.ListFormat.ApplyStyle(listStyle2.Name);
            Paragraph p3 = section.Body.AddParagraph();
            p3.AppendText("Spire.XLS for .NET");
            p3.ListFormat.ApplyStyle(listStyle3.Name);
            Paragraph p4 = section.Body.AddParagraph();
            p4.AppendText("Spire.Presentation for .NET");
            p4.ListFormat.ApplyStyle(listStyle4.Name);

            //Save to file
            doc.SaveToFile("output.docx", FileFormat.Docx2013);
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace SetBulletCharacter
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a Document object and add a section
            Document doc = New Document()
            Dim section As Section = doc.AddSection()
 
            'Create four list styles based on different ASCII characters
            Dim listStyle1 As ListStyle = New ListStyle(doc, ListType.Bulleted)
            listStyle1.Name = "liststyle"
            listStyle1.Levels(0).BulletCharacter = "\x006e"
            listStyle1.Levels(0).CharacterFormat.FontName = "Wingdings"
            doc.ListStyles.Add(listStyle1)
            Dim listStyle2 As ListStyle =  New ListStyle(doc, ListType.Bulleted)
            listStyle2.Name = "liststyle2"
            listStyle2.Levels(0).BulletCharacter = "\x0075"
            listStyle2.Levels(0).CharacterFormat.FontName = "Wingdings"
            doc.ListStyles.Add(listStyle2)
            Dim listStyle3 As ListStyle =  New ListStyle(doc, ListType.Bulleted)
            listStyle3.Name = "liststyle3"
            listStyle3.Levels(0).BulletCharacter = "\x00b2"
            listStyle3.Levels(0).CharacterFormat.FontName = "Wingdings"
            doc.ListStyles.Add(listStyle3)
            Dim listStyle4 As ListStyle =  New ListStyle(doc, ListType.Bulleted)
            listStyle4.Name = "liststyle4"
            listStyle4.Levels(0).BulletCharacter = "\x00d8"
            listStyle4.Levels(0).CharacterFormat.FontName = "Wingdings"
            doc.ListStyles.Add(listStyle4)
 
            'Add four paragraphs and apply list style separately
            Dim p1 As Paragraph = section.Body.AddParagraph()
            p1.AppendText("Spire.Doc for .NET")
            p1.ListFormat.ApplyStyle(listStyle1.Name)
            Dim p2 As Paragraph =  section.Body.AddParagraph()
            p2.AppendText("Spire.PDF for .NET")
            p2.ListFormat.ApplyStyle(listStyle2.Name)
            Dim p3 As Paragraph =  section.Body.AddParagraph()
            p3.AppendText("Spire.XLS for .NET")
            p3.ListFormat.ApplyStyle(listStyle3.Name)
            Dim p4 As Paragraph =  section.Body.AddParagraph()
            p4.AppendText("Spire.Presentation for .NET")
            p4.ListFormat.ApplyStyle(listStyle4.Name)
 
            'Save to file
            doc.SaveToFile("output.docx", FileFormat.Docx2013)
        End Sub
    End Class
End Namespace

效果图:

Word .NET库组件Spire.Doc系列教程(53):以编程方式将 XML 转为 Word


慧都是E-iceblue官方友好合作伙伴,如果您对spire.Doc感兴趣,可以联系在线客服了解具体授权价格和使用机制。

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至hey@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
在线咨询
联系我们
TOP
在线客服系统
live chat