Example #1
0
 /// <summary>
 /// Release the resources.
 /// </summary>
 public void Dispose() {
     _table.Dispose();
     _table = null;
     _rowsall = null;
     _rowswhere = null;
     _cells = null;
 }
Example #2
0
 /// <summary>
 /// Creates a new Table object.
 /// </summary>
 public Table()
 {
     _table     = null;
     _rowsall   = null;
     _rowswhere = null;
     _cells     = null;
 }
Example #3
0
 /// <summary>
 /// Release the resources.
 /// </summary>
 public void Dispose()
 {
     _table.Dispose();
     _table     = null;
     _rowsall   = null;
     _rowswhere = null;
     _cells     = null;
 }
Example #4
0
        /// <summary>
        /// Loads the data from the source. Can be an excel address or a range.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="hasHeaders"></param>
        /// <returns><see cref="Table"/></returns>
        public Table From(object source, bool hasHeaders = true) {
            try {
                IRange range = ExcelExt.GetRange(source);
                if (range.Count == 1) {
                    IListObject listObject = range.ListObject;
                    if (listObject != null) {
                        IExcel excel = range.Application;
                        range = excel[listObject.HeaderRowRange, listObject.DataBodyRange];
                    } else {
                        range = range.CurrentRegion;
                    }
                }

                var values = (object[,])range.Value2 ?? new object[1, 1];
                int clen = values.GetLength(1);
                int rlen = values.GetLength(0);

                _table = new System.Data.DataTable();
                _columns = _table.Columns;
                int irow = hasHeaders ? 2 : 1;
                for (var icol = 0; icol++ < clen; ) {
                    Type coltype = GetColumnType(values, irow, icol);

                    object colvalue = hasHeaders ?
                        values[1, icol]
                        : (icol + 1);

                    string colname = colvalue == null ?
                        string.Empty
                        : colvalue.ToString();

                    _columns.Add(new System.Data.DataColumn(colname, coltype));
                }

                _rowsall = _table.Rows;
                for (int r = hasHeaders ? 1 : 0; r++ < rlen; ) {
                    System.Data.DataRow row = _table.NewRow();
                    for (var c = 0; c < clen; c++)
                        row[c] = values[r, c + 1];

                    _rowsall.Add(row);
                }

                _hasheaders = hasHeaders;
                _cells = (ICells)range;
                return this;
            } catch (SeleniumException) {
                throw;
            } catch (Exception ex) {
                throw new SeleniumException(ex);
            }
        }
Example #5
0
 /// <summary>
 /// Creates a new Table object.
 /// </summary>
 public Table() {
     _table = null;
     _rowsall = null;
     _rowswhere = null;
     _cells = null;
 }
Example #6
0
        /// <summary>
        /// Loads the data from the source. Can be an excel address or a range.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="hasHeaders"></param>
        /// <returns><see cref="Table"/></returns>
        public Table From(object source, bool hasHeaders = true)
        {
            try {
                IRange range = ExcelExt.GetRange(source);
                if (range.Count == 1)
                {
                    IListObject listObject = range.ListObject;
                    if (listObject != null)
                    {
                        IExcel excel = range.Application;
                        range = excel[listObject.HeaderRowRange, listObject.DataBodyRange];
                    }
                    else
                    {
                        range = range.CurrentRegion;
                    }
                }

                var values = (object[, ])range.Value2 ?? new object[1, 1];
                int clen   = values.GetLength(1);
                int rlen   = values.GetLength(0);

                _table   = new System.Data.DataTable();
                _columns = _table.Columns;
                int irow = hasHeaders ? 2 : 1;
                for (var icol = 0; icol++ < clen;)
                {
                    Type coltype = GetColumnType(values, irow, icol);

                    object colvalue = hasHeaders ?
                                      values[1, icol]
                        : (icol + 1);

                    string colname = colvalue == null ?
                                     string.Empty
                        : colvalue.ToString();

                    _columns.Add(new System.Data.DataColumn(colname, coltype));
                }

                _rowsall = _table.Rows;
                for (int r = hasHeaders ? 1 : 0; r++ < rlen;)
                {
                    System.Data.DataRow row = _table.NewRow();
                    for (var c = 0; c < clen; c++)
                    {
                        row[c] = values[r, c + 1];
                    }

                    _rowsall.Add(row);
                }

                _hasheaders = hasHeaders;
                _cells      = (ICells)range;
                return(this);
            } catch (SeleniumException) {
                throw;
            } catch (Exception ex) {
                throw new SeleniumException(ex);
            }
        }