Skip to content

Instantly share code, notes, and snippets.

@bpwebs
Last active November 21, 2023 01:02
Show Gist options
  • Save bpwebs/90d562b852e0518b73f192f6fbdb2a2e to your computer and use it in GitHub Desktop.
Save bpwebs/90d562b852e0518b73f192f6fbdb2a2e to your computer and use it in GitHub Desktop.
Combine CSV Files with Google Apps Script - Prevent the column headers from being repeated in the merged CSV file
function combineCSVWithoutRepeatedHeaders() {
const folder = DriveApp.getFolderById("1MBaI_rGJ6t_loANMAvGpDbr2MeHZwxnn");
const files = folder.getFilesByType(MimeType.CSV);
let combinedData = [];
let firstFile = true;
while (files.hasNext()) {
let file = files.next();
let csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
if (firstFile) {
firstFile = false; // Skip headers for the first file
} else {
csvData.shift(); // Remove headers for subsequent files
}
combinedData = combinedData.concat(csvData);
}
folder.createFile("Combined1.csv", combinedData.join("\n"), MimeType.CSV);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment