在将电子表格导出为CSV格式时保留空行的分隔符
在将电子表格导出为CSV格式时保留空行的分隔符
Aspose.Cells for Python via .NET 具有将行分隔符保留在将电子表格转换为 CSV 格式时的功能。为此,您可以使用 keep_separators_for_blank_row 类的 TxtSaveOptions 属性。keep_separators_for_blank_row 是一个布尔属性。要在将 Excel 文件转换为 CSV 时保留空行的分隔符,请将 keep_separators_for_blank_row 属性设置为 true。
以下示例代码加载了 源 Excel 文件,将 keep_separators_for_blank_row 属性设置为 true 并将其保存为 output.csv。截图显示了源 Excel 文件,将电子表格转换为 CSV 时生成的默认输出以及将 keep_separators_for_blank_row 设置为 true 时生成的输出的比较。
示例代码
from aspose.cells import TxtSaveOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
filePath = dataDir + "Book1.xlsx" | |
# Create a Workbook object and opening the file from its path | |
wb = Workbook(filePath) | |
# Instantiate Text File's Save Options | |
options = TxtSaveOptions() | |
# Set KeepSeparatorsForBlankRow to true show separators in blank rows | |
options.keep_separators_for_blank_row = True | |
# Save the file with the options | |
wb.save(dataDir + "output.csv", options) |