Aspose.Cells を使用してテキストを列に変換します

考えられる使用シナリオ

Microsoft Excel を使用して、テキストを列に変換できます。この機能は、データ ツールデータタブ。列の内容を複数の列に分割するには、Microsoft Excel がセルの内容を複数のセルに分割するためのコンマ (またはその他の文字) などの特定の区切り文字をデータに含める必要があります。 Aspose.Cells もこの機能を提供していますWorksheet.Cells.TextToColumns()方法。

Aspose.Cells を使用してテキストを列に変換します

次のサンプル コードは、Worksheet.Cells.TextToColumns()方法。このコードは、最初のワークシートの列 A に人の名前を最初に追加します。姓と名はスペース文字で区切られています。それなら当てはまるWorksheet.Cells.TextToColumns()メソッドを列 A に追加し、出力 Excel ファイルとして保存します。開くと出力エクセルファイル、このスクリーンショットに示すように、名は列 A にあり、姓は列 B にあることがわかります。

todo:画像_代替_文章

サンプルコード

// 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);
//Create a workbook.
Workbook wb = new Workbook();
//Access first worksheet.
Worksheet ws = wb.Worksheets[0];
//Add people name in column A. Fast name and Last name are separated by space.
ws.Cells["A1"].PutValue("John Teal");
ws.Cells["A2"].PutValue("Peter Graham");
ws.Cells["A3"].PutValue("Brady Cortez");
ws.Cells["A4"].PutValue("Mack Nick");
ws.Cells["A5"].PutValue("Hsu Lee");
//Create text load options with space as separator.
TxtLoadOptions opts = new TxtLoadOptions();
opts.Separator = ' ';
//Split the column A into two columns using TextToColumns() method.
//Now column A will have first name and column B will have second name.
ws.Cells.TextToColumns(0, 0, 5, opts);
//Save the workbook in xlsx format.
wb.Save(dataDir + "outputTextToColumns.xlsx");