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, and the trial build ships it subject to the usual trial limits
TXlsTemplateFiller fills a workbook template without bringing it into the object model: the package is opened, the stored strings carrying placeholders are rewritten, media parts supplied by the caller are replaced, and every other entry is copied compressed and untouched. A template with an extension this library does not model therefore keeps that part exactly as it stood.
What is rewritten
| Shared strings | xl/sharedStrings.xml: every <t> text is searched for the registered placeholders |
| Inline strings | the <t> elements of each xl/worksheets/*.xml part, unless InlineStrings is false |
| Media | any part the caller registers with AddMedia, written with those bytes |
| Everything else | goes through the archive’s compressed-copy path, leaving the content and the compression method exactly as they were |
Values
AddValue(placeholder, text) records a single substitution. The text is XML-escaped while written - an ampersand turns into & and an angle bracket < - 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 sharing one string count as a single replacement, since the package stores that string once. A placeholder split across rich-text runs does not match; those runs are separate <r><t> elements by design.
Replacements reports the same count for the most recent call: it resets at the start of a fill and when Clear discards the registered values and media, and stays at zero until the first fill. Media parts written by that fill are counted too, so the property gives 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 with no stream behind it, 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 where the library fully understands the template; the template-filler layer is for templates that have to come back byte-similar.