Behalte Trennzeichen für leere Zeilen beim Exportieren von Tabellenkalkulationen im CSV Format mit C++

Trennzeichen für leere Zeilen beim Exportieren von Tabellenkalkulationen im CSV-Format beibehalten

Aspose.Cells bietet die Möglichkeit, Zeilen- und Spaltentrenner beim Konvertieren von Tabellenkalkulationen in das CSV-Format beizubehalten. Dafür kannst du die GetKeepSeparatorsForBlankRow()-Eigenschaft der TxtSaveOptions-Klasse verwenden. GetKeepSeparatorsForBlankRow() ist eine boolesche Eigenschaft. Um die Trenner für leere Zeilen beim Umwandeln der Excel-Datei in CSV beizubehalten, setze die GetKeepSeparatorsForBlankRow()-Eigenschaft auf true.

Der folgende Beispielcode lädt die Quellexcel-Datei. Es setzt die TxtSaveOptions.GetKeepSeparatorsForBlankRow()-Eigenschaft auf true und speichert sie als output.csv. Der Screenshot zeigt den Vergleich zwischen der Quell-Excel-Datei, der standardmäßigen Ausgabe beim Konvertieren in CSV und der Ausgabe, die durch Setzen von GetKeepSeparatorsForBlankRow() auf true erzeugt wurde.

todo:image_alt_text

Beispielcode

#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();
}