Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme

Olası Kullanım Senaryoları

Microsoft Excel kullanarak metninizi Sütunlara çevirebilirsiniz. Bu özellik, Data Tools altındaki Data sekmesinde bulunur. Bir sütunun içeriğini çoklu sütunlara ayırmak için, verilerin belirli bir ayırıcı içermesi gerekir, örneğin bir virgül (veya başka herhangi bir karakter), buna göre Microsoft Excel hücre içeriğini birden fazla hücreye ayırır. Aspose.Cells, bu özelliği TextToColumns metodu ile de sağlar.

Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme

Aşağıdaki örnek kod, TextToColumns metodunun kullanımını açıklar. Kod önce ilk çalışma sayfasındaki A sütununa bazı isimler ekler. Ad ve soyad boşluk karakteri ile ayrılmıştır. Daha sonra A sütunundaki hücreye TextToColumns metodunu uygular ve sonucu bir çıktı excel dosyası olarak kaydeder. Eğer çıktı excel dosyasını açarsanız, ilk isimlerin A sütununda, soy isimlerin ise B sütununda olduğunu göreceksiniz ki, bu da ekran görüntüsüyle gösterilmiştir.

todo:image_alt_text

Örnek Kod

// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ConvertTexttoCols.class) + "rows_cloumns/";
//Create a workbook.
Workbook wb = new Workbook();
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Add people name in column A. Fast name and Last name are separated by space.
ws.getCells().get("A1").putValue("John Teal");
ws.getCells().get("A2").putValue("Peter Graham");
ws.getCells().get("A3").putValue("Brady Cortez");
ws.getCells().get("A4").putValue("Mack Nick");
ws.getCells().get("A5").putValue("Hsu Lee");
//Create text load options with space as separator.
TxtLoadOptions opts = new TxtLoadOptions();
opts.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.
ws.getCells().textToColumns(0, 0, 5, opts);
//Save the workbook in xlsx format.
wb.save(dataDir + "outputTextToColumns.xlsx");