问题描述
为什么下面的代码在GSuite电子表格中返回服务器错误"?
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);
}
图像为JPEG,276KB.对于大小为173KB的图像,此代码有效.可以插入大的imageBlob吗?
The Image is JPEG, 276KB.With an image its size is 173KB, this code is working.Is it possible to insert large imageBlobs?
推荐答案
以我的经验,当按insertImage()
插入图像时,限制是由于图像区域(pixels ^ 2)而不是文件的大小它.可以插入的最大图像区域为1,048,576像素^ 2.
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.
我做了如下实验.
- 可以插入以下尺寸的图像.
- 1024像素x 1024像素
- 2048像素x 512像素
- 4096像素x 256像素
- Image with the following sizes can be inserted.
- 1024 pixels x 1024 pixels
- 2048 pixels x 512 pixels
- 4096 pixels x 256 pixels
- 1025像素x 1025像素
- 1024像素x 1025像素
- 1025像素x 1024像素
从这些结果中,我得出结论,插入图像的限制为1,048,576像素^ 2.
From these results, I concluded the limitation for inserting image is 1,048,576 pixels^2.
因此,如果要插入的图像区域大于1,048,576像素^ 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.
如果这对您的情况没有帮助,对不起.
If this was not useful for your situation, I'm sorry.
这篇关于SpreadsheetApp.insertImage服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!