officeaddin:: excel - cell 값의 개별 char에서도 속성변경가능 2025년 2월

 

 

 

https://github.com/OfficeDev/office-js/issues/4623#issuecomment-2537948014

 

Is there a way to read the format of individual characters in an Excel Cell? · Issue #4623 · OfficeDev/office-js

In Excel, it is possible to format the text within each cell separately. For example if cell A1 has the text you can format it on individual characters like so However, when using the officeJS API,...

github.com

 

Hi @KaranLala

Thank you for your patience. The requested rich text support feature has been implemented and will be included in the upcoming Excel requirement set 1.18 release, scheduled for February 2025. In the meantime, you can already experiment with these capabilities in the beta build.

The following APIs will be available:

  • Excel.CellPropertiesInternal.TextRuns
  • Excel.CellPropertiesLoadOptionsInternal.TextRuns
  • Excel.RangeTextRun.Text
  • Excel.RangeTextRun.Font

For more details, please refer to the official documentation. Below is a sample code snippet that demonstrates how you can use rich text formatting in cells:

(async () => {
  await Excel.run(async (context) => {
    var sheet = context.workbook.worksheets.getItem("TestSheet");
    const cellSrc = sheet.getRange("A1");
    const cellSrcTextRun: Excel.SettableCellProperties = {
      textRuns: [
        { text: "Sample", font: { bold: true, color: "#00B0F0", size: 14, italic: true } },
        { text: "1", font: { subscript: true } },
        { text: "String" },
        { text: "2", font: { superscript: true, color: "black", tintAndShade: 0.5 } },
      ],
    };

    cellSrc.clear(Excel.ClearApplyTo.all);
    cellSrc.setCellProperties([[cellSrcTextRun]]);
    await context.sync();

    const textRunCellProperty = cellSrc.getCellProperties({ textRuns: true });
    await context.sync();

    const cellTextRuns = textRunCellProperty.value[0][0].textRuns;
    console.log(JSON.stringify(cellTextRuns, undefined, "  "));
  });
})();

 

 

 

 

_

반응형