在将电子表格导出为CSV格式时保留空行的分隔符

在将电子表格导出为CSV格式时保留空行的分隔符

Aspose.Cells 提供将电子表格转换为 CSV 格式时保留行分隔符的能力。为此,您可以使用 TxtSaveOptions 类的 KeepSeparatorsForBlankRow 属性。KeepSeparatorsForBlankRow 是一个布尔属性。要在将 Excel 文件转换为 CSV 时保留空行的分隔符,请将 KeepSeparatorsForBlankRow 属性设置为 true

以下示例代码加载源Excel文件。将TxtSaveOptions.KeepSeparatorsForBlankRow属性设置为true,并将其另存为KeepSeparatorsForBlankRow.out.csv。屏幕截图显示了源Excel文件、将电子表格转换为CSV时生成的默认输出和将KeepSeparatorsForBlankRow设置为true时生成的输出之间的比较。

todo:image_alt_text

示例代码

// 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);