Iterating through all the cells in Excel VBA or VSTO 2005

后端 未结 9 1619
既然无缘
既然无缘 2020-12-03 07:15

I need to simply go through all the cells in a Excel Spreadsheet and check the values in the cells. The cells may contain text, numbers or be blank. I am not very familiar

9条回答
  •  被撕碎了的回忆
    2020-12-03 07:57

    You basically can loop over a Range

    Get a sheet

    myWs = (Worksheet)MyWb.Worksheets[1];
    

    Get the Range you're interested in If you really want to check every cell use Excel's limits

    The Excel 2007 "Big Grid" increases the maximum number of rows per worksheet from 65,536 to over 1 million, and the number of columns from 256 (IV) to 16,384 (XFD). from here http://msdn.microsoft.com/en-us/library/aa730921.aspx#Office2007excelPerf_BigGridIncreasedLimitsExcel

    and then loop over the range

            Range myBigRange = myWs.get_Range("A1", "A256");
    
            string myValue;
    
            foreach(Range myCell in myBigRange )
            {
                myValue = myCell.Value2.ToString();
            }
    

提交回复
热议问题