مقال تقني

HotXLS Component: data validation, AutoFilter, and worksheet tables في Delphi

أنشئ وحرر وافحص واحسب وصدّر مصنفات Excel مباشرة من كود Delphi أو C++Builder. HotXLS مكتبة جداول Object Pascal أصلية مع المصدر لسير عمل XLS وXLSX، ومناسبة لأدوات سطح المكتب والمهام الدفعية وأنظمة التقارير وتوليد المستندات على الخادم دون أتمتة Microsoft Excel.

هذه المقالة موجّهة إلى developers generating workbooks that users continue editing after export. وهي تتعامل مع data validation, AutoFilter, and worksheet tables كجزء من هندسة المستندات في بيئة الإنتاج، لا كاستدعاء سريع لمكوّن.

الخطر العملي هو أن editable workbooks become error-prone when valid values, filters, table ranges, and totals are not generated as part of the data contract. لذلك يحتاج المسار إلى عقد واضح وتشخيص قابل للملاحظة وملفات اختبار واقعية.

قرارات البنية

Make user editing rules visible in the workbook. validation rules, allowed blank values, error messages, and list-source ownership / table range, header names, totals row, calculated columns, and naming policy

  • validation rules, allowed blank values, error messages, and list-source ownership
  • table range, header names, totals row, calculated columns, and naming policy
  • AutoFilter criteria, hidden-row behavior, and whether filters are pre-applied
  • how validation ranges expand when rows are appended by users or automation

مسار التنفيذ

Build tables around validated ranges. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. write the data range and define headers before applying table behavior
  2. attach validation rules to user-editable cells rather than entire unused columns
  3. apply AutoFilter and totals after the final row count is known
  4. test adding rows, clearing values, sorting, and filtering in Excel
  5. record validation and table definitions for support comparison

أدلة التحقق

Workbook evidence for editable deliverables. Keep these fields with the output or support record.

  • table name, range, header list, totals-row formula, and AutoFilter state
  • validation type, source range, prompt, error message, and blank-value policy
  • row count before and after user-inserted test rows
  • compatibility notes for downstream spreadsheet applications

Editing support starts before the user opens Excel

Data validation, AutoFilter, and worksheet tables help users edit data safely. They need stable ranges, clear list sources, consistent table names, and formulas that expand predictably.

ملاحظات تنفيذ للإنتاج

اجعل موضوع «HotXLS Component: data validation, AutoFilter, and worksheet tables في Delphi» عقد خدمة واضحا حول استدعاءات HotXLS، مع فصل التحقق من الإدخال وكتابة المصنف وفحص الخرج وأدلة الدعم

  • حدد مصدر البيانات ونطاقات الخلايا وتنسيق الخرج قبل إنشاء المصنف
  • سجل عدد الصفوف والأوراق والتحذيرات ومسار الخرج في سجل دعم قابل للمراجعة
  • ضع التفاصيل الخاصة بالتطبيق داخل دوال مساعدة قابلة للاختبار بدلا من نشرها داخل حدث واجهة
  • افتح أو افحص الملف المحفوظ قبل تسليمه إلى نظام آخر أو إلى العميل

حالات فشل يجب اختبارها

  • نجاح SaveAs لا يثبت أن العقد التجاري بقي صحيحا
  • قد تختلف الخطوط والأذونات والإعدادات الإقليمية بين الخادم وجهاز التطوير
  • يجب ألا تكشف السجلات كلمات مرور أو بيانات عملاء أو روابط داخلية

مثال Delphi تفصيلي

يوضح المثال التالي حدود خدمة عملية لهذا الموضوع، مع إبقاء السياسات والسجلات والتحقق في طبقة يمكن اختبارها

procedure BuildValidatedOrderWorkbook(const OutputFile: string; const Rows: TArray<TOrderRow>);
var
  Wb: TXLSXWorkbook;
  Sh: IXLSWorksheet;
  RowIndex: Integer;
  Row: TOrderRow;
begin
  Wb := TXLSXWorkbook.Create;
  try
    Sh := Wb.Sheets[0];
    Sh.Name := 'Orders';
    WriteHeaderRow(Sh, ['OrderId', 'Customer', 'Status', 'Amount', 'Owner']);

    RowIndex := 2;
    for Row in Rows do
    begin
      WriteOrderRow(Sh, RowIndex, Row);
      Inc(RowIndex);
    end;

    Sh.Range['A1:E1'].ApplyBuiltinStyle(xbsTitle);
    AddListValidation(Sh, 'C2:C' + IntToStr(RowIndex - 1), ['New', 'Approved', 'Blocked']);
    AddOwnerValidation(Sh, 'E2:E' + IntToStr(RowIndex - 1));
    AddAutoFilterToHeader(Sh, 'A1:E' + IntToStr(RowIndex - 1));
    CreateStructuredTable(Sh, 'OrdersTable', 'A1:E' + IntToStr(RowIndex - 1));
    AssertValidationCoverage(Sh, RowIndex - 1);

    if Wb.SaveAs(OutputFile) <> 1 then
      RaiseWorkbookSaveError(OutputFile);
  finally
    Wb.Free;
  end;
end;

قائمة فحص الإنتاج

  • Run the workflow on an empty workbook, a normal customer workbook, and a worst-case workbook
  • Open the output with the target spreadsheet application or downstream importer
  • Log product version, template version, profile, row count, output path, elapsed time, and warning count
  • Keep passwords, temporary files, customer data, and support bundles under explicit retention rules
  • Add regression workbooks when a customer file exposes a new edge case

Product documentation

HotXLS Component