I have this code to export my Google sheets to a 'CSV' delimited tab "|" thanks to the help @iansedano.
So this is the script:
function createCsvContent(values, delimiter) {
// This converts the values 2D array into a simple array of strings delimited by the delimiter
const stringArray = values.map(row => row.join(delimiter))
// Then it joins all the strings with newlines
const output = stringArray.join("\n")
return output
}
function createCsv() {
// Get all the values from the sheet as a 2D array
const file = SpreadsheetApp.getActive();
const sheet = file.getSheetByName("LIST");
const range = sheet.getDataRange();
const values = range.getValues();
// call the function to create the csv-like content
const csvContent = createCsvContent(values, "|")
// create the file in drive
//DriveApp.createFile('csvFile', csvContent, MimeType.PLAIN_TEXT)
DriveApp.getFileById("[10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y]").setContent(csvContent)
}
So each time I run the script, I want to overwrite this file https://docs.google.com/document/d/10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y/edit.
I cant file the proper File ID of this. If i am not wrong, this is not the file ID '10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y'.
Where i can get the real ID of the Google Doc?
If you are using the value of [10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y] as the file ID, please modify it to 10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y. Ref So, when your script is modified, it becomes as follows.
DriveApp.getFileById("[10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y]").setContent(csvContent)
DriveApp.getFileById("10eI7WAO688nQHRqj7ymscN5I5fJpP4fVTUn_qZMuq3Y").setContent(csvContent);
If you want to directly use the URL of https://docs.google.com/document/d/###/edit, you can also use the following script.
DocumentApp.openByUrl("https://docs.google.com/document/d/###/edit").getBody().setText(csvContent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With