Artykuł techniczny

HotXLS: VBA payload and external link preservation in Delphi

Twórz, edytuj, sprawdzaj, obliczaj i eksportuj skoroszyty Excel bezpośrednio z kodu Delphi lub C++Builder. HotXLS to natywna biblioteka Object Pascal z kodem źródłowym dla przepływów XLS i XLSX, przeznaczona do narzędzi desktopowych, zadań batch, systemów raportowych i generowania dokumentów po stronie serwera bez automatyzacji Microsoft Excel.

Ten artykuł jest przeznaczony dla teams editing workbook content while preserving macro payloads and link relationships they do not own. Traktuje VBA payload and external link preservation jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.

Praktyczne ryzyko polega na tym, że a workbook can save successfully while silently dropping VBA projects, changing link targets, or refreshing data connections against policy. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.

Decyzje architektoniczne

Identify protected workbook assets before editing. whether macro-enabled workbooks are accepted, preserved, blocked, or converted / external link inventory, update policy, trusted domains, and refresh behavior

  • whether macro-enabled workbooks are accepted, preserved, blocked, or converted
  • external link inventory, update policy, trusted domains, and refresh behavior
  • which workbook edits are allowed without rewriting protected payloads
  • security warning, operator review, and audit-report requirements

Przebieg implementacji

Preserve opaque payloads unless policy says otherwise. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. inventory VBA projects, external links, data connections, and defined names before editing
  2. load worksheet data changes without executing or refreshing external content
  3. preserve opaque payloads where policy allows and mark blocked content clearly
  4. save in a format that supports the required payloads
  5. compare pre-save and post-save inventories before delivery

Dowody walidacji

Preservation evidence for governed workbooks. Keep these fields with the output or support record.

  • macro presence, VBA project preservation status, and macro-enabled format decision
  • external link targets, trusted or blocked status, and refresh policy
  • payload inventory before and after save
  • operator decision for workbooks with governed content

Preservation is not execution

Preserving VBA payloads and external links means keeping workbook structures intact while clearly avoiding automatic trust or execution. The application should inventory what exists and decide what is allowed to change.

Uwagi wdrożeniowe dla produkcji

Traktuj HotXLS: VBA payload and external link preservation in Delphi jako jawny kontrakt usługi wokół wywołań HotXLS, oddzielając walidację wejścia, zapis skoroszytu, kontrolę wyniku i dowody dla wsparcia

  • Ustal źródło danych, zakresy komórek i format wyjściowy przed utworzeniem skoroszytu
  • Zapisuj liczbę wierszy, arkusze, ostrzeżenia i ścieżkę wyjściową w możliwym do sprawdzenia logu
  • Szczegóły aplikacji zamykaj w testowalnych helperach zamiast w zdarzeniach UI
  • Otwórz lub sprawdź zapisany plik przed przekazaniem go do innego systemu lub klienta

Tryby awarii do przećwiczenia

  • Udany SaveAs nie dowodzi, że kontrakt biznesowy nadal jest poprawny
  • Czcionki, uprawnienia i ustawienia regionalne mogą różnić się między serwerem a maszyną deweloperską
  • Logi nie mogą ujawniać haseł, danych klientów ani linków wewnętrznych

Szczegółowy przykład Delphi

Poniższy przykład Delphi pokazuje praktyczną granicę usługi dla tego tematu, z polityką, logowaniem i walidacją w warstwie możliwej do testowania

procedure UpdateLinkedWorkbookWithoutBreakingMacros(const InputFile, OutputFile: string; const Update: TWorkbookUpdate);
var
  Wb: TXLSXWorkbook;
  BeforeState: TMacroLinkInventory;
  AfterState: TMacroLinkInventory;
begin
  RequireFileExists(InputFile);
  Wb := TXLSXWorkbook.Create;
  try
    Wb.Open(InputFile);
    BeforeState := CaptureMacroAndLinkInventory(Wb);
    AssertAllowedExternalLinks(BeforeState, Update.AllowedLinkHosts);

    SetNamedValue(Wb, 'RefreshDate', Update.RefreshDate);
    FillNamedTable(Wb, 'DataRefreshRows', Update.Rows);
    Wb.Calculate;

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

    AfterState := InspectMacroAndLinkInventory(OutputFile);
    AssertMacroModulesPreserved(BeforeState, AfterState);
    AssertExternalLinksPolicy(AfterState, Update.AllowedLinkHosts);
    WriteMacroLinkAudit(OutputFile, BeforeState, AfterState);
  finally
    Wb.Free;
  end;
end;

Lista produkcyjna

  • 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