Set 'Fit All Columns on One Page' via Excel JavaScript API
Asked Answered
I

1

-4

I'm looking to set the "Fit All Columns on Page" print option via the Excel JavaScript API. It's very similar to this question which uses VBA -->

How to set 'Fit all columns on one page' in print tab

Internationalism answered 8/7, 2022 at 21:54 Comment(0)
I
3

The Office 365 Online Automate Scripts helped get me on the right path.

Docs:

https://learn.microsoft.com/en-us/javascript/api/excel/excel.pagelayoutzoomoptions?view=excel-js-preview

https://learn.microsoft.com/en-us/javascript/api/excel/excel.pagelayout?view=excel-js-preview#excel-excel-pagelayout-zoom-member

Code:

await Excel.run(async (context) => {
    var ws = context.workbook.worksheets.getActiveWorksheet();
    var PageLayoutZoomOptions_Obj = {
        'horizontalFitToPages': 1,
        'verticalFitToPages': 0,
    }
    ws.pageLayout.zoom = PageLayoutZoomOptions_Obj
    await context.sync();
});

Note: I had issues using/including scale so I just left it out.

Internationalism answered 19/7, 2022 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.