Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme
Olası Kullanım Senaryoları
Metni Sütunlara Çevirebilirsiniz Microsoft Excel kullanarak metni sütunlara çevirebilirsiniz. Bu özellik, Data sekmesi altındaki Data Tools menüsünden erişilebilir. Bir sütunun içeriğini birden fazla sütuna ayırmak için, verinin Microsoft Excel’in hücre içeriğini birden fazla hücreye ayırdığı belirli bir ayırıcı içermesi gerekmektedir. Aspose.Cells, bu özelliği Worksheet.Cells.TextToColumns() metodu aracılığıyla sağlar.
Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme
Aşağıdaki örnek kod, Worksheet.Cells.TextToColumns() 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.TextToColumns() 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
// 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"); |