Keep Separators for Blank Rows while exporting spreadsheets to CSV format with C++
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 GetKeepSeparatorsForBlankRow() property of the TxtSaveOptions class. GetKeepSeparatorsForBlankRow() is a boolean property. To keep the separators for blank lines while converting the Excel file to CSV, set the GetKeepSeparatorsForBlankRow() property to true.
The following sample code loads the source Excel file. It sets the TxtSaveOptions.GetKeepSeparatorsForBlankRow() property to true and saves it as output.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 GetKeepSeparatorsForBlankRow() to true.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input excel file
U16String inputFilePath = srcDir + u"Book1.xlsx";
// Create a Workbook object and opening the file from its path
Workbook workbook(inputFilePath);
// Instantiate Text File's Save Options
TxtSaveOptions options;
// Set KeepSeparatorsForBlankRow to true to show separators in blank rows
options.SetKeepSeparatorsForBlankRow(true);
// Save the file with the options
workbook.Save(outDir + u"output.csv", options);
std::cout << "File saved successfully as output.csv!" << std::endl;
Aspose::Cells::Cleanup();
}