【发布时间】:2014-09-08 08:40:58
【问题描述】:
我正在创建一个使用单词自动化的应用程序。我正在使用 Visual Studio 2010、Microsoft Word 2010 并使用互操作。
我的word文档中有以下3种样式。
如您所见,我已经对样式进行了格式化,以便它们在编号时达到自己的水平。 我希望应用程序做的是打开一个带有编号项目符号的现有文档(应用程序可以这样做),然后添加更多(见图)。
到目前为止,我已经尝试过了,但它似乎没有遵循我手动放入样式的格式。
public void insertTextHeading(Word.Document document, string bookmark, string text, int fontSize, string headingType, int listNumber, int bulletLevel)
{
var start = document.Bookmarks[bookmark].Start;
var end = document.Bookmarks[bookmark].End;
Word.Range range = document.Range(start, end);
//The text design
range.Font.Name = "Verdana";
range.Font.Size = fontSize;
range.set_Style(headingType);
object n = listNumber;
Word.ListTemplate template =
document.Application.ListGalleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates.get_Item(ref n);
object bContinuePrevList = true;
object applyTo = Word.WdListApplyTo.wdListApplyToSelection;
object defBehavior = Word.WdDefaultListBehavior.wdWord10ListBehavior;
object missing = System.Reflection.Missing.Value;
range.ListFormat.ApplyListTemplateWithLevel(
template, ref bContinuePrevList,
ref applyTo, ref defBehavior, ref missing);
range.Text = text;
}
【问题讨论】: