複数のエンコーディングでのCSVファイルの読み込み

Contents
[ ]

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

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

入力ファイル
todo:image_alt_text

|入力ファイル|

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

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

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

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

// 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 + "MultiEncoded.csv";
// Set Multi Encoded Property to True
TxtLoadOptions options = new TxtLoadOptions();
options.IsMultiEncoded = true;
// Load the CSV file into Workbook
Workbook workbook = new Workbook(filePath, options);
// Save it in XLSX format
workbook.Save( filePath + ".out.xlsx", SaveFormat.Xlsx);

関連記事