Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

google apps script - SpreadsheetApp.insertImage server error

Why the below code return 'server error' in GSuite Spreadsheet?

function test() {
  var ss = SpreadsheetApp.openById('1Wc6nKxxxxxxxxxxxxxxxxxx0Ld6QyaY');
  var sheet = ss.getSheetByName('2018.0801-0831');
  var img = DriveApp.getFileById('1qw2uy3cNxxxxxxxxxxxxxxxxxDZRES');
  var imgBlob = img.getBlob();
  sheet.insertImage(imgBlob, 9, 20);
}

The Image is JPEG, 276KB. With an image its size is 173KB, this code is working. Is it possible to insert large imageBlobs?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In my experience, when an image is inserted by insertImage(), the limitation is due to the image area (pixels^2) rather than the file size of it. The maximum area of image which can be inserted is 1,048,576 pixels^2.

I have experimented as follows.

  • Image with the following sizes can be inserted.
    • 1024 pixels x 1024 pixels
    • 2048 pixels x 512 pixels
    • 4096 pixels x 256 pixels
  • Image with the following sizes can NOT be inserted.
    • 1025 pixels x 1025 pixels
    • 1024 pixels x 1025 pixels
    • 1025 pixels x 1024 pixels

From these results, I concluded the limitation for inserting image is 1,048,576 pixels^2.

So if the area of image you want to insert is more than 1,048,576 pixels^2, please resize it and try again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...