Advanced Workbook Workflows
This guide groups the higher-level APIs that are most useful when a workbook workflow goes beyond basic cell reading and writing
Print-ready PDF output
Classic XLS and modern XLSX workbook, worksheet, and range PDF exports render formatted values, cell fills, font color and emphasis, alignment, borders, optional gridlines, column widths, row heights, manual page breaks, repeated print titles, and three-part headers and footers
Sheet.PageSetup.PrintArea := 'A1:H80';
Sheet.PageSetup.PrintTitleRows := '$1:$3';
Sheet.PageSetup.RightHeader := 'Page &P of &N';
Sheet.HPageBreaks.Add(45);
Workbook.SaveAsPDF('report.pdf');
Modern workbooks expose the same direct entry points through TXLSXWorkbook, TXLSXWorksheet, and TXLSXRange
ModernSheet.PrintArea := '$A$1:$H$80';
ModernSheet.PrintTitleRows := '$1:$3';
ModernSheet.AddRowBreak(45);
ModernWorkbook.SaveAsPDF('modern-report.pdf');
Text outside WinAnsi is written with an embedded TrueType CID font and a ToUnicode map so readers can render and extract Unicode text
Set TXLSPDFExport.UnicodeFontFile when a workbook needs a particular script or corporate typeface, otherwise the exporter selects a suitable installed font when available
Use TXLSPaginationModel when preview, PDF, and custom output must share the same paper geometry, margins, fit scale, manual breaks, repeated titles, page order, headers, footers, and drawing anchors
Pages := Exporter.CreatePaginationModel(Workbook);
try
Pages.SavePageAsMetafile(0, 'FirstPage.emf');
finally
Pages.Free;
end;
Progress, cancellation, and diagnostics
Use OnProgressEx for begin, work, and end callbacks and set its abort argument to cancel an operation
Inspect Diagnostics or LastDiagnostic after save, open, or recalculation failures instead of relying only on a numeric return value
Unsupported OOXML package parts
TXLSXWorkbook.PreserveUnsupportedParts defaults to true and retains custom parts reachable through unknown root, workbook, worksheet, or drawing relationships
UnsupportedPartCount and UnsupportedPartBytes report retained content, while ClearUnsupportedParts intentionally removes it before a save
Rich clipboard exchange
Call range-level CopyToClipboard to publish both Unicode tabular text and CF_HTML, including display formatting, formulas, merged cells, links, and safely quoted embedded delimiters
VBA source editing
After loading a VBA project, update an existing module's SourceCode and save the workbook or standalone storage
The writer recompresses only the edited source stream while preserving stream prefixes and untouched project content
Classic form controls
MacroName := Workbook.Names.Add('RunReport', '=0', False);
MacroName.IsMacro := True;
Button := Sheet.AddButton('Run report', 1, 2, 2, 5);
Button.MacroName := 'RunReport';
CheckBox := Sheet.AddCheckBox('Approved', 2, 2, 3, 5);
CheckBox.State := xcsMixed;
CheckBox.LinkedCell := 'Controls!$F$2';
RadioButton := Sheet.AddRadioButton('Primary', 4, 2, 5, 5);
RadioButton.FirstInGroup := True;
ComboBox := Sheet.AddComboBox(5, 2, 6, 5);
ComboBox.SourceRange := 'Controls!$A$1:$A$8';
ListBox := Sheet.AddListBox(8, 2, 12, 5);
ListBox.SourceRange := 'Controls!$A$1:$A$8';
The typed wrappers retain labels, control kinds, anchors, check states, flat or 3D appearance, radio-group links, macro bindings, linked cells, input ranges, enumeration, and deletion across classic XLS open and save cycles
Selective format patches
Target.ApplyFormatPatch(Source, [xfpFont, xfpFill, xfpNumberFormat]);
A smaller source range tiles across a larger target and unselected formatting plus all destination values remain unchanged
Master-detail dataset export
Enable TDataToXLS.ReadDetailTables to export linked detail datasets below every master record and enable IndentDetailTables to add one column of indentation per relationship level
WordArt
Shape := Sheet.AddWordArt('HotXLS', 'textArchUp', 2, 2, 6, 8);
Shape.TextColor := $FF00A060;
Shape.OutlineColor := $FF17365D;
The complete DrawingML anchor survives later open and save cycles through the raw drawing preservation path
See Demo\Delphi\FeatureShowcase for a compact executable example that combines PDF printing, form controls, format patches, and WordArt