This section summarizes how GcExcel 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 string value as a separator. | |
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. | |
Used to specify whether the leading blank rows and columns should be trimmed like in Excel. |
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("-"); workbook.save("SaveToCsvFile.csv", options); |