Aspose.Cells'i kullanarak Metni Sütunlara Dönüştür
Olası Kullanım Senaryoları
Microsoft Excel kullanarak Metninizi Sütunlara dönüştürebilirsiniz. Bu özellik şu adresten edinilebilir:Veri Araçları altındaVeri sekme. Bir sütunun içeriğini birden çok sütuna bölmek için veriler, Microsoft Excel’in bir hücrenin içeriğini birden çok hücreye böldüğü virgül (veya başka herhangi bir karakter) gibi belirli bir sınırlayıcı içermelidir. Aspose.Cells üzerinden de bu özelliği sağlıyor.Worksheet.Cells.TextToColumns()yöntem.
Aspose.Cells’i kullanarak Metni Sütunlara Dönüştür
Aşağıdaki örnek kod, kullanımını açıklarWorksheet.Cells.TextToColumns() yöntem. Kod, önce ilk çalışma sayfasının A sütununa bazı kişilerin adını ekler. Ad ve soyadı boşluk karakteriyle ayrılır. Sonra geçerliWorksheet.Cells.TextToColumns() A sütunundaki yöntemi ve çıktı excel dosyası olarak kaydedin. eğer açarsançıktı excel dosyası, göreceksiniz, bu ekran görüntüsünde gösterildiği gibi adlar A sütununda, soyadlar ise B sütunundadır.
Basit 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"); |