مقال تقني

HotXLS Component: CSV, TSV, HTML, and RTF export في Delphi

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

هذه المقالة موجّهة إلى developers exporting workbook data to integration feeds, web previews, reports, and legacy document flows. وهي تتعامل مع CSV, TSV, HTML, and RTF export كجزء من هندسة المستندات في بيئة الإنتاج، لا كاستدعاء سريع لمكوّن.

الخطر العملي هو أن export formats lose workbook semantics in different ways, so data, encoding, formulas, styles, and selected ranges need explicit product policy. لذلك يحتاج المسار إلى عقد واضح وتشخيص قابل للملاحظة وملفات اختبار واقعية.

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

Define the target format contract. selected sheets, ranges, headers, hidden rows, and filtered data policy / encoding, delimiter, quote, newline, decimal, and date formatting rules

  • selected sheets, ranges, headers, hidden rows, and filtered data policy
  • encoding, delimiter, quote, newline, decimal, and date formatting rules
  • formula output as cached values, formulas, or blocked content
  • style preservation expectations for HTML and RTF compared with workbook layout

مسار التنفيذ

Choose data fidelity before visual fidelity. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. select the export profile from the target system rather than from file extension alone
  2. normalize data types and locale-sensitive formats before writing delimited output
  3. escape delimiters, quotes, line breaks, and HTML-sensitive characters deliberately
  4. record which workbook features were dropped or simplified
  5. validate exported files with the downstream importer or browser target

أدلة التحقق

Export evidence for downstream consumers. Keep these fields with the output or support record.

  • format, encoding, delimiter, selected range, row count, and column count
  • formula handling, hidden-row policy, filter policy, and style-loss warnings
  • downstream import result or web-preview verification
  • sample records showing quote, newline, Unicode, date, and number behavior

Every export format is a tradeoff

CSV and TSV emphasize delimited data, HTML emphasizes presentation and web preview, and RTF emphasizes styled document interchange. The application should decide which workbook features are preserved, flattened, or rejected.

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

اجعل موضوع «HotXLS Component: CSV, TSV, HTML, and RTF export في Delphi» عقد خدمة واضحا حول استدعاءات HotXLS، مع فصل التحقق من الإدخال وكتابة المصنف وفحص الخرج وأدلة الدعم

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

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

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

مثال Delphi تفصيلي

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

procedure ExportWorkbookViews(const WorkbookFile, OutputFolder: string; const Profiles: TArray<TExportProfile>);
var
  Wb: TXLSXWorkbook;
  Profile: TExportProfile;
  ExportPath: string;
begin
  RequireFolder(OutputFolder);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(WorkbookFile);
    for Profile in Profiles do
    begin
      RequireExportRange(Wb, Profile.SheetName, Profile.RangeAddress);
      ExportPath := BuildExportPath(OutputFolder, Profile);
      case Profile.Format of
        efCsv: ExportRangeAsCsv(Wb, Profile, ExportPath);
        efTsv: ExportRangeAsTsv(Wb, Profile, ExportPath);
        efHtml: ExportRangeAsHtml(Wb, Profile, ExportPath);
      else
        RaiseUnsupportedExportFormat(Profile.Format);
      end;
      ValidateExportRecordCount(Profile, ExportPath);
      AppendExportManifest(OutputFolder, Profile, ExportPath);
    end;
  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