Forum Discussion

robert_L's avatar
robert_L
Occasional Contributor
11 years ago
Solved

how to get the max number of columns used/populated in spreadsheet (and not the excel max column limit)?





Hello,



I'm using the ExcelCompare Script Extension that is referenced in the Compare Excel Files article (http://support.smartbear.com/viewarticle/9046/).

In it, there is a function named CreateInfo.



In an excerpt from this function:



var vSheet = Sys.OleObject("Scripting.Dictionary");

    var rowCount = oSheet.UsedRange.Rows.Count;

    for (var rowId = 1; rowId < rowCount + 1; rowId++)

    {

      var rowObj = oSheet.Rows.Item(rowId);

      var vRow = Sys.OleObject("Scripting.Dictionary");

      var cellCount = rowObj.Cells.Count;

      for (var cellId = 1; cellId < cellCount + 1; cellId++)


      {

        var cellObj = rowObj.Cells.Item(cellId);

        vRow.Add(cellObj.Column, cellObj.Text);

      }

      vSheet.Add(rowId, vRow);

    }



The line

var cellCount = rowObj.Cells.Count;

appears to get the max column value of the Excel spreadsheet, which equals 16384. 

Is there a way to just get the maximum number of columns used/populated in the spreadsheet (and not the excel max column limit)?



Thanks,

Rob



 
  • Yes you could use oSheet.UsedRange.Columns.Count