예제 #1
0
        private static void SearchByCols(ExcelFile xls, int StartRow, int EndRow, int FirstStartCol, int StartCol, int EndCol, TSearchOrReplace Action)
        {
            int RealEndRow = Math.Min(xls.RowCount, EndRow);

            for (int row = StartRow; row <= RealEndRow; row++)
            {
                int cIndex = row == StartRow?xls.ColToIndex(StartRow, FirstStartCol) : xls.ColToIndex(StartRow, StartCol);

                int ColsInRow = xls.ColCountInRow(row);
                while (cIndex <= ColsInRow)
                {
                    int XF  = -1;
                    int col = xls.ColFromIndex(row, cIndex);
                    if (col < StartCol)
                    {
                        cIndex++;
                        continue;
                    }
                    if (col > EndCol)
                    {
                        break;
                    }
                    object OldVal = xls.GetCellValueIndexed(row, cIndex, ref XF);
                    if (Action.Go(xls, OldVal, row, col))
                    {
                        return;
                    }
                    cIndex++;
                }
            }
            Action.Clear();
        }
예제 #2
0
        private static void SearchByRows(ExcelFile xls, int FirstStartRow, int StartRow, int EndRow, int StartCol, int EndCol, TSearchOrReplace Action)
        {
            int RealEndRow = Math.Min(xls.RowCount, EndRow);
            int RealEndCol = 0; //we won't use xls.ColCount as it would have to loop over all rows. We can do this here anyway.

            for (int col = StartCol; col <= EndCol; col++)
            {
                int sr;
                if (col == StartCol)
                {
                    sr = FirstStartRow;
                }
                else
                {
                    sr = StartRow;
                }

                if (col > StartCol + 1 && col > RealEndCol)
                {
                    break;
                }

                for (int row = sr; row <= RealEndRow; row++)
                {
                    if (col <= StartCol + 1) //We might start searching in the middle of a range. So we need to have at least 2 columns checked to be sure all rows have been inspected for max col.
                    {
                        int ccInRow = xls.ColFromIndex(row, xls.ColCountInRow(row));
                        if (ccInRow > RealEndCol)
                        {
                            RealEndCol = ccInRow;
                        }
                    }

                    object OldVal = xls.GetCellValue(row, col);
                    if (Action.Go(xls, OldVal, row, col))
                    {
                        return;
                    }
                }
            }
            Action.Clear();
        }