Interop.Microsoft.Office.Interop.Word.dll을 사용하여 C#에서 Word 문서를 동적으로 작성합니다.Microsoft Word의 번호 매기기 목록
누구나 번호가 매겨진 목록을 만드는 코드 예제가 있습니까?
Interop.Microsoft.Office.Interop.Word.dll을 사용하여 C#에서 Word 문서를 동적으로 작성합니다.Microsoft Word의 번호 매기기 목록
누구나 번호가 매겨진 목록을 만드는 코드 예제가 있습니까?
시도하십시오 ... Word10에 대한 참조가 있다고 가정합니다 (다른 버전을 사용할 수 있으므로 상수를 변경해야합니다). 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);
편집 : 형식을 잊지 마세요.
나는 이것이 오래된 질문 인 것을 압니다. Interop.Word를 사용하여 목록 번호 매기기를 다시 시작합니다. Office 2003에 대한이 코드를 부분적으로 어떻게 적용 할 수 있는지 알고 있습니까? (http://stackoverflow.com/q/11674952/869912) –
안녕하세요 짐이 질문을 확인하면 http://stackoverflow.com/questions/23380676/format-numbered-list-with-styles와 하나의 답변을 찾을 수 있습니까? –
필자에게는 예제가 없지만 이런 종류의 것을 찾기가 정말 쉬운 방법은 매크로를 기록한 다음 기록 된 매크로의 코드를 보는 것입니다. 일반적으로 당신이 필요로하지 않는 많은 불필요한 것들이 있지만, 그것의 고기는 일반적으로 꽤 분명하고 올바른 방향으로 당신을 가리 킵니다 ... –