複数のエンコーディングでのCSVファイルの読み込み
Contents
[
Hide
]
CSVファイルには複数のエンコーディング(Unicode、ANSI、UTF8、UTF7など)が含まれることがあります。Aspose.Cellsを使用すると、このようなCSVファイルをロードし、PDFやXLSXなどの他の形式に変換することができます。
Aspose.CellsはTxtLoadOptions.IsMultiEncodedプロパティを提供しており、複数のエンコーディングでCSVファイルを正しくロードするにはtrueに設定する必要があります。
以下のスクリーンショットは、2行を含むサンプルCSVファイルを示しています。1行目はANSIエンコーディングで、2行目はUnicodeエンコーディングです
入力ファイル |
---|
![]() |
|入力ファイル|
出力ファイル1: 複数のエンコーディングを考慮していない |
---|
![]() |
上記のCSVファイルから変換されたXLSXファイルを、TxtLoadOptions.IsMultiEncodedプロパティをtrueに設定した後のスクリーンショットは以下の通りです。Unicodeテキストが正しく変換されていることがわかります。
出力ファイル2: IsMultiEncodedをtrueに設定 |
---|
![]() |
以下は、上記のCSVファイルを正しくXLSX形式に変換するサンプルコードです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |