Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme
Olası Kullanım Senaryoları
Metni Sütunlara Dönüştürmek için Microsoft Excel’i kullanabilirsiniz. Bu özellik, Veri Araçları altındaki Veri sekmesinden kullanılabilir. Bir sütunun içeriğini birden fazla sütuna bölmek için, verinin, Microsoft Excel’in bir hücredeki içeriği birden çok hücreye bölmek için kullandığı gibi virgül (veya başka herhangi bir karakter) gibi belirli bir ayraç içermesi gerekmektedir. Aspose.Cells for Python via .NET ayrıca Worksheet.Cells.text_to_columns() methodunu kullanarak bu özelliği sağlar.
Aspose.Cells for Python Excel Kütüphanesi Kullanarak Metni Sütunlara Dönüştürme
Aşağıdaki örnek kod, Worksheet.Cells.text_to_columns() metodunun kullanımını açıklar. Kod öncelikle ilk çalışma sayfasının A sütununa bazı kişi adları ekler. İlk ve soyadı boşluk karakteriyle ayrılmıştır. Ardından A sütununa Worksheet.Cells.text_to_columns() metodu uygular ve çıktı excel dosyası olarak kaydeder. Eğer çıktı excel dosyasını açarsanız, ilk isimlerin A sütununda ve soyadlarının B sütununda olduğunu göreceksiniz.
Örnek Kod
from aspose.cells import TxtLoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a workbook. | |
wb = Workbook() | |
# Access first worksheet. | |
ws = wb.worksheets[0] | |
# Add people name in column A. Fast name and Last name are separated by space. | |
ws.cells.get("A1").put_value("John Teal") | |
ws.cells.get("A2").put_value("Peter Graham") | |
ws.cells.get("A3").put_value("Brady Cortez") | |
ws.cells.get("A4").put_value("Mack Nick") | |
ws.cells.get("A5").put_value("Hsu Lee") | |
# Create text load options with space as separator. | |
opts = 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.text_to_columns(0, 0, 5, opts) | |
# Save the workbook in xlsx format. | |
wb.save(dataDir + "outputTextToColumns.xlsx") |