سؤال

أنا باستخدام التعليمات البرمجية التالية لإدراج جدول مع 2 خلايا في مس ورد باستخدام دلفي ز5.كل الخط لخلايا الجدول هي جميلة على التوالي إلى الأمام.باستثناء 1 كلمة.أحتاج أن تكون هذه الكلمة جريئة بينما الباقي ليس كذلك.

الرجاء مساعدتي في ضبط رمز بلدي حتى أتمكن من جعل 1 كلمة جريئة.

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 will not be bold text');
 wrdDoc.Tables.Item(3).Cell(1,2).Range.InsertAfter('this will not be bold text');
 wrdDoc.Tables.Item(3).Cell(1,2).Range.InsertAfter('THIS TEXT MUST BE 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;

كما ترى في الجزء الأخير من الكود ، هناك 3 مكالمات لـ InsertAfter(), ، الجمل التي أدخلها طويلة جدا.ودلفي يحدني إلى 255 لذلك أنا فقط ندعو لهم أكثر من مرة وانها مجرد جيدة كما يطلق عليه مرة واحدة.

فقط المكالمة الأخيرة ، يجب أن تكون جريئة.يجب أن يبقى الباقي فقط التنسيق المحدد أعلاه.

أي وجميع المساعدة سيكون موضع تقدير.يعطيكم الصّحة

هل كانت مفيدة؟

المحلول

لقد تمكنت من إيجاد طريقة.إنه فوضوي بعض الشيء ولكنه يقوم بالمهمة.

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 the search }
     WrdApp.Selection.Find.Execute();
  WrdApp.Selection.Font.Bold:=True;
End;

ثم أنا فقط اتصل MakeBold('THIS TEXT MUST BE BOLD'); وأنه لا يحل المشكلة.

لا تزال أي إجابات محتملة أخرى موضع ترحيب ، لأن هذه الطريقة قد تجعل النص الآخر غير ذي الصلة غامقا أيضا.

نصائح أخرى

كنت تعمل بعيدا من الصعب جدا.:- ) تحتاج إلى أن تصبح أكثر دراية نطاقات كلمة (واستخدام المتغيرات المؤقتة).تم اختباره باستخدام وحدة ورد 2010 في دلفي 10 سياتل ، باستخدام ورد 2013.

var
  WordTbl: Table;

// Grab a local reference to the table for ease of use
Tbl := wrdDoc.Selection.Tables.Item(3);
Tbl.Cell(1, 2).Range.Text := 'not bold';

// Make sure the cell is the current selection
Tbl.Cell(1, 2).Select;

// Move the selection to the end of the text we wrote before
wrdDoc.Selection.EndKey(wdLine, wdMove);

// Add the next section of the text and move to the end, so we
// know for sure where Word thinks we are now. Notice the spaces
// at both ends - for some reason they make a difference
wrdDoc.Selection.Range.Text := ' BOLD TEXT ';
wrdDoc.Selection.EndKey(wdLine, wdMove);

// Move back two words to select the text we just added and bold
wrdDoc.Selection.MoveLeft(wdWord, 2, wdExtend);
wrdDoc.Selection.Font.Bold := 1;

// End of the line again, and turn bold off, then more text
wrdDoc.Selection.EndKey(wdLine, wdMove);
wrdDoc.Selection.Font.Bold := 0;
wrdDoc.Selection.Range.Text := 'not bold again';

هذا الحل يجعل جميع المباريات في أكتيفيدوكومنت جريئة

function TfmMain.MakeBold(SearchStr: String; App: OLEVariant {Word application var} ): Integer;
var
  Find: OLEVariant;
begin
  Find := App.Selection.Find;
  Find.ClearFormatting;
  Find.Forward := true;
  Find.Wrap := wdFindStop;
  Find.Format := false;
  Find.MatchCase := false;
  Find.MatchWholeWord := true;
  Find.MatchWildcards := false;
  Find.MatchSoundsLike := false;
  Find.MatchAllWordForms := false;

  Find.Text := SearchStr;
  while Find.Execute() do
  begin
    App.Selection.Font.Bold := true;
    App.Selection.Collapse(wdCollapseEnd);
  end;
  Find := UnAssigned;
end;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top