예제 #1
0
        /**
         * Gets the named range from this workbook.  The Range object returns
         * contains all the cells from the top left to the bottom right
         * of the range.
         * If the named range comprises an adjacent range,
         * the Range[] will contain one object; for non-adjacent
         * ranges, it is necessary to return an array of length greater than
         * one.
         * If the named range contains a single cell, the top left and
         * bottom right cell will be the same cell
         *
         * @param name the name to find
         * @return the range of cells
         */
        public override Range[] findByName(string name)
        {
            if (!namedRecords.ContainsKey(name))
            {
                return(null);
            }

            NameRecord nr = namedRecords[name];

            NameRecord.NameRange[] ranges = nr.getRanges();

            Range[] cellRanges = new Range[ranges.Length];

            for (int i = 0; i < ranges.Length; i++)
            {
                cellRanges[i] = new RangeImpl
                                    (this,
                                    getExternalSheetIndex(ranges[i].getExternalSheet()),
                                    ranges[i].getFirstColumn(),
                                    ranges[i].getFirstRow(),
                                    getLastExternalSheetIndex(ranges[i].getExternalSheet()),
                                    ranges[i].getLastColumn(),
                                    ranges[i].getLastRow());
            }

            return(cellRanges);
        }
예제 #2
0
        /**
         * Gets the named cell from this workbook.  If the name refers to a
         * range of cells, then the cell on the top left is returned.  If
         * the name cannot be found, null is returned
         *
         * @param  name the name of the cell/range to search for
         * @return the cell in the top left of the range if found, NULL
         *         otherwise
         */
        public override Cell findCellByName(string name)
        {
            if (!namedRecords.ContainsKey(name))
            {
                return(null);
            }

            NameRecord nr = namedRecords[name];

            NameRecord.NameRange[] ranges = nr.getRanges();

            // Go and retrieve the first cell in the first range
            Sheet s   = getSheet(getExternalSheetIndex(ranges[0].getExternalSheet()));
            int   col = ranges[0].getFirstColumn();
            int   row = ranges[0].getFirstRow();

            // If the sheet boundaries fall short of the named cell, then return
            // an empty cell to stop an exception being thrown
            if (col > s.getColumns() || row > s.getRows())
            {
                return(new EmptyCell(col, row));
            }

            Cell cell = s.getCell(col, row);

            return(cell);
        }