Google-sheets – PDF shows only top row of spreadsheet

google sheetsgoogle-apps-scriptpdf

I am attempting to export a spreadsheet which is "created" daily through an automated e-mail in Google Apps Script. When attempting to convert to PDF I only get the top row shown in the PDF document (none of the data).

var file = DriveApp.getFileById(spreadsheet.getId()).getAs(MimeType.PDF);

  MailApp.sendEmail('email', 'Equipment Update', 'Spreadsheet Attached', {
name: 'Testing',
attachments: [file]
  });

I have checked and the spreadsheet does have the appropriate list of information on the sheet which is to be exported.

Any ideas as to what might be causing this?

Best Answer

It appears you were trying to convert a spreadsheet to PDF immediately after it was filled with data. This is sometimes an issue because the data may be stuck in a pipeline: the changes are not immediately applied for performance reasons. Use the command

SpreadsheetApp.flush();

before conversion to PDF, to make sure any pending changes are applied. Reference.