תיעוד HotXLS

TCondFormat / TCondFormatRule

יחידה: lxCondFormat

משפחת עיצובי התנאי של BIFF8 (.xls) התומכת בכללי הרחבה של Excel 2007+. TXLSWorksheet שומרת אוסף של רשומות TCondFormat; כל רשומה מכסה טווח תאים אחד או יותר ומכילה רשימה מסודרת של אובייקטי TCondFormatRule, כאשר כל כלל הוא או כלל ערך-תא מדור קודם או כלל CF12 מסוג Data Bar / Color Scale / Icon Set. ארבעת נקודות הכניסה Sheet.AddCondFormat* (DataBar, ColorScale2, ColorScale3, IconSet) בונות כללים מהתת-סוג הנכון. זמין מאז v2.34.0

ספירת סוג סף

type
  TXLSCfValueKind = (
    cfvNumber      = 0,
    cfvMinOfRange  = 1,
    cfvMaxOfRange  = 2,
    cfvPercent     = 3,
    cfvPercentile  = 4,
    cfvFormula     = 5,
    cfvAutoMin     = 6,  // Excel 2010+ data-bar only
    cfvAutoMax     = 7); // Excel 2010+ data-bar only

ספירת משפחת קבוצת-אייקונים

type
  TXLSIconSetType = (
    icsArrows3, icsArrows3Gray, icsFlags3,
    icsTrafficLights3, icsTrafficLightsRimmed3, icsSigns3,
    icsSymbols3, icsSymbolsUncircled3,
    icsArrows4, icsArrows4Gray, icsRedToBlack4,
    icsRatings4, icsTrafficLights4,
    icsArrows5, icsArrows5Gray,
    icsRatings5, icsQuarters5);

17 משפחות הסמלים הבסיסיות של Excel 2007. מספר העצירות (3, 4 או 5) מקודד בשם ה-enum

ערך סף (cfvo)

type
  TXLSCfValue = class
    constructor Create(AKind: TXLSCfValueKind;
      const AValue: WideString; AColor: LongWord);
    procedure SetThemeColor(ThemeId: Word; Tint: Single); // v2.43.0+
    procedure ClearThemeColor;                            // v2.43.0+
    property Kind: TXLSCfValueKind;
    property Value: WideString;       // numeric literal or formula text
    property Color: LongWord;         // BGR RGB for ColorScale stops
    property IsThemeColor: Boolean;    // v2.43.0+ true = theme mode active
    property ThemeColorId: Word;       // v2.43.0+ theme palette index
    property ThemeColorTint: Single;   // v2.43.0+ -1.0 .. 0.0 .. +1.0
  end;

מטען של שורת נתונים

type
  TXLSDataBarSpec = class
    procedure SetThemeColor(ThemeId: Word; Tint: Single); // v2.43.0+ — opt bar fill into theme mode
    procedure ClearThemeColor;                            // v2.43.0+ — revert to RGB Color
    property Min: TXLSCfValue;
    property Max: TXLSCfValue;
    property Color: LongWord;         // bar fill
    property ShowValue: Boolean;      // false = hide cell text
    property MinLength: Byte;         // 0..100 percent
    property MaxLength: Byte;         // 0..100 percent
    property IsThemeColor: Boolean;    // v2.43.0+ true = theme mode active
    property ThemeColorId: Word;       // v2.43.0+ theme palette index
    property ThemeColorTint: Single;   // v2.43.0+ -1.0 .. 0.0 .. +1.0
  end;

סבב round-trip של צבעי theme ב-XLSX (v2.43.0+)

צבע המילוי של הסרגל בכלל Data Bar והצבעים לכל תחנה בכלל Color Scale ניתנים להגדרה מול אינדקס theme של חוברת העבודה בתוספת ערך tint דרך SetThemeColor(ThemeId, Tint) במקום RGB קבוע. כותב ה-XLSX פולט <color theme="N"/> כאשר Tint הוא בדיוק 0.0 או <color theme="N" tint="0.5"/> כאשר הוא שונה מאפס, בהתאם לפלט "הצורה הקצרה ביותר" של Excel. הקורא מנתח את שתי צירופי המאפיינים ונופל לנתיב rgb= כאשר לא מופיעים theme ולא tint. שני המצבים בלעדיים זה לזה לכל חריץ; מה שנקרא ב-Set אחרון מנצח. IsThemeColor משקף את המצב הפעיל לצורך בדיקה

