Keep Separators for Blank Rows while exporting spreadsheets to CSV format

Keep Separators for Blank Rows while exporting spreadsheets to CSV format

Aspose.Cells provides the ability to keep line separators while converting spreadsheets to CSV format. For this, You may use the KeepSeparatorsForBlankRow property of TxtSaveOptions class. KeepSeparatorsForBlankRow is a boolean property. To keep the separators for blank lines while converting the Excel File to CSV, set the KeepSeparatorsForBlankRow property to true.

The following sample code loads the source Excel file. It sets TxtSaveOptions.KeepSeparatorsForBlankRow property to true and saves it as KeepSeparatorsForBlankRow.out.csv. The screenshot shows the comparison between the source Excel file, the default output generated while converting the spreadsheet to CSV and the output generated by setting KeepSeparatorsForBlankRow to true.

todo:image_alt_text

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ConvertTableToRangeWithOptions.class) + "LoadingSavingConvertingAndManaging/";
// Open an existing file that contains a table/list object in it
Workbook workbook = new Workbook(dataDir + "KeepSeparatorsForBlankRow.xlsx");
// Instantiate Text File's Save Options
TxtSaveOptions options = new TxtSaveOptions();
// Set KeepSeparatorsForBlankRow to true show separators in blank rows
options.setKeepSeparatorsForBlankRow(true);
// Save the file with the options
workbook.save(dataDir + "KeepSeparatorsForBlankRow.out.csv", options);