diff --git a/OpenXmlFormats/Wordprocessing/Table.cs b/OpenXmlFormats/Wordprocessing/Table.cs index 9c0d769c3..137ab626b 100644 --- a/OpenXmlFormats/Wordprocessing/Table.cs +++ b/OpenXmlFormats/Wordprocessing/Table.cs @@ -1176,6 +1176,10 @@ public class CT_TblPrBase private CT_ShortHexNumber tblLookField; + private CT_String tblCaptionField; + + private CT_String tblDescriptionField; + public CT_TblPrBase() { } @@ -1216,6 +1220,10 @@ public static CT_TblPrBase Parse(XmlNode node, XmlNamespaceManager namespaceMana ctObj.tblCellMar = CT_TblCellMar.Parse(childNode, namespaceManager); else if (childNode.LocalName == "tblLook") ctObj.tblLook = CT_ShortHexNumber.Parse(childNode, namespaceManager); + else if (childNode.LocalName == "tblCaption") + ctObj.tblCaption = CT_String.Parse(childNode, namespaceManager); + else if (childNode.LocalName == "tblDescription") + ctObj.tblDescription = CT_String.Parse(childNode, namespaceManager); } return ctObj; } @@ -1256,6 +1264,10 @@ internal void Write(StreamWriter sw, string nodeName) this.tblCellMar.Write(sw, "tblCellMar"); if (this.tblLook != null) this.tblLook.Write(sw, "tblLook"); + if (this.tblCaption != null) + this.tblCaption.Write(sw, "tblCaption"); + if (this.tblDescription != null) + this.tblDescription.Write(sw, "tblDescription"); sw.Write(string.Format("", nodeName)); } @@ -1454,6 +1466,32 @@ public CT_ShortHexNumber tblLook } } + [XmlElement(Order = 15)] + public CT_String tblCaption + { + get + { + return this.tblCaptionField; + } + set + { + this.tblCaptionField = value; + } + } + + [XmlElement(Order = 16)] + public CT_String tblDescription + { + get + { + return this.tblDescriptionField; + } + set + { + this.tblDescriptionField = value; + } + } + public bool IsSetTblW() { return this.tblW != null; @@ -2776,6 +2814,10 @@ public class CT_TblPr : CT_TblPrBase ctObj.tblCellMar = CT_TblCellMar.Parse(childNode, namespaceManager); else if (childNode.LocalName == "tblLook") ctObj.tblLook = CT_ShortHexNumber.Parse(childNode, namespaceManager); + else if (childNode.LocalName == "tblCaption") + ctObj.tblCaption = CT_String.Parse(childNode, namespaceManager); + else if (childNode.LocalName == "tblDescription") + ctObj.tblDescription = CT_String.Parse(childNode, namespaceManager); } return ctObj; } @@ -2818,6 +2860,10 @@ public class CT_TblPr : CT_TblPrBase this.tblCellMar.Write(sw, "tblCellMar"); if (this.tblLook != null) this.tblLook.Write(sw, "tblLook"); + if (this.tblCaption != null) + this.tblCaption.Write(sw, "tblCaption"); + if (this.tblDescription != null) + this.tblDescription.Write(sw, "tblDescription"); sw.Write(string.Format("", nodeName)); } diff --git a/ooxml/XWPF/Usermodel/XWPFTable.cs b/ooxml/XWPF/Usermodel/XWPFTable.cs index 7c9941cd7..5b64de3d0 100644 --- a/ooxml/XWPF/Usermodel/XWPFTable.cs +++ b/ooxml/XWPF/Usermodel/XWPFTable.cs @@ -654,6 +654,58 @@ public int CellMarginRight } } + public string TableCaption + { + get + { + CT_TblPr tblPr = GetTrPr(); + if (tblPr.tblCaption != null) + return tblPr.tblCaption.val; + else + return string.Empty; + } + set + { + CT_TblPr tblPr = GetTrPr(); + if (tblPr.tblCaption == null) + { + CT_String caption = new CT_String(); + caption.val = value; + tblPr.tblCaption = caption; + } + else + { + tblPr.tblCaption.val = value; + } + } + } + + public string TableDescription + { + get + { + CT_TblPr tblPr = GetTrPr(); + if (tblPr.tblDescription != null) + return tblPr.tblDescription.val; + else + return string.Empty; + } + set + { + CT_TblPr tblPr = GetTrPr(); + if (tblPr.tblDescription == null) + { + CT_String desc = new CT_String(); + desc.val = value; + tblPr.tblDescription = desc; + } + else + { + tblPr.tblDescription.val = value; + } + } + } + public void SetCellMargins(int top, int left, int bottom, int right) { CT_TblPr tblPr = GetTrPr(); @@ -807,6 +859,7 @@ public XWPFTableRow GetRow(CT_Row row) } return null; } + }// end class } \ No newline at end of file diff --git a/testcases/ooxml/XWPF/UserModel/TestXWPFTable.cs b/testcases/ooxml/XWPF/UserModel/TestXWPFTable.cs index 30d7718fd..1bc83ff05 100644 --- a/testcases/ooxml/XWPF/UserModel/TestXWPFTable.cs +++ b/testcases/ooxml/XWPF/UserModel/TestXWPFTable.cs @@ -173,6 +173,7 @@ public void TestSetGetMargins() int r = table.CellMarginRight; Assert.AreEqual(450, r); } + [Test] public void TestSetGetHBorders() { @@ -266,5 +267,53 @@ public void TestCreateTable() } doc.Package.Revert(); } + + [Test] + public void TestSetTableCaption() + { + // create a table + XWPFDocument doc = new XWPFDocument(); + CT_Tbl ctTable = new CT_Tbl(); + XWPFTable table = new XWPFTable(ctTable, doc); + + //Set Caption + table.TableCaption = "%TABLECAPTION%"; + + //Check + CT_String tblCaption = table.GetCTTbl().tblPr.tblCaption; + Assert.IsNotNull(tblCaption); + Assert.AreEqual("%TABLECAPTION%", tblCaption.val); + } + + [Test] + public void TestSetTableDescription() + { + // create a table + XWPFDocument doc = new XWPFDocument(); + CT_Tbl ctTable = new CT_Tbl(); + XWPFTable table = new XWPFTable(ctTable, doc); + + //Set Description + table.TableDescription = "%TABLEDESCRIPTION%"; + + //Check + CT_String tblDesc = table.GetCTTbl().tblPr.tblDescription; + Assert.IsNotNull(tblDesc); + Assert.AreEqual("%TABLEDESCRIPTION%", tblDesc.val); + } + + [Test] + public void TestReadTableCaptionAndDescription() + { + // open an document with table containing Table caption and Table Description + XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("table_properties.docx"); + + //Get Table + var table = doc.Tables[0]; + + //Assert Table Caption & Description + Assert.AreEqual("Table Title", table.TableCaption); + Assert.AreEqual("Table Description", table.TableDescription); + } } } \ No newline at end of file diff --git a/testcases/test-data/document/table_properties.docx b/testcases/test-data/document/table_properties.docx new file mode 100644 index 000000000..b68438f88 Binary files /dev/null and b/testcases/test-data/document/table_properties.docx differ