-1

I know what I want to do but I can't figure out where to start I'm afraid.

  • do I need python?
  • or can Excel or Google Sheets do this with a script?

  1. In a Google sheet which stores data on 100 products in our forthcoming e-commerce store, I have 100 images, each with a unique URL in Col A.

    Each product has an image pointing to our Google docs, eg <a href="https://drive.google.com/open?id=XXX>...`

  2. I want to rename those images with the product code of each image, in Col B, for example, VFBARCL-70.jpg, and save in a new folder in Google docs, so we can upload the images via our CSV file to the WooCommerce store.

  3. As a separate question, how can Excel open an image in Excel, from its URL?

Please, can someone help?

I've looked at download list of images from urls but this doesn't help, and I found this code:

function convertToImage() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var range = sheet.getDataRange(); 
  var colnum = 3;             // assuming column C; change to another column number
  var cell;
  var values = range.getValues(); 
  for (var i=0; i<values.length; i++) {
    if (values[i][colnum-1]) {
      cell = range.getCell(i+1, colnum);
      cell.setFormula('=image("'+values[i][colnum-1]+'")')
    }
  } 
}

Which at least opens the URLs as images in Google, but I don't know how to (i) run the script, and (ii) modify it to rename and resave the images into a different folder.

Community
  • 1
  • 1
SJJHR
  • 9
  • 3

1 Answers1

0

Copy, Move and Rename Images based on values in a Spreadsheet

This is very similar to what you want to do:

function copyMoveAndRenameImages() {
  var srcfldr=DriveApp.getFolderById('source folder id');//source folder
  var desfldr=DriveApp.getFolderById('destination folder Id');//destination folder
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Sheet94');//put your sheetname here
  var rg=sh.getRange(1,1,sh.getLastRow(),2);//getting data in columns 1 and 2
  var vA=rg.getValues();
  var files=srcfldr.getFiles();//getting files in sources folder
  while(files.hasNext()) {
    var file=files.next();
    if(file.getName().slice(0,3)=='die') {//I am picking files with a certain name
      for(var i=0;i<vA.length;i++) {
        if(vA[i][0]==file.getName().slice(0,4)) {//if filename = value in column 1
        //In your case you will compare image url to url in column1 I think
          file.makeCopy(Utilities.formatString('%s.jpg', vA[i][1]),desfldr);
        }
      }
    }
  }  
}

This is what my spreadsheet looks like:

enter image description here

I think this is close to what you want but I will require more information about the urls and how to correlate the image names to the desired new image names.

Cooper
  • 59,616
  • 6
  • 23
  • 54