Lesson 7 of 8
Document creation
Generate PDF or Word documents from an API request by mapping Word-template placeholders to workbook inputs and calculated outputs.
2 min readGenerate a personalized PDF or Word document as part of a SpreadsheetWeb API calculation. This is useful when a calling application needs a quote, proposal, report, or other customer-facing document that combines static language with workbook inputs and calculated results.
Prepare the Word template
Create the document layout in Microsoft Word. The template can contain ordinary text, formatting, legal language, and other fixed content.
Insert placeholders for dynamic values using double curly brackets. Each placeholder represents a document stub that will be mapped to a named range in the Excel workbook. In the insurance example, the template includes customer inputs such as issue age and coverage amount along with the calculated total premium.
Using the same names for Word placeholders and Excel named ranges makes the mapping easier, but it is not required.
Create the Print Process
- Open the API application in Design and start a new transaction.
- Go to Events and add a Print Process.
- Give the process a descriptive name, such as Proposal.
- Choose PDF or Word as the document output format.
- Create the process, then add a document and upload the Word template.
After the template is uploaded, open its document stubs. SpreadsheetWeb lists the placeholders detected in the Word file and the named ranges available in the workbook.
Map placeholders to workbook values
Map each document stub to the input or output that should replace it at runtime. When a placeholder and named range use the same name, SpreadsheetWeb can match them automatically. Otherwise, select the correct named range manually.
Enable the required stubs and publish the transaction. The published API version now includes the document-generation process.
Generate the document through API Toolkit
Open API Toolkit and select the newly published transaction. The request settings now contain a Print Process section.
- Add the configured process to the calculation request.
- Supply the required workbook inputs.
- Select Calculate.
- Open the document URL returned in the print section of the response.
SpreadsheetWeb calculates the workbook, replaces the template placeholders with the submitted inputs and calculated outputs, and generates the requested document. The consuming application can use the returned URL to retrieve and present the file to the user.