将电子表格导出为 CSV 格式时保留空白行的分隔符
Contents
[
Hide
]
将电子表格导出为 CSV 格式时保留空白行的分隔符
Aspose.Cells 提供了在将电子表格转换为 CSV 格式时保留行分隔符的功能。为此,您可以使用**KeepSeparatorsForBlankRow**的财产**TxtSaveOptions**班级。**KeepSeparatorsForBlankRow**是一个布尔属性。要在将 Excel 文件转换为 CSV 时保留空行分隔符,请设置**KeepSeparatorsForBlankRow**财产给**真的**.
下面的示例代码加载源Excel文件.它设置**TxtSaveOptions.KeepSeparatorsForBlankRow**财产给**真的**并将其另存为输出.csv .屏幕截图显示了源 Excel 文件、将电子表格转换为 CSV 时生成的默认输出与通过设置生成的输出之间的比较**KeepSeparatorsForBlankRow**到**真的**.
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |