Austin
Austin

Reputation: 35

Google Scripts to Copy Image

After the Google Scripts update, I tried to run one of mine and it gave me an error I can't figure out.

I am trying to copy an image that is a formula ( Example: =image("link here") but ever since the update it copies CellImage and does not copy the formula. I have tried a few other pieces but all seem to lead to just "CellImage" text being copied instead of the actual formula or image.

Does anyone have any ideas or know what change to implement?

function getItemName(CellName) {
 return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getValue();}

function getItemImage(CellName) {
return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getFormula();}

var item = getItem('row + column');
if (item == '') {
item = getItemImage('row + column')
}

Upvotes: 0

Views: 490

Answers (1)

Austin
Austin

Reputation: 35

It looks like previously you were able to check for text and if there was no text have it check for a formula with the below code.

function getItemName(CellName) {
 return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getValue();}

function getItemImage(CellName) {
return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getFormula();}

var item = getItem('row + column');
if (item == '') {
item = getItemImage('row + column')
}

Now you need to check if it is CellImage instead of being blank. The old script is not working properly even after changing that, but the new one I am making seems to now work properly.

function getItemName(CellName) {
 return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getValue();}

function getItemImage(CellName) {
return SpreadsheetApp.openById('Google Sheet ID').getSheetByName('Sheet1').getRange(CellName).getFormula();}

var item = getItem('row + column');
if (item == 'CellImage') {
item = getItemImage('row + column')
}

Upvotes: 0

Related Questions