FontSettingCollection.Replace

Replace(int, int, string)

Replace the text.

public void Replace(int index, int count, string text)
ParameterTypeDescription
indexInt32The start index.
countInt32The count of characters.
textStringThe text.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Drawing.Texts;
    using System;

    public class FontSettingCollectionMethodReplaceWithInt32Int32StringDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add a text box to the worksheet
            var textBox = worksheet.Shapes.AddTextBox(0, 0, 100, 100, 200, 200);
            var fontSettingCollection = textBox.TextBody;

            // Set initial text
            fontSettingCollection.Text = "Original text to be modified";

            try
            {
                // Call Replace method to replace 8 characters starting at index 9 with new text
                fontSettingCollection.Replace(9, 8, "replaced");

                // Display the modified text
                Console.WriteLine("Text after replacement: " + fontSettingCollection.Text);

                // Save the workbook
                workbook.Save("FontSettingCollectionReplaceDemo.xlsx");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error executing Replace method: {ex.Message}");
            }
        }
    }
}

See Also


Replace(string, string)

Replace the text.

public void Replace(string oldValue, string newValue)
ParameterTypeDescription
oldValueStringThe old text.
newValueStringThe new text.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Drawing;

namespace AsposeCellsExamples
{
    public class FontSettingCollectionMethodReplaceWithStringStringDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            
            // Add a shape and set text
            Shape shape = worksheet.Shapes.AddTextBox(1, 0, 0, 100, 100, 100);
            shape.Text = "Sample text 34 for replacement";
            
            // Replace text in the shape
            shape.TextBody.Replace("34", "ABC");
            
            // Save the workbook
            workbook.Save("output.xlsx");
        }
    }
}

See Also