Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active August 15, 2021 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/386745c6e850606db29ec44796406f20 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/386745c6e850606db29ec44796406f20 to your computer and use it in GitHub Desktop.
Generate PDF and Word Reports from CSV data using Template in Java
// Generate PDF Report from CSV data using TXT template in Java with GroupDocs.Assembly API
// Define datasource, template, and output report files.
String csvDataSource = "dataPath/Person.csv";
String templateFilePath = "templatePath/template.txt";
String reportFilePath = "reportsPath/reportFromCSV.pdf";
// Laod CSV Data Source
CsvDataLoadOptions options = new CsvDataLoadOptions(true);
CsvDataSource datasource= new CsvDataSource(csvDataSource,options);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"persons");
// Generate Report
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(templateFilePath, reportFilePath, dataSourceInfo);
// Generate Word Report from CSV data using TXT template in Java with GroupDocs.Assembly API
// Define datasource, template, and output report files.
String csvDataSource = "dataPath/Person.csv";
String templateFilePath = "templatePath/template.txt";
String reportFilePath = "reportsPath/reportFromCSV.docx";
// Load CSV Data Source
CsvDataLoadOptions options = new CsvDataLoadOptions(true);
CsvDataSource datasource= new CsvDataSource(csvDataSource,options);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"persons");
// Generate Report
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(templateFilePath, reportFilePath, dataSourceInfo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment