How to hide column with the excel javascript api

Yaco 1 Reputation point
2021-02-06T13:11:57.25+00:00

Hi,
I use the JavaScript API with Excel.
I want to hide a couple of columns.
I don't understant witch syntax to use. My code doesn't work :

export const test = () => {
  Excel.run((context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    sheet.getRange("C:D").hidden("true");
  });
};

Where to set 'true' ?
Thanks !

Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office Development Other
{count} votes

1 answer

Sort by: Most helpful
  1. Martin 1 Reputation point
    2021-12-02T18:42:50.71+00:00

    I found it working this way:

    async function hideUnhideColumnAsync(hidden) {
            return Excel.run(async (context) => {
    
    let targetSheet = context
                    .workbook
                    .worksheets
                    .getItem('MyWorkSheet');
    
    targetSheet.getRange('A:A').columnHidden = hidden;
    
    return await context.sync();
            });
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.