3

We have some marketing software that pulls reports on email marketing and uploads a CSV automatically every week or month into our Google Drive. Our reporting software can't automatically pull data from a CSV, so I have to use Google Sheets.

How can I make it so that when a new CSV is uploaded onto the Drive (replacing the old CSV in the process), my Google Sheet will pull the new data and replace it over the old data?

Alex Jennings
  • 31
  • 1
  • 2
  • Have you checked the solution in this [SO post](https://stackoverflow.com/questions/26854563/how-to-automatically-import-data-from-uploaded-csv-or-xls-file-into-google-sheet)? I think this is what you are looking for. – MαπμQμαπkγVπ.0 Mar 09 '18 at 08:00
  • Hey Alex, I was wondering if you still had this problem. If so, I can help solve it for you. Let me know via replies! – Maximus S Apr 24 '19 at 23:20

1 Answers1

0

The question isn't clear, meaning there are many "variables" to your question, and thus a variety of solutions which you can implement to solve the specific permutation you're looking for. But I'll try to answer your question with some considerations and suggestions:

  1. "[A] new CSV is uploaded onto the Drive (replacing the old CSV in the process)." Are you sure this is happening? Every time you upload, say a hello.csv to Drive, it adds a new hello.csv file one rather than replacing an existing one with the same name. You would have to have an application that knows or can look up the original CSV Drive file ID and explicitly replace the file contents or upload a new version of that file.
  2. If you do replace the original file via one of those two techniques, track the changes to that file via the Drive API, meaning your app can take action as soon as that file has been updated. See this page in the docs to learn how to detect changes.
  3. The comment in the OP makes a suggestion from another SO Q&A, however that solution does not address the OP's question. Instead, it imports a CSV file to Google Drive as a Google Sheets (file) -- the CSV file never makes it to Drive as per the OP. Also, the OP is requesting something more than a mere import.
  4. However, with that said, the OP's final request was: "[My] Google Sheet will pull the new data and replace it over the old data." There are 2 ways to do this:

a) The simplest/easiest way is to just overwrite all existing data in the Sheet with what's in the CSV file... old data, new data, it doesn't matter. Once the new CSV file has been imported and new Sheets file created, you can delete both the old CSV and corresponding Sheet. The (new) files can have the same names as their predecessors no problem. For that, build a solution similar to the SO Q&A mentioned above -- the CSV file will already be in Drive, so just create a new Sheets file and use the content from the CSV file on Drive (rather than from the local filesystem).

b) If you only want the deltas, you need to keep a copy of the old CSV and "diff" it with the new CSV, and only overwrite the rows that have changed, a much more complex solution, and one in which you'll have to use the Google Sheets API (because it's for spreadsheet operations while the Drive API is used for file operations).

wescpy
  • 10,689
  • 3
  • 54
  • 53
  • 1
    To answer your #1, when the CSV is uploaded automatically, Google Drive recognizes it has the same name as the old file and therefore replaces it, but the new CSV and old CSV have different file IDs, technically different files completely even though the old one is deleted. – Alex Jennings Mar 13 '18 at 13:08