title: Extract text from several Google docs into Google Spreadsheet
body: <p>I am trying to extract the text from each Google document in a folder in Drive and paste the text into the first column of a Google spreadsheet so that the contents of file 1 are in A1, the contents of file 2 in A2 etc. Ultimately I am trying to recreate a database of the information stored in all these files, so if the text can be split by field so much the better, but I think this should be trivial in Excel using Text to Columns.</p>
  
  <p>I have used a few snippets online to have a stab at it but I'm now stumped.</p>
  
  <p>Here is my script as it stands:</p>
  
  <pre><code>//Function to extract the body from each document in a folder and copy it to a spreadsheet
  function extract() {
  
  //Define the folder we're working with ("Communication Passports") and get the file list
  var folder = DocsList.getFolder("Communication Passports");
  var contents = folder.getFiles();
  
  //Define the destination spreadsheet file (CP) and set up the sheet to receive the data
  
  var ss = SpreadsheetApp.openById("0AicdFGdf-Cx5dHFTX1R3Wm1RTEFTZ2d5ZmxuSjJSOHc");
  SpreadsheetApp.setActiveSpreadsheet(ss);
  Logger.log('File name: ' + ss.getName()); 
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.clear();
  sheet.appendRow(["Name", "Date", "Contents", "URL", "Download", "Description"]);
  
  //Set up other variables
  var file;
  var data;
  
  //Loop through and collect the data (I don't actually need this - just borrowed the code from    a   snippet online - but it is SO CLOSE!)
  //Sadly, getBody doesn't work on files, only on documents
  for (var i = 0; i &lt; contents.length; i++) {
  file = contents[i];
  
  data = [ 
    file.getName(),
    file.getDateCreated(),
    file.getViewers(),
    file.getUrl(),
    "https://docs.google.com/uc?export=download&amp;confirm=no_antivirus&amp;id=" + file.getId(),
    file.getDescription()
  ];
  
  sheet.appendRow(data);
  
  
  //Extract the text from the file (this doesn't work at present, but is what I actually need)
  
  
  var doc = DocumentApp.openById(file.getId());
  var body = doc.getBody();
  
  //Find a way to paste the extracted body text to the spreadsheet
  }
  };
  </code></pre>
  
  <p>Any help would be very gratefully received - I'm not a programmer, I'm a teacher and the information is about children's learning needs at our school (someone deleted the database over summer and our backups only go back a month!).</p>
  
  <p>Thanks,</p>
  
  <p>Simon</p>