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

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

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

以下示例代码加载了 源 Excel 文件,将 TxtSaveOptions.KeepSeparatorsForBlankRow 属性设置为 true 并将其保存为 output.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-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string filePath = dataDir + "Book1.xlsx";
// Create a Workbook object and opening the file from its path
Workbook wb = new Workbook(filePath);
// Instantiate Text File's Save Options
TxtSaveOptions options = new TxtSaveOptions();
// Set KeepSeparatorsForBlankRow to true show separators in blank rows
options.KeepSeparatorsForBlankRow = true;
// Save the file with the options
wb.Save(dataDir + "output.csv", options);