예제 #1
0
        private int InsertCellAtIndex(IList <IHtmlCell> cells, IHtmlCell cell, int index = -1)
        {
            int wantedindex = index;

            if (wantedindex < 0)
            {
                for (int i = 0; i < cells.Count; i++)
                {
                    if (cells[i] == null)
                    {
                        wantedindex = i;
                        break;
                    }
                }
                if (wantedindex < 0)
                {
                    wantedindex = cells.Count;
                }
            }

            for (int i = cells.Count; i <= wantedindex; i++)
            {
                cells.Add(null);
            }

            cells[wantedindex] = cell;
            return(wantedindex);
        }
예제 #2
0
파일: HtmlTest.cs 프로젝트: FleurLotus/MPSD
        public void TestExtractCell(string text, string expectedText, int expectedRowSpan, int expectedColSpan, bool expectedIsHeader)
        {
            IHtmlCell cell = HtmlTableParser.ExtractCell(text);

            if (cell.InnerText != expectedText)
            {
                throw new Exception(string.Format("The found InnerText {0} is differente from the excepted one {1} for {2}", cell.InnerText, expectedText, text));
            }

            if (cell.IsHeader != expectedIsHeader)
            {
                throw new Exception(string.Format("The found IsHeader {0} is differente from the excepted one {1} for {2}", cell.IsHeader, expectedIsHeader, text));
            }

            if (cell.RowSpan != expectedRowSpan)
            {
                throw new Exception(string.Format("The found RowSpan {0} is differente from the excepted one {1} for {2}", cell.RowSpan, expectedRowSpan, text));
            }

            if (cell.ColSpan != expectedColSpan)
            {
                throw new Exception(string.Format("The found ColSpan {0} is differente from the excepted one {1} for {2}", cell.ColSpan, expectedColSpan, text));
            }
        }
예제 #3
0
파일: HtmlTest.cs 프로젝트: FleurLotus/MPSD
        public void TestCellsInfos()
        {
            //Test when table is not the first caracters
            //Row 1 : test header
            //Row 2 : test cell
            //Row 3 : test colspan
            //Row 4-5: test rowspan and next row completion
            //Row 6-7: test rowspan and next row missing data
            //Row 8-9: test rowspan and colspan averlap
            //Row 10-13: test multi rowspan with overlap

            IHtmlTable ret = HtmlTableParser.Parse(@"azertyui 
<Table>
<TR><TH>H1</TH><TH>H2</TH></TR>
<TR><TD>C11</TD><TD>C12</TD></TR>

<TR><TD colspan=2>C21</TD><TD>C23</TD></TR>

<TR><TD>C31</TD><TD rowspan=2>C32</TD></TR>
<TR><TD>C41</TD><TD>C43</TD></TR>

<TR><TD>C51</TD><TD rowspan=2>C52</TD></TR>
<TR></TR>

<TR><TD>C71</TD><TD rowspan=2>C72</TD></TR>
<TR><TD colspan=2>C81</TD><TD>C83</TD></TR>

<TR><TD rowspan=3 colspan=3>C91</TD></TR>
<TR><TD rowspan=3 colspan=3>CA4</TD></TR>
</Table>");

            Assert.IsNotNull(ret, "ret must be not null");

            Assert.AreEqual(ret.RowCount, 13, "RowCount must be 13");

            string[,] expectedValue =
            {
                { "H1",  "H2",  null,  null,  null,  null,  null },
                { "C11", "C12", null,  null,  null,  null,  null },
                { "C21", "C21", "C23", null,  null,  null,  null },
                { "C31", "C32", null,  null,  null,  null,  null },
                { "C41", "C32", "C43", null,  null,  null,  null },
                { "C51", "C52", null,  null,  null,  null,  null },
                { null,  "C52", null,  null,  null,  null,  null },
                { "C71", "C72", null,  null,  null,  null,  null },
                { "C81", "C81", "C83", null,  null,  null,  null },
                { "C91", "C91", "C91", null,  null,  null,  null },
                { "C91", "C91", "C91", "CA4", "CA4", "CA4", null },
                { "C91", "C91", "C91", "CA4", "CA4", "CA4", null },
                { null,  null,  null,  "CA4", "CA4", "CA4", null }
            };


            for (int i = 0; i < expectedValue.GetLength(0); i++)
            {
                for (int j = 0; j < expectedValue.GetLength(1); j++)
                {
                    IHtmlCell cell  = ret[i, j];
                    string    value = cell?.InnerText;
                    Assert.AreEqual(expectedValue[i, j], value, "Value different for ({0},{1}) : {2} vs {3}", i, j, value, expectedValue[i, j]);
                    Assert.AreEqual(cell?.ToString(), value);
                }
            }
        }