テキストを列に変換

テキストを列に変換

Microsoft Excel を使用して、テキストを列に変換できます。この機能は、データ ツールデータタブ。列の内容を複数の列に分割するには、Microsoft Excel がセルの内容を複数のセルに分割するためのコンマ (またはその他の文字) などの特定の区切り文字をデータに含める必要があります。 Aspose.Cells も、[TextToColumns](https://reference.aspose.com/cells/python/asposecells.api/cells#textToColumns(int,%20int,%20int,%20com.aspose.cells.TxtLoadOptions)) 方法。次のコード スニペットは、TextToColumns 区切り文字としてスペースを使用してテキストを列に変換する方法。

output_directory = "Examples/SampleFiles/OutputDirectory/"
# Create Workbook
workbook = Workbook()
# Access the first worksheet
worksheet = workbook.getWorksheets().get(0)
# Add people name in column A. Fast name and Last name are separated by space.
worksheet.getCells().get("A1").putValue("John Teal")
worksheet.getCells().get("A2").putValue("Peter Graham")
worksheet.getCells().get("A3").putValue("Brady Cortez")
worksheet.getCells().get("A4").putValue("Mack Nick")
worksheet.getCells().get("A5").putValue("Hsu Lee")
# Create text load options with space as separator.
txtLoadOptions = TxtLoadOptions()
txtLoadOptions.setSeparator(' ')
# Split the column A into two columns using TextToColumns() method.
# Now column A will have first name and column B will have second name.
worksheet.getCells().textToColumns(0, 0, 5, txtLoadOptions)
# Save the excel file.
workbook.save(output_directory + "outputTextToColumns.xlsx")