excel print setup fit width not correct

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

excel print setup fit width not correct

Postby pitc » Thu Oct 14, 2021 2:36 pm

The svyUtils$Excel provides a sheet print setup feature.
I want the excel print to fit in 1 page wide by multiple pages high as needed.
The code I have is:
Code: Select all
   var printSetup = scopes.svyExcelUtils.createPrintSetup();
   printSetup.setLandscape(true);
   printSetup.setPaperSize(scopes.svyExcelUtils.PAPER_SIZE.LETTER_PAPERSIZE);
//   printSetup.setFitHeight(1);// do not set - multiple pages high
   printSetup.setFitWidth(1);// one page wide
   
   scopes.svyExcelUtils.setDefaultPrintSetup(printSetup);


then later after creating a sheet:
Code: Select all
   var sheet = workbook.createSheet(sheet_title);
   
   sheet.setPrintSetup(printSetup);//ensures that the sheet is correctly setup


But the resultant excel file appears to not be one page wide when I print it out.
Is this a bug or do I need something else in set up?
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: excel print setup fit width not correct

Postby pitc » Wed Oct 20, 2021 4:08 am

SOLVED:
After much trial and error and researching the web for the same topic I finally found this sequence works:
Code: Select all
   
//in this EXACT order
var ps = sheet.sheet.getPrintSetup();
ps.setFitHeight(0);
ps.setFitWidth(1);


Oh Yes and if you want to see grid lines:
Code: Select all
   
sheet.sheet.setDisplayGridlines(true);//for display
sheet.sheet.setPrintGridlines(true);// for printing


(Yes that is correct: sheet.sheet has methods...
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 14 guests