CF12 של BIFF8 מאחסן רק את צבע ה-RGB שנפתר — מצב theme עובר round-trip בגב ה-XLSX בלבד במהדורה זו. לכללי iconSet אין רכיבי <color>, ולכן התוספת למצב theme לא משפיעה עליהם

מטען של סולם צבעים

type
  TXLSColorScaleSpec = class
    constructor Create(IsThreeStop: Boolean);
    procedure SetStop(I: Integer; Kind: TXLSCfValueKind;
      const Value: WideString; Color: LongWord);
    property StopCount: Integer;      // 2 or 3
    property Stops[I: Integer]: TXLSCfValue; default;
  end;

מטען של קבוצת אייקונים

type
  TXLSIconSetSpec = class
    constructor Create(ASetType: TXLSIconSetType);
    procedure SetThreshold(I: Integer; Kind: TXLSCfValueKind;
      const Value: WideString);
    // Per-stop icon override (v2.44.0+).
    procedure SetIconOverride(I: Integer;
      OverrideSet: TXLSIconSetType; IconId: Byte);
    procedure ClearIconOverride(I: Integer);
    property SetType: TXLSIconSetType;
    property Reverse: Boolean;        // reverse the icon order
    property ShowOnly: Boolean;       // true = icon only, hide cell text
    property IconCount: Integer;      // 3, 4 or 5 (derived from SetType)
    property Thresholds[I: Integer]: TXLSCfValue;
    property HasIconOverride[I: Integer]: Boolean;        // v2.44.0+
    property IconOverrideSet[I: Integer]: TXLSIconSetType; // v2.44.0+
    property IconOverrideId[I: Integer]: Byte;             // v2.44.0+
  end;

עקיפת סמל לכל תחנה (v2.44.0+)

כל תחנה בכלל Icon Set יכולה לעקוף את הסמל המוצג שלה באמצעות כל סמל מתוך אחת מ-17 משפחות הסמלים המובנות, המזוהה על ידי זוג (OverrideSet, IconId). XLSX פולט <cfIcon iconSet="..." iconId="N"/> עבור כל תחנה שעוקפת. CF12 של BIFF8 ממשיך להציג את סמל ברירת המחדל של המשפחה, כי לפורמט ה-wire של BIFF8 אין חריץ לעקיפה לכל תחנה — זו יכולת של XLSX בלבד במהדורה הנוכחית. HasIconOverride[i] מחזיר True רק עבור תחנות שסומנו במפורש דרך SetIconOverride; תחנות הסמל ברירת מחדל ממשיכות להשתמש בברירת המחדל של מיקום התחנה במשפחה

כלל

type
  TCondFormatRule = class
    property Kind: TXLSCfKind;
    property cfType: Word;            // CF-record subtype
    property Operator_: Word;         // comparison operator for cellIs
    property DataBar: TXLSDataBarSpec;       // non-nil for Data Bar rules
    property ColorScale: TXLSColorScaleSpec; // non-nil for Color Scale rules
    property IconSet: TXLSIconSetSpec;       // non-nil for Icon Set rules
    property Style: TXLSDxfStyle;        // DXF override; lazy-created (v2.35.0+)
    property DxfBlob: TXLSBlob;       // raw DXF bytes from Parse (v2.35.0+)
    property Priority: Word;          // CF12 ipriority; 0 = writer assigns (v2.45.0+)
  end;

רק אחד מבין DataBar / ColorScale / IconSet אינו nil לכל כלל CF12, בהתאם ל-Kind של הכלל. כללי cellIs מדור קודם (שאינם CF12) משאירים את שלושתם כ-nil ומשתמשים ב-Operator_ יחד עם Formula1 / Formula2

המאפיין Style (מ- v2.35.0+) נוצר בעצלתיים בקריאה הראשונה; האובייקט המוחזר בבעלות הכלל ומשתחרר בבנאי ההשמדה שלו. קבעו HasXxx דרך הקריאה המתאימה SetXxx על Style. הקורא של BIFF8 שומר את הבתים הגולמיים ב-DxfBlob בנוסף לפענוח שלהם ל-Style (מ- v2.35.1+), כך שסבב טעינה-עריכה-שמירה משקף כל שינוי ב-Style לאחר הטעינה; אם המשתמש לא נוגע בו, הקובץ השמור נושא את אותן עקיפות כמו המקור

ב-CF12 של BIFF8, כללי Data Bar, Color Scale ו-Icon Set דורשים שבלוק ה-DXF המוטמע יהיה ריק. החל מ-v2.87.4, HotXLS מציית לכך: עקיפות סגנון שהוקצו דרך Rule.Style אינן מסודרות עבור שלושת סוגי CF12 האלה בעת שמירת קבצי .xls. תצורת הכלל עצמה של Data Bar / Color Scale / Icon Set עדיין נשמרת דרך הזנב הספציפי לסוג CF12. פלט עיצוב התנאי של XLSX לא מושפע

מיכל

type
  TCondFormat = class
    procedure ClearRow(row: Integer);
    procedure ClearCol(col: Integer);
    procedure ClearRange(row1, col1, row2, col2: Integer);
    procedure MoveRanges(row1, col1, row2, col2,
      drow, dcol: Integer);
    function  RuleCount: Integer;                // v2.40.0+
    function  Rule(I: Integer): TCondFormatRule;  // v2.40.0+
    property Range[i: Integer]: TCondRange; default;
    property IsEmpty: Boolean;
    property IsExt12: Boolean;       // true = emits CONDFMT12/CF12
    property IsShadowed: Boolean;    // v2.37.0+ — duplicate CONDFMT marker
    property TotalRange: TCondRange; // v2.37.0+ — merged-extent range
  end;

Cross-גרסה shadow detection (v2.37.0+)

קבצים שנשמרו ב-Excel נושאים לעיתים קרובות גם CONDFMT של Excel 2003 על ערך התא וגם CONDFMT12 של Excel 2007+ המכסים את אותו sqref — רשומת ערך התא היא fallback בין-גרסאות שה-Excel הישן עדיין יכול לצייר. הקורא מסמן את הרשומה הישנה באמצעות IsShadowed = True לאחר זיהוי התאמה מדויקת של תיבת הגבול ב-TotalRange, כך שקוד הפונה למשתמש ומאתר את אוסף עיצובי התנאי יכול לדלג על הכפילות. הכותב ממשיך לפלוט את שתי משפחות הרשומות בשמירה לתאימות Excel 2003 ↔ Excel 2007+

פורמט תיל

ב-SaveAs(xlExcel97) של BIFF8, כללי CF12 פולטים CONDFMT12 ($0879) ו-CF12 ($087A) לצד CONDFMT ($01B0) ו-CF ($01B1) מדור קודם לצורך תאימות בין-גרסאות עם Excel 2003. הקורא מזהה את הרשומות המודרניות וחושף אותן דרך אותו מודל כללים בזיכרון, כך שקבצי .xls שנוצרו ב-Excel עם כללי הרחבה עוברים round-trip בלי אובדן נתונים

דוגמה

// Data bar with custom min/max thresholds.
with Sheet.AddCondFormatDataBar('A1:A10', $00FF0000,
  cfvNumber, '0', cfvNumber, '100').DataBar do
begin
  ShowValue := True;
  MinLength := 10;
  MaxLength := 90;
end;

// 3 Arrows icon set, reversed so green points down.
with Sheet.AddCondFormatIconSet('B1:B10', icsArrows3).IconSet do
begin
  Reverse  := True;
  ShowOnly := False;
end;

ראה גם

TXLSWorksheet.AddCondFormatDataBar
TXLSWorksheet.AddCondFormatColorScale2
TXLSWorksheet.AddCondFormatColorScale3
TXLSWorksheet.AddCondFormatIconSet
TXLSXConditionalFormat (צד ה-XLSX)