{"id":6813,"date":"2024-01-02T14:47:15","date_gmt":"2024-01-02T14:47:15","guid":{"rendered":"https:\/\/www.garysieling.com\/blog\/?p=6813"},"modified":"2024-01-02T14:47:15","modified_gmt":"2024-01-02T14:47:15","slug":"import-a-folder-of-csvs-into-a-single-google-sheet-1-per-tab","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/import-a-folder-of-csvs-into-a-single-google-sheet-1-per-tab\/","title":{"rendered":"Import a folder of CSVs into a single Google Sheet (1 per tab)"},"content":{"rendered":"\n<p>Got this from ChatGPT and tested.<\/p>\n\n\n\n<p>Go to apps script:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"203\" src=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-1.png\" alt=\"\" class=\"wp-image-6814\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-1.png 343w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-1-300x178.png 300w\" sizes=\"(max-width: 343px) 100vw, 343px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1303\" height=\"362\" src=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-2-1303x362.png\" alt=\"\" class=\"wp-image-6815\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-2-1303x362.png 1303w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-2-300x83.png 300w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-2-768x214.png 768w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-2.png 1330w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Paste the script below, add your folder ID, and save. The folder ID can be obtained from the URL to the folder:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1303\" height=\"591\" src=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-3-1303x591.png\" alt=\"\" class=\"wp-image-6816\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-3-1303x591.png 1303w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-3-300x136.png 300w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-3-768x348.png 768w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2024\/01\/image-3.png 1327w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Then, click Run &#8211; you will have to go through several security prompts to agree to trust the script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function importCSVFiles() {\n  var folderId = '1_ZVuufw69Ns9ZeOCdxWwN0GqJrSl9YgO';\n  var sheet = SpreadsheetApp.getActiveSpreadsheet();\n  var folder = DriveApp.getFolderById(folderId);\n  var files = folder.getFiles();\n\n  while (files.hasNext()) {\n    var file = files.next();\n    var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());\n    var sheetName = file.getName().replace(\/\\.csv$\/, ''); \/\/ Remove '.csv' from the sheet name\n    var existingSheet = sheet.getSheetByName(sheetName);\n\n    if (existingSheet) {\n      existingSheet.clear(); \/\/ Clear existing sheet content\n    } else {\n      sheet.insertSheet(sheetName); \/\/ Create a new sheet if it doesn't exist\n    }\n\n    var targetSheet = sheet.getSheetByName(sheetName);\n    targetSheet.getRange(1, 1, csvData.length, csvData&#91;0].length).setValues(csvData);\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Got this from ChatGPT and tested. Go to apps script: Paste the script below, add your folder ID, and save. The folder ID can be obtained from the URL to the folder: Then, click Run &#8211; you will have to go through several security prompts to agree to trust the script.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6813"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=6813"}],"version-history":[{"count":1,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6813\/revisions"}],"predecessor-version":[{"id":6817,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6813\/revisions\/6817"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=6813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=6813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=6813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}