C++を使用した複数エンコーディングのCSVファイルの読み取り

Contents
[ ]

Aspose.CellsはTxtLoadOptions.IsMultiEncodedプロパティを提供しており、これをtrueに設定する必要があります。そうすることで、複数エンコーディングのCSVファイルを正しく読み込むことができます。

以下のスクリーンショットは、2行を含むサンプルCSVファイルを示しています。最初の行はANSIエンコーディングで、2行目はUnicodeエンコーディングです。

入力ファイル
todo:image_alt_text

以下のスクリーンショットは、上記のCSVファイルから変換されたXLSXファイルを、TxtLoadOptions.IsMultiEncodedプロパティをtrueに設定しなかった場合を示しています。ご覧のとおり、Unicodeテキストは正しく変換されませんでした。

出力ファイル1: 複数のエンコーディングを考慮していない
todo:image_alt_text

以下のスクリーンショットは、TxtLoadOptions.IsMultiEncodedプロパティをtrueに設定した後の、上記のCSVファイルから変換されたXLSXファイルを示しています。ご覧のとおり、Unicodeテキストは正しく変換されています。

出力ファイル2: IsMultiEncodedをtrueに設定
todo:image_alt_text

以下は、上記のCSVファイルを正しくXLSX形式に変換するサンプルコードです。

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Path of input CSV file
    U16String filePath = srcDir + u"MultiEncoded.csv";

    // Create TxtLoadOptions and set MultiEncoded property to true
    TxtLoadOptions options;
    options.SetIsMultiEncoded(true);

    // Load the CSV file into Workbook with the specified options
    Workbook workbook(filePath, options);

    // Save the workbook in XLSX format
    workbook.Save(filePath + u".out.xlsx", SaveFormat::Xlsx);

    std::cout << "File converted successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

関連記事