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

Olası Kullanım Senaryoları

Microsoft Excel kullanarak Metni Sütunlara Dönüştürme

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ının A sütununa bazı insan isimleri ekler. İlk ve soyadı boşluk karakteriyle ayrılmıştır. Ardından A sütununa TextToColumns metodunu uygular ve çıktı excel dosyası olarak kaydeder. Eğer çıktı excel dosyasını açarsanız, ilk isimleri A sütununda, soyadlarını ise B sütununda görebilirsiniz.

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");