HotXLS Docs

Raw template filling

Single edition: lxTemplateFill ships in the core HotXLS package (HotXLSLaz.lpk for Lazarus), so it is included in Single, Small Business, and Enterprise source and DCU editions; the trial build includes it under the usual trial limits

TXlsTemplateFiller fills a workbook template without loading it into the object model: it opens the package, rewrites the stored strings that carry placeholders, substitutes the media parts the caller supplies, and copies every other entry compressed and unchanged. A template that carries an extension this library does not model therefore keeps that part exactly as it was.

What is rewritten

Shared stringsxl/sharedStrings.xml: every <t> text is searched for the registered placeholders
Inline stringsthe <t> elements of each xl/worksheets/*.xml part, unless InlineStrings is false
Mediaany part the caller registers with AddMedia, written with those bytes
Everything elsecopied through the archive’s compressed-copy path, so the content and the compression method stay as they were

Values

AddValue(placeholder, text) registers one substitution. The text is XML-escaped as it is written - an ampersand becomes &amp; and an angle bracket &lt; - and a value whose replacement starts or ends with a space gets xml:space="preserve" on its element so the application does not trim it back off.

Fill(source, destination) answers how many substitutions it made inside the stored strings: two cells that share one string are one replacement, because the package stores that string once. A placeholder split across rich-text runs is not a match; the runs are separate <r><t> elements by design.

Replacements reports the same count for the most recent call: it resets when a fill starts and when Clear discards the registered values and media, and stays zero before the first fill. Media parts written by that fill are counted as well, so the property is the number of package entries the fill actually replaced, not the number of registered placeholders.

Example

Filler := TXlsTemplateFiller.Create;
try
  Filler.AddValue('{{Name}}', 'Ada & Co');
  Filler.AddValue('{{Total}}', '42');
  Applied := Filler.Fill('template.xlsx', 'filled.xlsx');
finally
  Filler.Free;
end;

Errors raise EXlsTemplateFill: registering a placeholder with an empty name, adding media without a stream, a template file that cannot be opened, or a package part that cannot be copied during the fill

See also

Compiled reporting binds values through the object model when the template is fully understood by the library; this layer is for templates that must come back byte-similar.