mogsdad / SheetConverter

Google Apps Script library - interprets Google Sheets Formats, converts to formatted text or html
49 stars 26 forks source link

Issue: getting error "Those columns are out of bounds" #20

Open manuariza opened 4 years ago

manuariza commented 4 years ago

Description of issue

When running the function I'm getting the error:

Execution failed: Those columns are out of bounds. (line 213, file "Code", project "SheetConverter") [9.712 seconds total runtime]

Seems the issue is around this part of the code:

  for (var col=startCol; col<=lastCol; col++) { 
    colWidths.push(120==sheet.getColumnWidth(col)?100:sheet.getColumnWidth(col));
    tableWidth += colWidths[colWidths.length-1];
  }

Cell Format exhibiting problem

I'm pulling the range I want to send over email in with formating this way:var range = s.getRange(4,2,s.getLastRow(),46);

If I change column 46 to column 45, the issue is solved, but it will exclude column 46 from the output. Sounds like column 46 was out of range, but it actually exists (used COLUMN() function to be sure is they right number). I also tried getMaxColumns() with the same result.

Here's the full function I'm using,

function myFunction() {
  var s = SpreadsheetApp.getActive().getSheetByName('MYSHEETNAME');
  var range = s.getRange(4,2,s.getLastRow(),46);
  var to = "MYEMAIL" ;
  var htmlTable = SheetConverter.convertRange2html(range);
    Logger.log(htmlTable);

  var body = "Launches with timeline changes:<br/><br/>"
     + htmlTable
     + "<br/><br/>"
   MailApp.sendEmail(to, 'Subject', body, {htmlBody: body})

   var rangesToClear = ["B5:AT"];   
    for (var i = 0; i < rangesToClear.length; i++){
    s.getRange(rangesToClear[i]).clearContent();
  }
}

Expected result vs Observed result

Should be getting the full range from column 2 to column 46, and from row 2 to the last empty row.

Installed Library Version

Version 6