Esempio n. 1
0
        public HtmlTable GetDataFromHtmlTable(HTMLTableClass tableCalss)
        {
            HtmlTable    table     = new HtmlTable();
            HtmlTableRow headerRow = new HtmlTableRow();
            int          rowIndex  = 0;

            foreach (HTMLTableRowClass row in tableCalss.rows)
            {
                // table header
                if (rowIndex == 0)
                {
                    int columnIndex = 0;
                    foreach (HTMLTableCellClass cell in row.cells)
                    {
                        if (null != cell.innerText)
                        {
                            HtmlTableCell newCell = new HtmlTableCell();
                            newCell.CellName        = cell.innerText;
                            newCell.CellColumnIndex = columnIndex;
                            newCell.CellValue       = null;
                            headerRow.Cells.Add(newCell);
                        }
                        columnIndex++;
                    }
                }
                else
                {
                    // table body
                    HtmlTableRow newRow = new HtmlTableRow();
                    newRow.RowIndex = --rowIndex;
                    int columnIndex = 0;
                    foreach (HTMLTableCellClass cell in row.cells)
                    {
                        if (null != cell.innerText)
                        {
                            HtmlTableCell newCell = new HtmlTableCell();
                            newCell.CellName        = headerRow.Cells[columnIndex].CellName;
                            newCell.CellColumnIndex = columnIndex;
                            newCell.CellValue       = cell.innerText;
                            newRow.Cells.Add(newCell);
                        }
                        columnIndex++;
                    }
                    table.HtmlTableRows.Add(newRow);
                }
                rowIndex++;
            }
            return(table);
        }
Esempio n. 2
0
        public HTMLTableClass FindTableFromDocument(HTMLDocument doc, string tableId)
        {
            HTMLTableClass findTable = null;

            HTMLBodyClass bodyClass = (HTMLBodyClass)doc.body;

            IHTMLElementCollection tableElementCollection = bodyClass.getElementsByTagName("table");

            foreach (HTMLTableClass table in tableElementCollection)
            {
                if (null != table.id && table.id.Equals(tableId))
                {
                    findTable = table;
                    break;
                }
            }
            return(findTable);
        }
Esempio n. 3
0
        /// <summary>
        /// Find the index of given table within the document DOM tree.
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private int FindTableIndex(HTMLTableClass table) {
            int idx = -1;
            HTMLDocumentClass doc = table.ownerDocument as HTMLDocumentClass;
            if( doc == null) {
                return -1;
            }

            IHTMLElementCollection eList = doc.all.tags("TABLE") as IHTMLElementCollection;
            if ( eList == null ) {
                return -1;
            }

            IEnumerator it = eList.GetEnumerator();
            while ( it.MoveNext() ) {
                HTMLTableClass e2 = it.Current as HTMLTableClass;
                if ( e2 != null ) {
                    idx++;
                    if ( e2.Equals(table) ) { // This works in deed.
                        return idx;
                    }
                }
            }
            return -1;
        }