This section summarizes how DsExcel Java handles the spreadsheet documents(.csv files).
While importing and exporting a workbook in order to open and save a csv file or stream, you can use the following methods of the CsvOpenOptions class and the CsvSaveOptions class in order to configure several open and save options in a workbook.
Methods | Description |
---|---|
Used to get or set a value that indicates whether the string in text file is converted to numeric data. | |
Used to get or set a value that indicates whether the string in text file is converted to date data. | |
Used to get or set the default encoding which is UTF-8. | |
Used to specify whether the style for parsed values should be applied while converting the string values to number or date time. | |
Used to specify whether the text is formula if it starts with "=". | |
Used to get or set the string value as the separator. By default, this value is a comma separator. | |
Used to specify the default encoding which is UTF-8. | |
Used to get or set how to quote values in the exported text file. Note: DsExcel ignores this method when QuoteColumns property is set. | |
Used to specify whether the leading blank rows and columns should be trimmed like in Excel. | |
Used to specify which column values will be in quotes while the values in the remaining columns are not. The column number starts at 0, and specifying an invalid column number has no effect. Note: If the value contains special characters such as quotes or separators, it will be in quotes. |
Refer to the following example code in order to import a .csv file.
Java |
Copy Code |
---|---|
Workbook workbook = new Workbook(); // Opening a CSV file workbook.open("documents\source.csv", OpenFileFormat.Csv); // Opening a CSV file using several open options CsvOpenOptions options = new CsvOpenOptions(); options.setSeparatorString("-"); workbook.open("documents\source.csv", options); |
Refer to the following example code in order to export a .csv file from a workbook or a particular worksheet in the workbook.
Java |
Copy Code |
---|---|
// Saving a CSV file from workbook Workbook workbook = new Workbook(); // Saving to a CSV file workbook.save("SaveToCsvFile.csv", SaveFileFormat.Csv); // Saving to a csv file with advanced settings CsvSaveOptions options = new CsvSaveOptions(); options.setSeparatorString("-"); options.setValueQuoteType(ValueQuoteType.Always); options.setQuoteColumns(new int[] { 1, 3, 4 }); //ValueQuoteType is ignored when QuoteColumns is set. workbook.save("SaveToCsvFile.csv", options); |