//判断是否为三线表 是为true protected bool correctTable(DocumentFormat.OpenXml.Wordprocessing.Table t) { int tcCount = 0; IEnumerable <TableRow> trList = t.Elements <TableRow>(); int rowCount = trList.Count <TableRow>(); TableProperties tpr = t.GetFirstChild <TableProperties>(); TableBorders tb = tpr.GetFirstChild <TableBorders>(); if (tpr != null) { if (tb != null) { if (rowCount <= 2) { return(true); } foreach (TableRow tr in trList) { tcCount++; IEnumerable <TableCell> tcList = tr.Elements <TableCell>(); foreach (TableCell tc in tcList) { TableCellProperties tcp = tc.GetFirstChild <TableCellProperties>(); int bottom = 1; if (tcp != null) { TableCellBorders tcb = tcp.GetFirstChild <TableCellBorders>(); if (tcb != null) { if (tcb.GetFirstChild <LeftBorder>() != null) { if (tcb.GetFirstChild <LeftBorder>().Val != "nil") { return(false); } } if (tcb.GetFirstChild <RightBorder>() != null) { if (tcb.GetFirstChild <RightBorder>().Val != "nil") { return(false); } } //第一行 if (tcCount == 1) { if (tcb.GetFirstChild <BottomBorder>() != null) { if (tcb.GetFirstChild <BottomBorder>().Val == "nil") { bottom = 0; } } else { if (tb.GetFirstChild <InsideHorizontalBorder>() != null) { if (tb.GetFirstChild <InsideHorizontalBorder>().Val == "none") { return(false); } } } if (tcb.GetFirstChild <TopBorder>() != null) { if (tcb.GetFirstChild <TopBorder>().Val == "nil") { return(false); } } else { if (tb.GetFirstChild <TopBorder>() != null) { if (tb.GetFirstChild <TopBorder>().Val == "none") { return(false); } } } } //第二行的top if (tcCount == 2) { if (tcb.GetFirstChild <TopBorder>() != null) { if (tcb.GetFirstChild <TopBorder>().Val == "nil" && bottom == 0) { return(false); } } } //除去第一行和最后一行的其他所有行 if (tcCount != 1 && tcCount != rowCount) { if (tcb.GetFirstChild <BottomBorder>() != null) { if (tcb.GetFirstChild <BottomBorder>().Val == "single") { return(false); } } else { if (tcCount != 2 && tb.GetFirstChild <InsideHorizontalBorder>() != null && tb.GetFirstChild <InsideHorizontalBorder>().Val == "single") { return(false); } } } //最后一行并且不是第二行 if (tcCount == rowCount && tcCount != 2) { if (tcb.GetFirstChild <TopBorder>() != null) { if (tcb.GetFirstChild <TopBorder>().Val == "single") { return(false); } } else { if (tb.GetFirstChild <InsideHorizontalBorder>() != null && tb.GetFirstChild <InsideHorizontalBorder>().Val == "single") { return(false); } } if (tcb.GetFirstChild <BottomBorder>() != null) { if (tcb.GetFirstChild <BottomBorder>().Val == "nil") { return(false); } } else { if (tb.GetFirstChild <BottomBorder>() != null) { if (tb.GetFirstChild <BottomBorder>().Val == "none") { return(false); } } } } } //没有tcb的情况 else { //第一行 if (tcCount == 1) { if (tb.GetFirstChild <TopBorder>() != null) { if (tb.GetFirstChild <TopBorder>().Val == "none") { return(false); } } if (tb.GetFirstChild <InsideHorizontalBorder>() != null) { if (tb.GetFirstChild <InsideHorizontalBorder>().Val == "none") { return(false); } } } //中间行 if (tcCount != 1 && tcCount != rowCount) { if (tcCount != 2 && tb.GetFirstChild <InsideHorizontalBorder>() != null && tb.GetFirstChild <InsideHorizontalBorder>().Val == "single") { return(false); } } //最后一行 if (tcCount == rowCount && tcCount - 1 != rowCount) { if (tb.GetFirstChild <InsideHorizontalBorder>() != null && tb.GetFirstChild <InsideHorizontalBorder>().Val == "single") { return(false); } if (tb.GetFirstChild <BottomBorder>() != null) { if (tb.GetFirstChild <BottomBorder>().Val == "none") { return(false); } } } } } } } } } return(true); }