public XWPFTable(CT_Tbl table, IBody part) { this.part = part; this.ctTbl = table; tableRows = new List<XWPFTableRow>(); // is an empty table: I add one row and one column as default if (table.SizeOfTrArray() == 0) CreateEmptyTable(table); foreach (CT_Row row in table.GetTrList()) { StringBuilder rowText = new StringBuilder(); row.Table = table; XWPFTableRow tabRow = new XWPFTableRow(row, this); tableRows.Add(tabRow); foreach (CT_Tc cell in row.GetTcList()) { cell.TableRow = row; foreach (CT_P ctp in cell.GetPList()) { XWPFParagraph p = new XWPFParagraph(ctp, part); if (rowText.Length > 0) { rowText.Append('\t'); } rowText.Append(p.GetText()); } } if (rowText.Length > 0) { this.text.Append(rowText); this.text.Append('\n'); } } }
/// <summary> /// Get the TableCell which belongs to the TableCell /// </summary> /// <param name="cell"></param> /// <returns></returns> public XWPFTableCell GetTableCell(CT_Tc cell) { object obj = cell.Parent; if (!(obj is CT_Row)) { return(null); } CT_Row row = (CT_Row)obj; if (!(row.Parent is CT_Tbl)) { return(null); } CT_Tbl tbl = (CT_Tbl)row.Parent; XWPFTable table = GetTable(tbl); if (table == null) { return(null); } XWPFTableRow tableRow = table.GetRow(row); if (row == null) { return(null); } return(tableRow.GetTableCell(cell)); }
public XWPFTableRow CloneRow() { XWPFTableRow clonedRow = new XWPFTableRow(ctRow.Copy(), this.table); table.AddRow(clonedRow); return(clonedRow); }
public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) { this.ctTc = cell; this.part = part; this.tableRow = tableRow; if (cell.GetPList().Count < 1) { cell.AddNewP(); } this.bodyElements = new List <IBodyElement>(); this.paragraphs = new List <XWPFParagraph>(); this.tables = new List <XWPFTable>(); foreach (object obj in this.ctTc.Items) { if (obj is CT_P) { XWPFParagraph xwpfParagraph = new XWPFParagraph((CT_P)obj, (IBody)this); this.paragraphs.Add(xwpfParagraph); this.bodyElements.Add((IBodyElement)xwpfParagraph); } if (obj is CT_Tbl) { XWPFTable xwpfTable = new XWPFTable((CT_Tbl)obj, (IBody)this); this.tables.Add(xwpfTable); this.bodyElements.Add((IBodyElement)xwpfTable); } } }
/** * Get the TableCell which belongs to the TableCell */ public XWPFTableCell GetTableCell(CT_Tc cell) { if (!(cell.Parent is CT_Row)) { return(null); } CT_Row row = (CT_Row)cell.Parent; if (!(row.Parent is CT_Tbl)) { return(null); } CT_Tbl tbl = (CT_Tbl)row.Parent; XWPFTable table = GetTable(tbl); if (table == null) { return(null); } XWPFTableRow tr = table.GetRow(row); if (tr == null) { return(null); } return(tr.GetTableCell(cell)); }
public void TestSetGetVertAlignment() { // instantiate the following classes so they'll Get picked up by // the XmlBean process and Added to the jar file. they are required // for the following XWPFTableCell methods. CT_Shd ctShd = new CT_Shd(); Assert.IsNotNull(ctShd); CT_VerticalJc ctVjc = new CT_VerticalJc(); Assert.IsNotNull(ctVjc); ST_Shd stShd = ST_Shd.nil; Assert.IsNotNull(stShd); ST_VerticalJc stVjc = ST_VerticalJc.top; Assert.IsNotNull(stVjc); // create a table XWPFDocument doc = new XWPFDocument(); CT_Tbl ctTable = new CT_Tbl(); XWPFTable table = new XWPFTable(ctTable, doc); // table has a single row by default; grab it XWPFTableRow tr = table.GetRow(0); Assert.IsNotNull(tr); // row has a single cell by default; grab it XWPFTableCell cell = tr.GetCell(0); cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH); XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment().Value; Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al); }
public XWPFTableRow CreateRow() { int sizeCol = this.ctTbl.SizeOfTrArray() > 0 ? this.ctTbl.GetTrArray(0).SizeOfTcArray() : 0; XWPFTableRow tabRow = new XWPFTableRow(this.ctTbl.AddNewTr(), this); this.AddColumn(tabRow, sizeCol); this.tableRows.Add(tabRow); return(tabRow); }
private void AddColumn(XWPFTableRow tabRow, int sizeCol) { if (sizeCol > 0) { for (int i = 0; i < sizeCol; i++) { tabRow.CreateCell(); } } }
/** * inserts a new tablerow * @param pos * @return the inserted row */ public XWPFTableRow InsertNewTableRow(int pos) { if (pos >= 0 && pos <= tableRows.Count) { CT_Row row = ctTbl.InsertNewTr(pos); XWPFTableRow tableRow = new XWPFTableRow(row, this); tableRows.Insert(pos, tableRow); return(tableRow); } return(null); }
private void AddColumn(XWPFTableRow tabRow, int sizeCol) { if (sizeCol <= 0) { return; } for (int index = 0; index < sizeCol; ++index) { tabRow.CreateCell(); } }
public bool AddRow(XWPFTableRow row, int pos) { if (pos < 0 || pos > this.tableRows.Count) { return(false); } this.ctTbl.InsertNewTr(pos); this.ctTbl.SetTrArray(pos, row.GetCtRow()); this.tableRows.Insert(pos, row); return(true); }
/** * add a new Row to the table * at position pos * @param row the row which should be Added */ public bool AddRow(XWPFTableRow row, int pos) { if (pos >= 0 && pos <= tableRows.Count) { ctTbl.InsertNewTr(pos); ctTbl.SetTrArray(pos, row.GetCTRow()); tableRows.Insert(pos, row); return(true); } return(false); }
public XWPFTableRow InsertNewTableRow(int pos) { if (pos < 0 || pos > this.tableRows.Count) { return((XWPFTableRow)null); } XWPFTableRow xwpfTableRow = new XWPFTableRow(this.ctTbl.InsertNewTr(pos), this); this.tableRows.Insert(pos, xwpfTableRow); return(xwpfTableRow); }
/** * add a new column for each row in this table */ public void AddNewCol() { if (ctTbl.SizeOfTrArray() == 0) { CreateRow(); } for (int i = 0; i < ctTbl.SizeOfTrArray(); i++) { XWPFTableRow tabRow = new XWPFTableRow(ctTbl.GetTrArray(i), this); tabRow.CreateCell(); } }
public void TestSetGetHeight() { XWPFDocument doc = new XWPFDocument(); CT_Tbl table = new CT_Tbl(); XWPFTable xtab = new XWPFTable(table, doc); XWPFTableRow row = xtab.CreateRow(); row.SetHeight(20); Assert.AreEqual(20, row.GetHeight()); }
public XWPFTable(CT_Tbl table, IBody part, int row, int col) : this(table, part) { for (int i = 0; i < row; i++) { XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i); for (int k = 0; k < col; k++) { XWPFTableCell tabCell = (tabRow.GetCell(k) == null) ? tabRow .CreateCell() : null; } } }
public void TestSetGetRepeatHeader() { // create a table XWPFDocument doc = new XWPFDocument(); CT_Tbl ctTable = new CT_Tbl(); XWPFTable table = new XWPFTable(ctTable, doc); // table has a single row by default; grab it XWPFTableRow tr = table.GetRow(0); Assert.IsNotNull(tr); tr.IsRepeatHeader = true; bool isRpt = tr.IsRepeatHeader; Assert.IsTrue(isRpt); }
public XWPFTable(CT_Tbl table, IBody part, int row, int col) : this(table, part) { for (int pos1 = 0; pos1 < row; ++pos1) { XWPFTableRow xwpfTableRow = this.GetRow(pos1) == null?this.CreateRow() : this.GetRow(pos1); for (int pos2 = 0; pos2 < col; ++pos2) { if (xwpfTableRow.GetCell(pos2) == null) { xwpfTableRow.CreateCell(); } } } }
/** * If a table cell does not include at least one block-level element, then this document shall be considered corrupt */ public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) { this.ctTc = cell; this.part = part; this.tableRow = tableRow; // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. if (cell.GetPList().Count < 1) { cell.AddNewP(); } bodyElements = new List <IBodyElement>(); paragraphs = new List <XWPFParagraph>(); tables = new List <XWPFTable>(); foreach (object o in ctTc.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } } /* * XmlCursor cursor = ctTc.NewCursor(); * cursor.SelectPath("./*"); * while (cursor.ToNextSelection()) { * XmlObject o = cursor.Object; * if (o is CTP) { * XWPFParagraph p = new XWPFParagraph((CTP)o, this); * paragraphs.Add(p); * bodyElements.Add(p); * } * if (o is CTTbl) { * XWPFTable t = new XWPFTable((CTTbl)o, this); * tables.Add(t); * bodyElements.Add(t); * } * } * cursor.Dispose();*/ }
public void TestSetGetCantSplitRow() { // create a table XWPFDocument doc = new XWPFDocument(); CT_Tbl ctTable = new CT_Tbl(); XWPFTable table = new XWPFTable(ctTable, doc); // table has a single row by default; grab it XWPFTableRow tr = table.GetRow(0); Assert.IsNotNull(tr); tr.SetCantSplitRow(true); bool isCant = tr.IsCantSplitRow(); //assert(isCant); Assert.IsTrue(isCant); }
public void Test54099() { XWPFDocument doc = new XWPFDocument(); CT_Tbl ctTable = new CT_Tbl(); XWPFTable table = new XWPFTable(ctTable, doc); XWPFTableRow tr = table.GetRow(0); XWPFTableCell cell = tr.GetCell(0); CT_Tc ctTc = cell.GetCTTc(); CT_TcPr tcPr = ctTc.AddNewTcPr(); CT_HMerge hMerge = tcPr.AddNewHMerge(); hMerge.val = (ST_Merge.restart); CT_TcBorders tblBorders = tcPr.AddNewTcBorders(); CT_VMerge vMerge = tcPr.AddNewVMerge(); }
public void TestSetGetColor() { // create a table XWPFDocument doc = new XWPFDocument(); CT_Tbl ctTable = new CT_Tbl(); XWPFTable table = new XWPFTable(ctTable, doc); // table has a single row by default; grab it XWPFTableRow tr = table.GetRow(0); Assert.IsNotNull(tr); // row has a single cell by default; grab it XWPFTableCell cell = tr.GetCell(0); cell.SetColor("F0000F"); String clr = cell.GetColor(); Assert.AreEqual("F0000F", clr); }
/** * If a table cell does not include at least one block-level element, then this document shall be considered corrupt */ public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) { this.ctTc = cell; this.part = part; this.tableRow = tableRow; // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. if(cell.GetPList().Count<1) cell.AddNewP(); bodyElements = new List<IBodyElement>(); paragraphs = new List<XWPFParagraph>(); tables = new List<XWPFTable>(); foreach (object o in ctTc.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } } /* XmlCursor cursor = ctTc.NewCursor(); cursor.SelectPath("./*"); while (cursor.ToNextSelection()) { XmlObject o = cursor.Object; if (o is CTP) { XWPFParagraph p = new XWPFParagraph((CTP)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CTTbl) { XWPFTable t = new XWPFTable((CTTbl)o, this); tables.Add(t); bodyElements.Add(t); } } cursor.Dispose();*/ }
/** * If a table cell does not include at least one block-level element, then this document shall be considered corrupt */ public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) { this.ctTc = cell; this.part = part; this.tableRow = tableRow; // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. if (cell.GetPList().Count < 1) { cell.AddNewP(); } bodyElements = new List <IBodyElement>(); paragraphs = new List <XWPFParagraph>(); tables = new List <XWPFTable>(); foreach (object o in ctTc.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } if (o is CT_SdtBlock) { XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); bodyElements.Add(c); } if (o is CT_SdtRun) { XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this); bodyElements.Add(c); } } }
public XWPFTable(CT_Tbl table, IBody part, int row, int col) : this(table, part) { CT_TblGrid ctTblGrid = table.AddNewTblGrid(); for (int j = 0; j < col; j++) { CT_TblGridCol ctGridCol = ctTblGrid.AddNewGridCol(); ctGridCol.w = 300; } for (int i = 0; i < row; i++) { XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i); for (int k = 0; k < col; k++) { if (tabRow.GetCell(k) == null) { tabRow.CreateCell(); } } } }
public XWPFTable(CT_Tbl table, IBody part) { this.part = part; this.ctTbl = table; tableRows = new List <XWPFTableRow>(); // is an empty table: I add one row and one column as default if (table.SizeOfTrArray() == 0) { CreateEmptyTable(table); } foreach (CT_Row row in table.GetTrList()) { StringBuilder rowText = new StringBuilder(); row.Table = table; XWPFTableRow tabRow = new XWPFTableRow(row, this); tableRows.Add(tabRow); foreach (CT_Tc cell in row.GetTcList()) { cell.TableRow = row; foreach (CT_P ctp in cell.GetPList()) { XWPFParagraph p = new XWPFParagraph(ctp, part); if (rowText.Length > 0) { rowText.Append('\t'); } rowText.Append(p.GetText()); } } if (rowText.Length > 0) { this.text.Append(rowText); this.text.Append('\n'); } } }
/** * If a table cell does not include at least one block-level element, then this document shall be considered corrupt */ public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part) { this.ctTc = cell; this.part = part; this.tableRow = tableRow; // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. if(cell.GetPList().Count<1) cell.AddNewP(); bodyElements = new List<IBodyElement>(); paragraphs = new List<XWPFParagraph>(); tables = new List<XWPFTable>(); foreach (object o in ctTc.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } if (o is CT_SdtBlock) { XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); bodyElements.Add(c); } if (o is CT_SdtRun) { XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this); bodyElements.Add(c); } } }
/** * add a new Row to the table * * @param row the row which should be Added */ public void AddRow(XWPFTableRow row) { ctTbl.AddNewTr(); ctTbl.SetTrArray(this.NumberOfRows - 1, row.GetCTRow()); tableRows.Add(row); }
public XWPFSDTContentCell(CT_SdtContentCell sdtContentCell, XWPFTableRow xwpfTableRow, IBody part) { StringBuilder sb = new StringBuilder(); //keep track of the following, //and add "\n" only before the start of a body //element if it is not the first body element. //index of cell in row int tcCnt = 0; //count of body objects int iBodyCnt = 0; int depth = 1; string sdtXml = sdtContentCell.ToString(); using (StringReader sr = new StringReader(sdtXml)) { XmlParserContext context = new XmlParserContext(null, POIXMLDocumentPart.NamespaceManager, null, XmlSpace.Preserve); using (XmlReader cursor = XmlReader.Create(sr, null, context)) { while (cursor.Read() && depth > 0) { if (cursor.NodeType == XmlNodeType.Text) { sb.Append(cursor.ReadContentAsString()); } else if (IsStartToken(cursor, "tr")) { tcCnt = 0; iBodyCnt = 0; } else if (IsStartToken(cursor, "tc")) { if (tcCnt++ > 0) { sb.Append("\t"); } iBodyCnt = 0; } else if (IsStartToken(cursor, "p") || IsStartToken(cursor, "tbl") || IsStartToken(cursor, "sdt")) { if (iBodyCnt > 0) { sb.Append("\n"); } iBodyCnt++; } } } } //IEnumerator cursor = sdtContentCell.Items.GetEnumerator(); //while (cursor.MoveNext() && depth > 0) //{ // //TokenType t = cursor.ToNextToken(); // object t = cursor.Current; // if (t is CT_Text)//?? // { // //sb.Append(cursor.TextValue); // } // else if (IsStartToken(cursor, "tr")) // { // tcCnt = 0; // iBodyCnt = 0; // } // else if (IsStartToken(cursor, "tc")) // { // if (tcCnt++ > 0) // { // sb.Append("\t"); // } // iBodyCnt = 0; // } // else if (IsStartToken(cursor, "p") || // IsStartToken(cursor, "tbl") || // IsStartToken(cursor, "sdt")) // { // if (iBodyCnt > 0) // { // sb.Append("\n"); // } // iBodyCnt++; // } // //if (cursor.IsStart()) // //{ // // depth++; // //} // //else if (cursor.IsEnd()) // //{ // // depth--; // //} //} text = sb.ToString(); }
public XWPFSDTCell(CT_SdtCell sdtCell, XWPFTableRow xwpfTableRow, IBody part) : base(sdtCell.sdtPr, part) { //base(sdtCell.SdtPr, part); cellContent = new XWPFSDTContentCell(sdtCell.sdtContent, xwpfTableRow, part); }
public void AddRow(XWPFTableRow row) { this.ctTbl.AddNewTr(); this.ctTbl.SetTrArray(this.GetNumberOfRows() - 1, row.GetCtRow()); this.tableRows.Add(row); }
/// <summary> /// 获取表中的列信息 /// </summary> /// <param name="row">行节点</param> /// <param name="dic">列名字典集合</param> /// <param name="pTable">表信息</param> private void InitColumns(XWPFTableRow row, Dictionary<int, string> dic, TableInfo pTable) { ColumnInfo mColumn = new ColumnInfo(); int iCell = 0; //列ID mColumn.ColumnObjectId = Guid.NewGuid().ToString(); string sTemp=""; foreach (var cell in row.GetTableCells()) { sTemp=cell.GetText().Trim(); Common.GetColumnInfo(dic, sTemp, mColumn, iCell, pTable); iCell++; } mColumn.DataTypeStr=Common.GetDataTypeStr(mColumn.DataTypeStr, mColumn.Width); mColumn.Width = Common.GetColumnWidth(mColumn.DataTypeStr); //杜冬军2014-07-23修改,添加主键列的判定方式 ,如果中文名称类似 A(主键) 则认为该列是主键列 Common.GetPrimaryKeyInfo(mColumn, pTable); if (string.IsNullOrEmpty(mColumn.Comment)) { mColumn.Comment = mColumn.Name; } if (string.IsNullOrEmpty(mColumn.DefaultValue)) { mColumn.DefaultValue = ""; } mColumn.Sequence = pTable.ListColumnInfo.Count + 1; pTable.ListColumnInfo.Add(mColumn); }
/** * add a new Row to the table * at position pos * @param row the row which should be Added */ public bool AddRow(XWPFTableRow row, int pos) { if (pos >= 0 && pos <= tableRows.Count) { ctTbl.InsertNewTr(pos); ctTbl.SetTrArray(pos, row.GetCtRow()); tableRows.Insert(pos, row); return true; } return false; }
/** * inserts a new tablerow * @param pos * @return the inserted row */ public XWPFTableRow InsertNewTableRow(int pos) { if(pos >= 0 && pos <= tableRows.Count){ CT_Row row = ctTbl.InsertNewTr(pos); XWPFTableRow tableRow = new XWPFTableRow(row, this); tableRows.Insert(pos, tableRow); return tableRow; } return null; }
/** * add a new Row to the table * * @param row the row which should be Added */ public void AddRow(XWPFTableRow row) { ctTbl.AddNewTr(); ctTbl.SetTrArray(GetNumberOfRows()-1, row.GetCtRow()); tableRows.Add(row); }
/** * create a new XWPFTableRow object with as many cells as the number of columns defined in that moment * * @return tableRow */ public XWPFTableRow CreateRow() { int sizeCol = ctTbl.SizeOfTrArray() > 0 ? ctTbl.GetTrArray(0) .SizeOfTcArray() : 0; XWPFTableRow tabRow = new XWPFTableRow(ctTbl.AddNewTr(), this); AddColumn(tabRow, sizeCol); tableRows.Add(tabRow); return tabRow; }
/** * add a new Row to the table * * @param row the row which should be Added */ public void AddRow(XWPFTableRow row) { ctTbl.AddNewTr(); ctTbl.SetTrArray(this.NumberOfRows-1, row.GetCTRow()); tableRows.Add(row); }