`

delphi 为word文档增加一个段落样式--转

阅读更多

下为程序中的一段,解决了为文档增加一个段落样式。这个段落样式的基础样式为“标题2”,标题字体、字号重设了,关键是设了自动编号的功能。
procedure TForm1.titlestyle(wordapp: variant);
begin
try
// wordapp.ActiveDocument.Styles.item('自定标题').Delete;
except
end;

wordapp.ActiveDocument.Styles.Add(Name := '自定标题', type := wdStyleTypeParagraph);
wordapp.ActiveDocument.Styles.item('自定标题').AutomaticallyUpdate := False;

wordapp.ActiveDocument.Styles.item('自定标题').AutomaticallyUpdate := False;
wordapp.ActiveDocument.Styles.item('自定标题').BaseStyle := '标题 2 ';


wordapp.ActiveDocument.Styles.item('自定标题').Font.NameFarEast := ' + 中文标题';
wordapp.ActiveDocument.Styles.item('自定标题').Font.NameAscii := ' + 西文标题';
// wordapp.ActiveDocument.Styles.item('自定标题').Font.NameOther := ' + 西文标题';
wordapp.ActiveDocument.Styles.item('自定标题').Font.Name := ' + 西文标题';
wordapp.ActiveDocument.Styles.item('自定标题').Font.Size := 10.5;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Bold := True;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Italic := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Underline := wdUnderlineNone;
wordapp.ActiveDocument.Styles.item('自定标题').Font.UnderlineColor := wdColorAutomatic;
wordapp.ActiveDocument.Styles.item('自定标题').Font.StrikeThrough := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.DoubleStrikeThrough := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Outline := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Emboss := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Shadow := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Hidden := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.SmallCaps := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.AllCaps := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Color := wdColorAutomatic;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Engrave := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Superscript := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Subscript := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Scaling := 100;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Kerning := 0;
wordapp.ActiveDocument.Styles.item('自定标题').Font.Animation := wdAnimationNone;
wordapp.ActiveDocument.Styles.item('自定标题').Font.DisableCharacterSpaceGrid := False;
wordapp.ActiveDocument.Styles.item('自定标题').Font.EmphasisMark := wdEmphasisMarkNone;


wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.LeftIndent := CentimetersToPoints(0.74);
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.RightIndent := CentimetersToPoints(0);
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.SpaceBefore := 6;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.SpaceBeforeAuto := False;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.SpaceAfter := 6;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.SpaceAfterAuto := False;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.LineSpacingRule := wdLineSpace1pt5;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.Alignment := wdAlignParagraphLeft;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.WidowControl := True;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.KeepWithNext := True;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.KeepTogether := True;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.PageBreakBefore := False;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.NoLineNumber := False;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.Hyphenation := True;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.FirstLineIndent := CentimetersToPoints(-0.74);
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.OutlineLevel := wdOutlineLevel1;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.CharacterUnitLeftIndent := 0;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.CharacterUnitRightIndent := 0;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.CharacterUnitFirstLineIndent := 0;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.LineUnitBefore := 0;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.LineUnitAfter := 0;
wordapp.ActiveDocument.Styles.item('自定标题').ParagraphFormat.BaseLineAlignment := wdBaselineAlignAuto;

wordapp.ActiveDocument.Styles.item('自定标题').NoSpaceBetweenParagraphsOfSameStyle := False;

wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).NumberFormat := '%1.';
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).TrailingCharacter := wdTrailingTab;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).NumberStyle := wdListNumberStyleArabic;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).NumberPosition := CentimetersToPoints(0);
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Alignment := wdListLevelAlignLeft;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).TextPosition := CentimetersToPoints(0.74);
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).TabPosition := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).ResetOnHigher := 0;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).StartAt := 1;

wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Bold := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Italic := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.StrikeThrough := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Subscript := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Superscript := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Shadow := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Outline := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Emboss := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Engrave := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.AllCaps := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Hidden := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Underline := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Color := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Size := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Animation := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.DoubleStrikeThrough := wdUndefined;
wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1).ListLevels.item(1).Font.Name := '';

// wordapp.ListGalleries.item(wdNumberGallery).LinkedStyle := '自定标题';

wordapp.ActiveDocument.Styles.item('自定标题').LinkToListTemplate(ListTemplate := wordapp.ListGalleries.item(wdNumberGallery).ListTemplates.item(1), ListLevelNumber := 1);
end;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics