I have the following data in my Spreadsheet
Since the latest doc_no
is TRY/2024/05/06/0707857126
, I want to generate a PDF according to that number. Here’s the PDF Spreadsheet:
I’m able to generate the spreadsheet according to the latest data. Now i want to export them as PDF by using the following script:
let url = "https://docs.google.com/spreadsheets/d/" + sheetExportId + "/export" +
"?format=pdf" +
"&size=A4" +
"&portrait=true" +
"&fitw=true" +
"&sheetnames=false" +
"&printtitle=false" +
"&pagenumbers=false" +
"&gridlines=false" +
"&fzr=true" +
"&gid=" + sheetId;
let token = ScriptApp.getOAuthToken();
let response = UrlFetchApp.fetch(url, {
headers: {
Authorization: "Bearer " + token
}
});
let blob = response.getBlob().setName(pdfName);
let folder = DriveApp.getFolderById(folderPdfId); // Change this to the desired folder
// Check if a file with the same name already exists and delete it
let existingFiles = folder.getFilesByName(blob.getName());
if (existingFiles.hasNext()) {
let existingFile = existingFiles.next();
existingFile.setTrashed(true); // Move the existing file to trash
}
let pdfFile = folder.createFile(blob);
console.log(`Sending email to ${emailRecipient}`);
MailApp.sendEmail({
to: emailRecipient,
subject: emailSubject,
body: emailBody,
attachments: [pdfFile.getAs(MimeType.PDF)]
});
The email sent with false data. The sent data was TRY/2024/05/06/0707431726
. What i expect is TRY/2024/05/06/0707857126
.
The problem is, why did PDF spreadsheet export the spreadsheet with TRY/2024/05/06/0707431726
not TRY/2024/05/06/0707857126
.
how do i resolve this?