0

I am trying to insert images into the google docs table and the table cells' dimensions keep changing which I don't want to happen. I have tried setting cell padding to zero and still not working. I also tried reducing the image size and that does not seem to work. Also, running my script takes a lot of time. How can I lessen the runtime of my script? Thanks in advance!


for (var i = 1; i < table.getNumRows(); i++) {
     // Check if the current row is a condition row
    if (conditionRows.indexOf(i) !== -1) {
       var row = table.getRow(i);
       // Loop through columns 0 to 4 to get the condition cells
       for (var j = 0; j < 5; j++) {
           var condition cell = row.getCell(j); 

           var condition = conditionCell.getText();
        
           var pattern = /\s{2,}/g;
           var replacement = " ";
           var replacedCondition = condition.replace(pattern, replacement);
           var inPutCondition = replacedCondition.trim().toLowerCase();
        
          // Check if the condition text is in the map
              
          if (inPutCondition in conditionImageMap) { 
          // Get the image URL from the map and insert the image in the previous row
             var fileId = conditionImageMap[inPutCondition];
             var previousRow = table.getRow(i - 1);
             var previousCell = previousRow.getCell(j);  
                    
             var file = DriveApp.getFileById(fileId);
             var imageBlob = file.getBlob();
         
             previousCell.clear();                                                  previousCell.setPaddingTop(0).setPaddingBottom(0).setPaddingRight(0).setPaddingLeft(20).insertImage(0, imageBlob).setWidth(63).setHeight(63);  
  • I have to apologize for my poor English skill. Unfortunately, I cannot imagine your situation. In order to correctly understand your question, can you provide the sample input and output situations you expect? First, I would like to correctly understand your question. – Tanaike Apr 13 '23 at 06:01
  • I have a google docs table where when users type particular words into some cells, corresponding images are inserted in other cells. I have a code for inserting the data into the table cells but when the images are loaded into the cells, the cell dimensions changes and table content overflows into another page. I do not want that to happen. Thanks. – Sangay Tshering Apr 13 '23 at 06:29
  • could you also help me to reduce the runtime in app script if its possible. I am a newbie to programming. Thanks a lot. – Sangay Tshering Apr 13 '23 at 06:31
  • Thank you for replying. I would like to support you. But, I have to apologize for my poor English skill, again. Unfortunately, from your reply, I cannot still understand your question. But I would like to try to understand it. When I could correctly understand it, I would like to think of a solution. I would be grateful if you can forgive my poor English skill. – Tanaike Apr 13 '23 at 06:51
  • no worries, this is my question in here. Basically, I want to prevent the table cell from changing its dimensions when an image is inserted using app script in Google Docs. – Sangay Tshering Apr 13 '23 at 07:03
  • Do you still not understand my question? – Sangay Tshering Apr 13 '23 at 08:03
  • About `Do you still not understand my question?`, I have to apologize for my poor English skill, again. Unfortunately, I cannot still understand your question. ut I would like to try to understand it. When I could correctly understand it, I would like to think of a solution. I would be grateful if you can forgive my poor English skill. – Tanaike Apr 13 '23 at 11:38

0 Answers0