在Microsoft Word中编号列表 [英] Numbered List in Microsoft Word

查看:265
本文介绍了在Microsoft Word中编号列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Interop.Microsoft.Office.Interop.Word.dll动态地建立在C#中的Word文档。

I am using Interop.Microsoft.Office.Interop.Word.dll to dynamically build a Word document in C#.

有没有人有一个代码示例创建AA编号列表?

Does anyone have a code example to create a a numbered list?

推荐答案

试试这个...它假定你有一个Word10引用(也可以使用其他版本的,你'将不得不改变常量)。不要忘了使用的Microsoft.Office.Interop.Word;

Try this... it assumes you have a reference to Word10 (you can use other versions, you'll have to change the constants). Don't forget the using Microsoft.Office.Interop.Word;

// setup
object missing = System.Reflection.Missing.Value;
ApplicationClass app = new ApplicationClass();
Document doc = app.Documents.Add(ref missing, ref missing, 
    ref missing, ref missing);
app.Visible = true;

// whatever is selected will be turned into a numbered list.
object n = 1;
ListTemplate template = 
    app.ListGalleries[WdListGalleryType.wdNumberGallery].ListTemplates.get_Item(ref n);
ListLevel level = template.ListLevels[1];
level.NumberFormat = "%1.";
level.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
level.NumberStyle = WdListNumberStyle.wdListNumberStyleArabic;
level.NumberPosition = app.InchesToPoints(0.25f);
level.Alignment = WdListLevelAlignment.wdListLevelAlignLeft;
level.TextPosition = app.InchesToPoints(0.5f);
level.TabPosition = (float)WdConstants.wdUndefined;
level.ResetOnHigher = 0;
level.StartAt = 1;

level.Font.Bold = (int)WdConstants.wdUndefined;
level.Font.Italic = (int)WdConstants.wdUndefined;
level.Font.StrikeThrough = (int)WdConstants.wdUndefined;
level.Font.Subscript = (int)WdConstants.wdUndefined;
level.Font.Superscript = (int)WdConstants.wdUndefined;
level.Font.Shadow = (int)WdConstants.wdUndefined;
level.Font.Outline = (int)WdConstants.wdUndefined;
level.Font.Emboss = (int)WdConstants.wdUndefined;
level.Font.Engrave = (int)WdConstants.wdUndefined;
level.Font.AllCaps = (int)WdConstants.wdUndefined;
level.Font.Hidden = (int)WdConstants.wdUndefined;
level.Font.Underline = WdUnderline.wdUnderlineNone;
level.Font.Color = WdColor.wdColorAutomatic;
level.Font.Size = (int)WdConstants.wdUndefined;
level.Font.Animation = WdAnimation.wdAnimationNone;
level.Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;

level.LinkedStyle = "";

template.Name = "";
object bContinuePrevList = false;
object applyTo = WdListApplyTo.wdListApplyToWholeList;
object defBehavior = WdDefaultListBehavior.wdWord10ListBehavior;

app.Selection.Range.ListFormat.ApplyListTemplateWithLevel(
    template, ref bContinuePrevList, 
    ref applyTo, ref defBehavior, ref missing);



编辑:格式化

edit: formatting.

这篇关于在Microsoft Word中编号列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