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 !

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
900 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,575 questions
{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