Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft Word中的编号列表_C#_Ms Word - Fatal编程技术网

C# Microsoft Word中的编号列表

C# Microsoft Word中的编号列表,c#,ms-word,C#,Ms Word,我正在使用Interop.Microsoft.Office.Interop.Word.dll在C#中动态构建Word文档 有人有创建编号列表的代码示例吗?试试这个。。。它假设您引用了Word10(您可以使用其他版本,您必须更改常量)。不要忘记使用Microsoft.Office.Interop.Word时的 // setup object missing = System.Reflection.Missing.Value; ApplicationClass app = new Applicati

我正在使用Interop.Microsoft.Office.Interop.Word.dll在C#中动态构建Word文档


有人有创建编号列表的代码示例吗?

试试这个。。。它假设您引用了Word10(您可以使用其他版本,您必须更改常量)。不要忘记使用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);

编辑:格式化。

我手头没有一个例子,但找到这类东西的一个非常简单的方法是录制一个宏,然后查看录制的宏的代码。通常有很多无关的东西你不需要,但它的实质通常是非常明显的,并指出你在正确的方向。。。