delphi - How to make certain text bold in MS Word -
i using following code insert table 2 cells in ms word using delphi xe5. font table's cells pretty straight forward. except 1 word. need word bold while rest not.
please me adjust code can make 1 word bold.
wrddoc.tables.add(wrdselection.range,3,2); wrddoc.tables.item(3).rows.alignment := wdalignrowleft; wrddoc.tables.item(3).columns.item(1).setwidth(36,wdadjustnone); wrddoc.tables.item(3).columns.item(2).setwidth(379,wdadjustnone); wrddoc.tables.item(3).borders.item(wdborderleft).linestyle := wdlinestylenone; wrddoc.tables.item(3).borders.item(wdborderright).linestyle := wdlinestylenone; wrddoc.tables.item(3).borders.item(wdbordervertical).linestyle := wdlinestylenone; wrddoc.tables.item(3).borders.item(wdbordertop).linestyle := wdlinestylenone; wrddoc.tables.item(3).borders.item(wdborderbottom).linestyle := wdlinestylenone; wrddoc.tables.item(3).borders.item(wdborderhorizontal).linestyle := wdlinestylenone; wrddoc.tables.item(3).cell(1,1).range.insertafter('8.1'); wrddoc.tables.item(3).cell(1,1).range.paragraphs.alignment := wdalignparagraphleft; wrddoc.tables.item(3).cell(1,1).range.font.size := 12; wrddoc.tables.item(3).cell(1,1).range.font.bold := false; wrddoc.tables.item(3).cell(1,1).range.font.underline := false; wrddoc.tables.item(3).cell(1,2).range.insertafter('this not bold text'); wrddoc.tables.item(3).cell(1,2).range.insertafter('this not bold text'); wrddoc.tables.item(3).cell(1,2).range.insertafter('this text must bold'); wrddoc.tables.item(3).cell(1,2).range.paragraphs.alignment := wdalignparagraphjustify; wrddoc.tables.item(3).cell(1,2).range.font.size := 12; wrddoc.tables.item(3).cell(1,2).range.font.bold := false; wrddoc.tables.item(3).cell(1,2).range.font.underline := false;
as can see in last part of code, there 3 calls insertafter()
, sentences inserting long. , delphi limits me 255 call them more once , calling once.
only last call, must bold. rest should stay format defined above.
any , appreciated. thank you
i did manage find way. bit messy job.
procedure makebold(searchstr:string); begin wrdapp.selection.find.clearformatting; wrdapp.selection.find.text := searchstr; wrdapp.selection.find.forward := true; wrdapp.selection.find.wrap := wdfindcontinue; wrdapp.selection.find.format := false; wrdapp.selection.find.matchcase := true; wrdapp.selection.find.matchwholeword := wrfmatchcase in flags; wrdapp.selection.find.matchwildcards :=wrfmatchwildcards in flags; wrdapp.selection.find.matchsoundslike := false; wrdapp.selection.find.matchallwordforms := false; { perform search } wrdapp.selection.find.execute(); wrdapp.selection.font.bold:=true; end;
then call makebold('this text must bold');
, solves problem.
any other possible answers still welcome, because method may make other unrelated text bold.
Comments
Post a Comment