margins parameters for spreadsheet export

2019-01-26 02:26发布

I need the margins parameter to export spreadsheet as pdf.

The following parameters are working well. However I can't find margins parameter after searing.

var url_ext = 'exportFormat=pdf&format=pdf'        // export as pdf / csv / xls / xlsx
  + '&size=A4'                       // paper size legal / letter / A4
  + '&portrait=false'                    // orientation, false for landscape
  + '&fitw=true&source=labnol'           // fit to page width, false for actual size
  + '&sheetnames=false&printtitle=false' // hide optional headers and footers
  + '&pagenumbers=false&gridlines=false' // hide page numbers and gridlines
  + '&fzr=false'                         // do not repeat row headers (frozen rows) on each page
  + '&gid=';                             // the sheet's Id

2条回答
We Are One
2楼-- · 2019-01-26 02:50

Actually, it's possible to set the margins and create a PDF. You just need to know the names of the parameters and their possible values. I've have got it to work with these

Parameters:

&format=pdf                   //export format
&size=a4                      //A3/A4/A5/B4/B5/letter/tabloid/legal/statement/executive/folio
&portrait=false               //true= Potrait / false= Landscape
&scale=1                      //1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
&top_margin=0.00              //All four margins must be set!
&bottom_margin=0.00           //All four margins must be set!
&left_margin=0.00             //All four margins must be set!
&right_margin=0.00            //All four margins must be set!
&gridlines=false              //true/false
&printnotes=false             //true/false
&pageorder=2                  //1= Down, then over / 2= Over, then down
&horizontal_alignment=CENTER  //LEFT/CENTER/RIGHT
&vertical_alignment=TOP       //TOP/MIDDLE/BOTTOM
&printtitle=false             //true/false
&sheetnames=false             //true/false
&fzr=false                    //true/false
&fzc=false                    //true/false
&attachment=false             //true/false

As you can see there are more parameters for PDF formatting than currently known circulating around the Internet. Yes, it seems like they are not documented by Google.

If PDF export fails, it's probably an incorrect value. Some parameters do not have an effect on the Export. For example: your are using source=labnol, this is not a "real" parameter but it doesn't cause any trouble.

Make sure you have all four margin parameters inside your url like this:

&top_margin=0.00&bottom_margin=0.00&left_margin=0.00&right_margin=0.00

Otherwise it won't create the PDF.

Hope that helps!

查看更多
Fickle 薄情
3楼-- · 2019-01-26 02:52

I too am looking for this info. the google forum noogui mentioned is from September 2015. I mentioned in my post that the margin feature was just recently added and that there was no documentation on how to pass that parameter into the browser. It's also not a function of AppScript, we're just trying to pass a parameter through the UrlFectApp.fetch feature. If you combine the parameters you can paste it into the browser and have it export your PDF. The question is what did they name the parameter for margins and what options are available for it.

The reason my this post and mine is tagged with google-app-script is that alot of people use this these parameters with the UrlFetchApp feature and this is the best place to ask about it.

查看更多
登录 后发表回答