Excel.SettableCellProperties interface

Représente le paramètre d’entrée de setCellProperties.

Jeu d’API : ExcelApi 1.9

Remarques

Utilisateur

Exemples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const detailedFormatProps: Excel.SettableCellProperties = {
        format: {
            borders: {
                diagonalDown: {
                    color: "#C00000",
                    style: Excel.BorderLineStyle.dash,
                    weight: Excel.BorderWeight.medium
                }
            },
            fill: {
                color: "#D9EAF7",
                pattern: Excel.FillPattern.lightDown,
                patternColor: "#4472C4"
            },
            font: {
                bold: true,
                color: "#1F1F1F",
                name: "Arial",
                size: 12
            },
            horizontalAlignment: Excel.HorizontalAlignment.center,
            protection: {
                formulaHidden: false,
                locked: false
            },
            textOrientation: 15,
            verticalAlignment: Excel.VerticalAlignment.center,
            wrapText: true
        }
    };

    const cell = sheet.getRange("C7");
    cell.setCellProperties([[detailedFormatProps]]);
    cell.format.rowHeight = 45;
    await context.sync();
});

Propriétés

format

Représente la format propriété.

Jeu d’API : ExcelApi 1.9

hyperlink

Représente la hyperlink propriété.

Jeu d’API : ExcelApi 1.9

style

Représente la style propriété.

Jeu d’API : ExcelApi 1.9

textRuns

Représente la textRuns propriété.

Détails de la propriété

format

Représente la format propriété.

Jeu d’API : ExcelApi 1.9

format?: Excel.CellPropertiesFormat;

Valeur de propriété

Représente la hyperlink propriété.

Jeu d’API : ExcelApi 1.9

hyperlink?: Excel.RangeHyperlink;

Valeur de propriété

Exemples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const hyperlinkDetails: Excel.RangeHyperlink = {
        address: "https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-ranges-set-get-values",
        screenTip: "Learn about working with ranges.",
        textToDisplay: "Range documentation",
    };
    const hyperlinkProps: Excel.SettableCellProperties = {
        hyperlink: hyperlinkDetails
    };

    sheet.getRange("B7").setCellProperties([[hyperlinkProps]]);
    await context.sync();
});

style

Représente la style propriété.

Jeu d’API : ExcelApi 1.9

style?: string;

Valeur de propriété

string

Exemples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    // Create the SettableCellProperties objects for the range.
    // Create these objects once, outside the function, in your add-in.
    const topHeaderProps: Excel.SettableCellProperties = {
        // Set the style property to the name of an Excel style.
        // The `BuiltInStyle` enum lists the built-in style names.
        // A style overwrites formatting, so don't use style and format in the same object.
        style: Excel.BuiltInStyle.heading1
    };

    const headerProps: Excel.SettableCellProperties = {
        // Setting these cell properties doesn't change unspecified format subproperties.
        format: {
            fill: {
                color: "Blue"
            },
            font: {
                color: "White",
                bold: true
            }
        }
    };

    const nonApplicableProps: Excel.SettableCellProperties = {
        format: {
            fill: {
                pattern: Excel.FillPattern.gray25
            },
            font: {
                color: "Gray",
                italic: true
            }
        }
    };

    const matchupScoreProps: Excel.SettableCellProperties = {
        format: {
            borders: {
                bottom: {
                    style: Excel.BorderLineStyle.continuous
                },
                left: {
                    style: Excel.BorderLineStyle.continuous
                },
                right: {
                    style: Excel.BorderLineStyle.continuous
                },
                top: {
                    style: Excel.BorderLineStyle.continuous
                }
            },
            horizontalAlignment: Excel.HorizontalAlignment.center
        }
    };

    const range = sheet.getRange("A1:E5");

    // Use empty JSON objects to leave a cell's properties unchanged.
    range.setCellProperties([
        [topHeaderProps, {}, {}, {}, {}],
        [{}, {}, headerProps, headerProps, headerProps],
        [{}, headerProps, nonApplicableProps, matchupScoreProps, matchupScoreProps],
        [{}, headerProps, matchupScoreProps, nonApplicableProps, matchupScoreProps],
        [{}, headerProps, matchupScoreProps, matchupScoreProps, nonApplicableProps]
    ]);

    sheet.getUsedRange().format.autofitColumns();
    await context.sync();
});

textRuns

Représente la textRuns propriété.

textRuns?: RangeTextRun[];

Valeur de propriété

Remarques

Jeu d’API : ExcelApi 1.18

Exemples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const textRunFormats: Excel.RangeTextRun[] = [
        {
            text: "Rich ",
            font: {
                bold: true,
                color: "#C00000",
                size: 14
            }
        },
        {
            text: "text",
            font: {
                color: "#4472C4",
                italic: true,
                underline: Excel.RangeUnderlineStyle.single
            }
        }
    ]
    const richTextProps: Excel.SettableCellProperties = {
        textRuns: textRunFormats
    };

    sheet.getRange("A7").setCellProperties([[richTextProps]]);
    await context.sync();
});