java.lang.Object
com.aspose.words.CsvDataSource
public class CsvDataSource
To learn more, visit the LINQ Reporting Engine documentation article.
To access data of the corresponding file or stream while generating a report, pass an instance of this class as
a data source to one of
In template documents, a
Data types of comma-separated values are determined automatically upon their string representations. So in template
documents, you can work with typed values rather than just strings. The engine is capable to automatically recognize
values of the following types:
Note that for automatic recognition of data types to work, string representations of comma-separated values should
be formed using invariant culture settings.
To override default behavior of CSV data loading, initialize and pass a Example:
Document doc = new Document(getMyDir() + "Reporting engine template - CSV data destination (Java).docx");
CsvDataLoadOptions loadOptions = new CsvDataLoadOptions(true);
loadOptions.setDelimiter(';');
loadOptions.setCommentChar('$');
loadOptions.hasHeaders(true);
loadOptions.setQuoteChar('"');
CsvDataSource dataSource = new CsvDataSource(getMyDir() + "List of people.csv", loadOptions);
buildReport(doc, dataSource, "persons");
doc.save(getArtifactsDir() + "ReportingEngine.CsvDataString.docx");
| Constructor Summary |
|---|
CsvDataSource(java.lang.String csvPath)
Creates a new data source with data from a CSV file using default options for parsing CSV data. |
CsvDataSource(java.lang.String csvPath, CsvDataLoadOptions options)
Creates a new data source with data from a CSV file using the specified options for parsing CSV data. |
CsvDataSource(java.io.InputStream csvStream)
Creates a new data source with data from a CSV stream using default options for parsing CSV data. |
CsvDataSource(java.io.InputStream csvStream, CsvDataLoadOptions options)
Creates a new data source with data from a CSV stream using the specified options for parsing CSV data. |
| Constructor Detail |
|---|
public CsvDataSource(java.lang.String csvPath)
throws java.lang.Exception
csvPath - The path to the CSV file to be used as the data source.
public CsvDataSource(java.lang.String csvPath, CsvDataLoadOptions options)
throws java.lang.Exception
csvPath - The path to the CSV file to be used as the data source.options - Options for parsing the CSV data.Example:
Shows how to use CSV as a data source (string).
Document doc = new Document(getMyDir() + "Reporting engine template - CSV data destination (Java).docx");
CsvDataLoadOptions loadOptions = new CsvDataLoadOptions(true);
loadOptions.setDelimiter(';');
loadOptions.setCommentChar('$');
loadOptions.hasHeaders(true);
loadOptions.setQuoteChar('"');
CsvDataSource dataSource = new CsvDataSource(getMyDir() + "List of people.csv", loadOptions);
buildReport(doc, dataSource, "persons");
doc.save(getArtifactsDir() + "ReportingEngine.CsvDataString.docx");
public CsvDataSource(java.io.InputStream csvStream)
throws java.lang.Exception
csvStream - The stream of CSV data to be used as the data source.
public CsvDataSource(java.io.InputStream csvStream, CsvDataLoadOptions options)
throws java.lang.Exception
csvStream - The stream of CSV data to be used as the data source.options - Options for parsing the CSV data.Example:
Shows how to use CSV as a data source (stream).
Document doc = new Document(getMyDir() + "Reporting engine template - CSV data destination (Java).docx");
CsvDataLoadOptions loadOptions = new CsvDataLoadOptions(true);
loadOptions.setDelimiter(';');
loadOptions.setCommentChar('$');
InputStream stream = new FileInputStream(getMyDir() + "List of people.csv");
try {
CsvDataSource dataSource = new CsvDataSource(stream, loadOptions);
buildReport(doc, dataSource, "persons");
} finally {
stream.close();
}
doc.save(getArtifactsDir() + "ReportingEngine.CsvDataStream.docx");