Forum Discussion

afhamilton's avatar
afhamilton
Copper Contributor
Oct 09, 2024
Solved

Remove strikethrough formatted characters in a cell

Hi,

I am trying to remove the all characters in a selected cell that is formatted with strikethrough.  I managed the Office script below but it's only removing the strikethrough format and doesn't delete the 'strikethrough formatted' word.  Any suggestions how I can modify the script to achieve my objective?

 

function main(workbook: ExcelScript.Workbook) {
    // Get the active cell
    let cell = workbook.getActiveCell();

    // Get the text from the cell
    let text = cell.getText();

    let sheet = workbook.getActiveWorksheet();

    // Get the selected range
    // let range = sheet.getSelectedRange();

    // Get the format of each character in the cell
    // Get the format of each character in the cell
    let formats = cell.getFormat().getFont().getStrikethrough();

    // Initialize a new string to store the result
    let newText = '';

    // Loop through each character in the cell text
    for (let i = 0; i < text.length; i++) {
        // Check if the character is formatted with strikethrough
        if (!formats) {
            // If not, add it to the new text
            newText += text[i];
        }
    }

    // Set the new text to the cell
    cell.setValue(newText);
}

 

 

3 Replies

Resources