تحويل النص إلى أعمدة باستخدام Aspose.Cells
Contents
[
Hide
]
سيناريوهات الاستخدام الممكنة
يمكنك تحويل النص الخاص بك إلى أعمدة باستخدام Microsoft Excel. هذه الميزة متاحة منأدوات البيانات تحتبيانات التبويب. لتقسيم محتويات عمود إلى عدة أعمدة ، يجب أن تحتوي البيانات على محدد معين مثل الفاصلة (أو أي حرف آخر) بناءً على Microsoft يقوم Excel بتقسيم محتويات خلية إلى خلايا متعددة. يوفر Aspose.Cells أيضًا هذه الميزة عبرورقة العمل Cells.طريقة.
تحويل النص إلى أعمدة باستخدام Aspose.Cells
يشرح نموذج التعليمات البرمجية التالي استخدامورقة العمل Cells. طريقة. يضيف الرمز أولاً أسماء بعض الأشخاص في العمود A من ورقة العمل الأولى. يتم فصل الاسم الأول والأخير بحرف مسافة. ثم ينطبقورقة العمل Cells. الطريقة في العمود A وحفظها كملف الإخراج إكسل. إذا قمت بفتح ملفملف اكسل الناتجسترى ، الأسماء الأولى موجودة في العمود A بينما الأسماء الأخيرة في العمود B كما هو موضح في لقطة الشاشة هذه.
عينة من الرموز
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |