python - openpyxl Page Setup "Fit To" vs "Adjust To" -


i'm trying set worksheet automatically fit columns on 1 page using openpyxl. way have approached set fittowidth property , fittoheight property. far can modify page setup have fittowidth value of 1 , fittoheight value of 0 when open spreadsheet, still in "adjust to" selection , not "fit to" selection fittowidth , fittoheight values have been applied. how can change selection in page setup "fit to" instead of "adjust to"?

i think pagesetup.zoom property needs false can't figure out how openpyxl. here's msdn article on it: https://msdn.microsoft.com/en-us/library/office/ff197028.aspx

here code far:

from openpyxl import load_workbook wb = load_workbook('test.xlsx') ws.page_setup.orientation = ws.orientation_landscape ws.page_setup.fittowidth = 1 ws.page_setup.fittoheight = 0 ws.sheet_view.view = "pagelayout" 

thanks!

the following works me:

import openpyxl, os  f = r'test.xlsx' wb = openpyxl.load_workbook(f) ws = wb.active  ws.sheet_properties.pagesetuppr.fittopage = true ws.page_setup.fittoheight = false  wb.save(f) 

of course, if wanted fit height 1 page , didn't care number of pages wide, replace

ws.page_setup.fittoheight = false 

with

ws.page_setup.fittowidth = false 

if want entire worksheet on single page, drop 'ws.page_setup...' line entirely.

if want height/width fit on, example, 3 pages, use:

ws.page_setup.fittowidth = 3 

but, key element struggled have set ws.sheet_properties.pagesetuppr.fittopage = true prior setting fittoheight and/or fittowidth properties.

you not need set scale percentage explicitly. undo settings here.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -