| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using Novacode;
- using System.IO.Packaging;
- using System.IO;
- using System.Reflection;
-
- namespace Novacode
- {
- /// <summary>
- /// Designs\Styles that can be applied to a table.
- /// </summary>
- public enum TableDesign { TableNormal, TableGrid, LightShading, LightShadingAccent1, LightShadingAccent2, LightShadingAccent3, LightShadingAccent4, LightShadingAccent5, LightShadingAccent6, LightList, LightListAccent1, LightListAccent2, LightListAccent3, LightListAccent4, LightListAccent5, LightListAccent6, LightGrid, LightGridAccent1, LightGridAccent2, LightGridAccent3, LightGridAccent4, LightGridAccent5, LightGridAccent6, MediumShading1, MediumShading1Accent1, MediumShading1Accent2, MediumShading1Accent3, MediumShading1Accent4, MediumShading1Accent5, MediumShading1Accent6, MediumShading2, MediumShading2Accent1, MediumShading2Accent2, MediumShading2Accent3, MediumShading2Accent4, MediumShading2Accent5, MediumShading2Accent6, MediumList1, MediumList1Accent1, MediumList1Accent2, MediumList1Accent3, MediumList1Accent4, MediumList1Accent5, MediumList1Accent6, MediumList2, MediumList2Accent1, MediumList2Accent2, MediumList2Accent3, MediumList2Accent4, MediumList2Accent5, MediumList2Accent6, MediumGrid1, MediumGrid1Accent1, MediumGrid1Accent2, MediumGrid1Accent3, MediumGrid1Accent4, MediumGrid1Accent5, MediumGrid1Accent6, MediumGrid2, MediumGrid2Accent1, MediumGrid2Accent2, MediumGrid2Accent3, MediumGrid2Accent4, MediumGrid2Accent5, MediumGrid2Accent6, MediumGrid3, MediumGrid3Accent1, MediumGrid3Accent2, MediumGrid3Accent3, MediumGrid3Accent4, MediumGrid3Accent5, MediumGrid3Accent6, DarkList, DarkListAccent1, DarkListAccent2, DarkListAccent3, DarkListAccent4, DarkListAccent5, DarkListAccent6, ColorfulShading, ColorfulShadingAccent1, ColorfulShadingAccent2, ColorfulShadingAccent3, ColorfulShadingAccent4, ColorfulShadingAccent5, ColorfulShadingAccent6, ColorfulList, ColorfulListAccent1, ColorfulListAccent2, ColorfulListAccent3, ColorfulListAccent4, ColorfulListAccent5, ColorfulListAccent6, ColorfulGrid, ColorfulGridAccent1, ColorfulGridAccent2, ColorfulGridAccent3, ColorfulGridAccent4, ColorfulGridAccent5, ColorfulGridAccent6, None};
- public enum AutoFit{Contents, Window, ColoumnWidth};
-
- /// <summary>
- /// Represents a Table in a document.
- /// </summary>
- public class Table
- {
- private Alignment alignment;
- private AutoFit autofit;
- private List<Row> rows;
- private int rowCount, columnCount;
- internal XElement xml;
-
- /// <summary>
- /// Returns the number of rows in this table.
- /// </summary>
- public int RowCount { get { return rowCount; } }
-
- /// <summary>
- /// Returns the number of coloumns in this table.
- /// </summary>
- public int ColumnCount { get { return columnCount; } }
-
- /// <summary>
- /// Returns a list of rows in this table.
- /// </summary>
- public List<Row> Rows { get { return rows; } }
- DocX document;
- private TableDesign design;
-
- internal Table(DocX document, XElement xml)
- {
- autofit = AutoFit.ColoumnWidth;
- this.xml = xml;
- this.document = document;
-
- XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName));
-
- rows = (from r in xml.Elements(XName.Get("tr", DocX.w.NamespaceName))
- select new Row(document, r)).ToList();
-
- rowCount = rows.Count;
-
- if (rows.Count > 0)
- if (rows[0].Cells.Count > 0)
- columnCount = rows[0].Cells.Count;
-
- XElement style = properties.Element(XName.Get("tblStyle", DocX.w.NamespaceName));
- if (style != null)
- {
- XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName));
-
- if (val != null)
- design = (TableDesign)Enum.Parse(typeof(TableDesign), val.Value.Replace("-", string.Empty));
- else
- design = TableDesign.None;
- }
-
- else
- design = TableDesign.None;
- }
-
- public Alignment Alignment
- {
- get { return alignment; }
- set
- {
- string alignmentString = string.Empty;
- switch (value)
- {
- case Alignment.left:
- {
- alignmentString = "left";
- break;
- }
-
- case Alignment.both:
- {
- alignmentString = "both";
- break;
- }
-
-
- case Alignment.right:
- {
- alignmentString = "right";
- break;
- }
-
- case Alignment.center:
- {
- alignmentString = "center";
- break;
- }
- }
-
- XElement tblPr = xml.Descendants(XName.Get("tblPr", DocX.w.NamespaceName)).First();
- XElement jc = tblPr.Descendants(XName.Get("jc", DocX.w.NamespaceName)).FirstOrDefault();
-
- if(jc != null)
- jc.Remove();
-
- jc = new XElement(XName.Get("jc", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), alignmentString));
- tblPr.Add(jc);
- alignment = value;
- }
- }
-
- /// <summary>
- /// Auto size this table according to some rule.
- /// </summary>
- public AutoFit AutoFit
- {
- get{return autofit;}
-
- set
- {
- string attributeValue = string.Empty;
- switch(value)
- {
- case AutoFit.ColoumnWidth:
- {
- attributeValue = "dxa";
- break;
- }
-
- case AutoFit.Contents:
- {
- attributeValue = "auto";
- break;
- }
-
- case AutoFit.Window:
- {
- attributeValue = "pct";
- break;
- }
- }
-
- var query = from d in xml.Descendants()
- let type = d.Attribute(XName.Get("type", DocX.w.NamespaceName))
- where (d.Name.LocalName == "tcW" || d.Name.LocalName == "tblW") && type != null
- select type;
-
- foreach (XAttribute type in query)
- type.Value = attributeValue;
-
- autofit = value;
- }
- }
- /// <summary>
- /// The design\style to apply to this table.
- /// </summary>
- public TableDesign Design
- {
- get { return design; }
- set
- {
- XElement tblPr = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName));
- XElement style = tblPr.Element(XName.Get("tblStyle", DocX.w.NamespaceName));
- if (style == null)
- {
- tblPr.Add(new XElement(XName.Get("tblStyle", DocX.w.NamespaceName)));
- style = tblPr.Element(XName.Get("tblStyle", DocX.w.NamespaceName));
- }
-
- XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName));
- if(val == null)
- {
- style.Add(new XAttribute(XName.Get("val", DocX.w.NamespaceName), ""));
- val = style.Attribute(XName.Get("val", DocX.w.NamespaceName));
- }
-
- design = value;
-
- if (design == TableDesign.None)
- {
- if (style != null)
- style.Remove();
- }
-
- switch (design)
- {
- case TableDesign.TableNormal: val.Value = "TableNormal"; break;
- case TableDesign.TableGrid: val.Value = "TableGrid"; break;
- case TableDesign.LightShading: val.Value = "LightShading"; break;
- case TableDesign.LightShadingAccent1: val.Value = "LightShading-Accent1"; break;
- case TableDesign.LightShadingAccent2: val.Value = "LightShading-Accent2"; break;
- case TableDesign.LightShadingAccent3: val.Value = "LightShading-Accent3"; break;
- case TableDesign.LightShadingAccent4: val.Value = "LightShading-Accent4"; break;
- case TableDesign.LightShadingAccent5: val.Value = "LightShading-Accent5"; break;
- case TableDesign.LightShadingAccent6: val.Value = "LightShading-Accent6"; break;
- case TableDesign.LightList: val.Value = "LightList"; break;
- case TableDesign.LightListAccent1: val.Value = "LightList-Accent1"; break;
- case TableDesign.LightListAccent2: val.Value = "LightList-Accent2"; break;
- case TableDesign.LightListAccent3: val.Value = "LightList-Accent3"; break;
- case TableDesign.LightListAccent4: val.Value = "LightList-Accent4"; break;
- case TableDesign.LightListAccent5: val.Value = "LightList-Accent5"; break;
- case TableDesign.LightListAccent6: val.Value = "LightList-Accent6"; break;
- case TableDesign.LightGrid: val.Value = "LightGrid"; break;
- case TableDesign.LightGridAccent1: val.Value = "LightGrid-Accent1"; break;
- case TableDesign.LightGridAccent2: val.Value = "LightGrid-Accent2"; break;
- case TableDesign.LightGridAccent3: val.Value = "LightGrid-Accent3"; break;
- case TableDesign.LightGridAccent4: val.Value = "LightGrid-Accent4"; break;
- case TableDesign.LightGridAccent5: val.Value = "LightGrid-Accent5"; break;
- case TableDesign.LightGridAccent6: val.Value = "LightGrid-Accent6"; break;
- case TableDesign.MediumShading1: val.Value = "MediumShading1"; break;
- case TableDesign.MediumShading1Accent1: val.Value = "MediumShading1-Accent1"; break;
- case TableDesign.MediumShading1Accent2: val.Value = "MediumShading1-Accent2"; break;
- case TableDesign.MediumShading1Accent3: val.Value = "MediumShading1-Accent3"; break;
- case TableDesign.MediumShading1Accent4: val.Value = "MediumShading1-Accent4"; break;
- case TableDesign.MediumShading1Accent5: val.Value = "MediumShading1-Accent5"; break;
- case TableDesign.MediumShading1Accent6: val.Value = "MediumShading1-Accent6"; break;
- case TableDesign.MediumShading2: val.Value = "MediumShading2"; break;
- case TableDesign.MediumShading2Accent1: val.Value = "MediumShading2-Accent1"; break;
- case TableDesign.MediumShading2Accent2: val.Value = "MediumShading2-Accent2"; break;
- case TableDesign.MediumShading2Accent3: val.Value = "MediumShading2-Accent3"; break;
- case TableDesign.MediumShading2Accent4: val.Value = "MediumShading2-Accent4"; break;
- case TableDesign.MediumShading2Accent5: val.Value = "MediumShading2-Accent5"; break;
- case TableDesign.MediumShading2Accent6: val.Value = "MediumShading2-Accent6"; break;
- case TableDesign.MediumList1: val.Value = "MediumList1"; break;
- case TableDesign.MediumList1Accent1: val.Value = "MediumList1-Accent1"; break;
- case TableDesign.MediumList1Accent2: val.Value = "MediumList1-Accent2"; break;
- case TableDesign.MediumList1Accent3: val.Value = "MediumList1-Accent3"; break;
- case TableDesign.MediumList1Accent4: val.Value = "MediumList1-Accent4"; break;
- case TableDesign.MediumList1Accent5: val.Value = "MediumList1-Accent5"; break;
- case TableDesign.MediumList1Accent6: val.Value = "MediumList1-Accent6"; break;
- case TableDesign.MediumList2: val.Value = "MediumList2"; break;
- case TableDesign.MediumList2Accent1: val.Value = "MediumList2-Accent1"; break;
- case TableDesign.MediumList2Accent2: val.Value = "MediumList2-Accent2"; break;
- case TableDesign.MediumList2Accent3: val.Value = "MediumList2-Accent3"; break;
- case TableDesign.MediumList2Accent4: val.Value = "MediumList2-Accent4"; break;
- case TableDesign.MediumList2Accent5: val.Value = "MediumList2-Accent5"; break;
- case TableDesign.MediumList2Accent6: val.Value = "MediumList2-Accent6"; break;
- case TableDesign.MediumGrid1: val.Value = "MediumGrid1"; break;
- case TableDesign.MediumGrid1Accent1: val.Value = "MediumGrid1-Accent1"; break;
- case TableDesign.MediumGrid1Accent2: val.Value = "MediumGrid1-Accent2"; break;
- case TableDesign.MediumGrid1Accent3: val.Value = "MediumGrid1-Accent3"; break;
- case TableDesign.MediumGrid1Accent4: val.Value = "MediumGrid1-Accent4"; break;
- case TableDesign.MediumGrid1Accent5: val.Value = "MediumGrid1-Accent5"; break;
- case TableDesign.MediumGrid1Accent6: val.Value = "MediumGrid1-Accent6"; break;
- case TableDesign.MediumGrid2: val.Value = "MediumGrid2"; break;
- case TableDesign.MediumGrid2Accent1: val.Value = "MediumGrid2-Accent1"; break;
- case TableDesign.MediumGrid2Accent2: val.Value = "MediumGrid2-Accent2"; break;
- case TableDesign.MediumGrid2Accent3: val.Value = "MediumGrid2-Accent3"; break;
- case TableDesign.MediumGrid2Accent4: val.Value = "MediumGrid2-Accent4"; break;
- case TableDesign.MediumGrid2Accent5: val.Value = "MediumGrid2-Accent5"; break;
- case TableDesign.MediumGrid2Accent6: val.Value = "MediumGrid2-Accent6"; break;
- case TableDesign.MediumGrid3: val.Value = "MediumGrid3"; break;
- case TableDesign.MediumGrid3Accent1: val.Value = "MediumGrid3-Accent1"; break;
- case TableDesign.MediumGrid3Accent2: val.Value = "MediumGrid3-Accent2"; break;
- case TableDesign.MediumGrid3Accent3: val.Value = "MediumGrid3-Accent3"; break;
- case TableDesign.MediumGrid3Accent4: val.Value = "MediumGrid3-Accent4"; break;
- case TableDesign.MediumGrid3Accent5: val.Value = "MediumGrid3-Accent5"; break;
- case TableDesign.MediumGrid3Accent6: val.Value = "MediumGrid3-Accent6"; break;
-
- case TableDesign.DarkList: val.Value = "DarkList"; break;
- case TableDesign.DarkListAccent1: val.Value = "DarkList-Accent1"; break;
- case TableDesign.DarkListAccent2: val.Value = "DarkList-Accent2"; break;
- case TableDesign.DarkListAccent3: val.Value = "DarkList-Accent3"; break;
- case TableDesign.DarkListAccent4: val.Value = "DarkList-Accent4"; break;
- case TableDesign.DarkListAccent5: val.Value = "DarkList-Accent5"; break;
- case TableDesign.DarkListAccent6: val.Value = "DarkList-Accent6"; break;
-
- case TableDesign.ColorfulShading: val.Value = "ColorfulShading"; break;
- case TableDesign.ColorfulShadingAccent1: val.Value = "ColorfulShading-Accent1"; break;
- case TableDesign.ColorfulShadingAccent2: val.Value = "ColorfulShading-Accent2"; break;
- case TableDesign.ColorfulShadingAccent3: val.Value = "ColorfulShading-Accent3"; break;
- case TableDesign.ColorfulShadingAccent4: val.Value = "ColorfulShading-Accent4"; break;
- case TableDesign.ColorfulShadingAccent5: val.Value = "ColorfulShading-Accent5"; break;
- case TableDesign.ColorfulShadingAccent6: val.Value = "ColorfulShading-Accent6"; break;
-
- case TableDesign.ColorfulList: val.Value = "ColorfulList"; break;
- case TableDesign.ColorfulListAccent1: val.Value = "ColorfulList-Accent1"; break;
- case TableDesign.ColorfulListAccent2: val.Value = "ColorfulList-Accent2"; break;
- case TableDesign.ColorfulListAccent3: val.Value = "ColorfulList-Accent3"; break;
- case TableDesign.ColorfulListAccent4: val.Value = "ColorfulList-Accent4"; break;
- case TableDesign.ColorfulListAccent5: val.Value = "ColorfulList-Accent5"; break;
- case TableDesign.ColorfulListAccent6: val.Value = "ColorfulList-Accent6"; break;
-
- case TableDesign.ColorfulGrid: val.Value = "ColorfulGrid"; break;
- case TableDesign.ColorfulGridAccent1: val.Value = "ColorfulGrid-Accent1"; break;
- case TableDesign.ColorfulGridAccent2: val.Value = "ColorfulGrid-Accent2"; break;
- case TableDesign.ColorfulGridAccent3: val.Value = "ColorfulGrid-Accent3"; break;
- case TableDesign.ColorfulGridAccent4: val.Value = "ColorfulGrid-Accent4"; break;
- case TableDesign.ColorfulGridAccent5: val.Value = "ColorfulGrid-Accent5"; break;
- case TableDesign.ColorfulGridAccent6: val.Value = "ColorfulGrid-Accent6"; break;
-
- default: break;
- }
-
- XDocument style_doc;
- PackagePart word_styles = document.package.GetPart(new Uri("/word/styles.xml", UriKind.Relative));
- using (TextReader tr = new StreamReader(word_styles.GetStream()))
- style_doc = XDocument.Load(tr);
-
- var tableStyle =
- (
- from e in style_doc.Descendants()
- let styleId = e.Attribute(XName.Get("styleId", DocX.w.NamespaceName))
- where (styleId != null && styleId.Value == val.Value)
- select e
- ).FirstOrDefault();
-
- if (tableStyle == null)
- {
- XDocument external_style_doc = DocX.DecompressXMLResource("Novacode.Resources.styles.xml.gz");
-
- var styleElement =
- (
- from e in external_style_doc.Descendants()
- let styleId = e.Attribute(XName.Get("styleId", DocX.w.NamespaceName))
- where (styleId != null && styleId.Value == val.Value)
- select e
- ).First();
-
- style_doc.Element(XName.Get("styles", DocX.w.NamespaceName)).Add(styleElement);
-
- using (TextWriter tw = new StreamWriter(word_styles.GetStream(FileMode.Create)))
- style_doc.Save(tw, SaveOptions.None);
- }
- }
- }
-
- /// <summary>
- /// Insert a row at the end of this table.
- /// </summary>
- /// <example>
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Insert a new row at the end of this table.
- /// Row row = table.InsertRow();
- ///
- /// // Loop through each cell in this new row.
- /// foreach (Cell c in row.Cells)
- /// {
- /// // Set the text of each new cell to "Hello".
- /// c.Paragraph.InsertText("Hello", false);
- /// }
- ///
- /// // Save the document to a new file.
- /// document.SaveAs(@"C:\Example\Test2.docx");
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- /// <returns>A new row.</returns>
- public Row InsertRow()
- {
- return InsertRow(rows.Count);
- }
-
- /// <summary>
- /// Returns the index of this Table.
- /// </summary>
- /// <example>
- /// Replace the first table in this document with a new Table.
- /// <code>
- /// // Load a document into memory.
- /// using (DocX document = DocX.Load(@"Test.docx"))
- /// {
- /// // Get the first Table in this document.
- /// Table t = document.Tables[0];
- ///
- /// // Get the character index of Table t in this document.
- /// int index = t.Index;
- ///
- /// // Remove Table t.
- /// t.Remove();
- ///
- /// // Insert a new Table at the original index of Table t.
- /// Table newTable = document.InsertTable(index, 4, 4);
- ///
- /// // Set the design of this new Table, so that we can see it.
- /// newTable.Design = TableDesign.LightShadingAccent1;
- ///
- /// // Save all changes made to the document.
- /// document.Save();
- /// } // Release this document from memory.
- /// </code>
- /// </example>
- public int Index
- {
- get
- {
- int index = 0;
- IEnumerable<XElement> previous = xml.ElementsBeforeSelf();
-
- foreach (XElement e in previous)
- index += Paragraph.GetElementTextLength(e);
-
- return index;
- }
- }
-
- /// <summary>
- /// Remove this Table from this document.
- /// </summary>
- /// <example>
- /// Remove the first Table from this document.
- /// <code>
- /// // Load a document into memory.
- /// using (DocX document = DocX.Load(@"Test.docx"))
- /// {
- /// // Get the first Table in this document.
- /// Table t = d.Tables[0];
- ///
- /// // Remove this Table.
- /// t.Remove();
- ///
- /// // Save all changes made to the document.
- /// document.Save();
- /// } // Release this document from memory.
- /// </code>
- /// </example>
- public void Remove()
- {
- xml.Remove();
- }
-
- /// <summary>
- /// Insert a column to the right of a Table.
- /// </summary>
- /// <example>
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first Table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Insert a new column to this right of this table.
- /// table.InsertColumn();
- ///
- /// // Set the new coloumns text to "Row no."
- /// table.Rows[0].Cells[table.ColumnCount - 1].Paragraph.InsertText("Row no.", false);
- ///
- /// // Loop through each row in the table.
- /// for (int i = 1; i < table.Rows.Count; i++)
- /// {
- /// // The current row.
- /// Row row = table.Rows[i];
- ///
- /// // The cell in this row that belongs to the new coloumn.
- /// Cell cell = row.Cells[table.ColumnCount - 1];
- ///
- /// // The Paragraph that this cell houses.
- /// Paragraph p = cell.Paragraph;
- ///
- /// // Insert this rows index.
- /// p.InsertText(i.ToString(), false);
- /// }
- ///
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void InsertColumn()
- {
- InsertColumn(columnCount);
- }
-
- /// <summary>
- /// Remove the last row from this Table.
- /// </summary>
- /// <example>
- /// Remove the last row from a Table.
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Remove the last row from this table.
- /// table.RemoveRow();
- ///
- /// // Save the document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void RemoveRow()
- {
- RemoveRow(rowCount - 1);
- }
-
- /// <summary>
- /// Remove a row from this Table.
- /// </summary>
- /// <param name="index">The row to remove.</param>
- /// <example>
- /// Remove the first row from a Table.
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Remove the first row from this table.
- /// table.RemoveRow(0);
- ///
- /// // Save the document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void RemoveRow(int index)
- {
- if (index < 0 || index > rows.Count)
- throw new IndexOutOfRangeException();
-
- rows[index].xml.Remove();
- }
-
- /// <summary>
- /// Remove the last column for this Table.
- /// </summary>
- /// <example>
- /// Remove the last column from a Table.
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Remove the last column from this table.
- /// table.RemoveColumn();
- ///
- /// // Save the document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void RemoveColumn()
- {
- RemoveColumn(columnCount - 1);
- }
-
- /// <summary>
- /// Remove a coloumn from this Table.
- /// </summary>
- /// <param name="index">The coloumn to remove.</param>
- /// <example>
- /// Remove the first column from a Table.
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Remove the first column from this table.
- /// table.RemoveColumn(0);
- ///
- /// // Save the document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void RemoveColumn(int index)
- {
- if (index < 0 || index > columnCount - 1)
- throw new IndexOutOfRangeException();
-
- foreach (Row r in rows)
- r.Cells[index].xml.Remove();
- }
-
- /// <summary>
- /// Insert a row into this table.
- /// </summary>
- /// <example>
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Insert a new row at index 1 in this table.
- /// Row row = table.InsertRow(1);
- ///
- /// // Loop through each cell in this new row.
- /// foreach (Cell c in row.Cells)
- /// {
- /// // Set the text of each new cell to "Hello".
- /// c.Paragraph.InsertText("Hello", false);
- /// }
- ///
- /// // Save the document to a new file.
- /// document.SaveAs(@"C:\Example\Test2.docx");
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- /// <param name="index">Index to insert row at.</param>
- /// <returns>A new Row</returns>
- public Row InsertRow(int index)
- {
- if (index < 0 || index > rows.Count)
- throw new IndexOutOfRangeException();
-
- List<XElement> content = new List<XElement>();
-
- foreach (Cell c in rows[0].Cells)
- content.Add(new XElement(XName.Get("tc", DocX.w.NamespaceName), new XElement(XName.Get("p", DocX.w.NamespaceName))));
-
- XElement e = new XElement(XName.Get("tr", DocX.w.NamespaceName), content);
- Row newRow = new Row(document, e);
-
- XElement rowXml;
- if (index == rows.Count)
- {
- rowXml = rows.Last().xml;
- rowXml.AddAfterSelf(newRow.xml);
- }
-
- else
- {
- rowXml = rows[index].xml;
- rowXml.AddBeforeSelf(newRow.xml);
- }
-
- rows.Insert(index, newRow);
- rowCount = rows.Count;
- return newRow;
- }
-
- /// <summary>
- /// Insert a column into a table.
- /// </summary>
- /// <param name="index">The index to insert the column at.</param>
- /// <example>
- /// Insert a column to the left of a table.
- /// <code>
- /// // Load a document.
- /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
- /// {
- /// // Get the first Table in this document.
- /// Table table = document.Tables[0];
- ///
- /// // Insert a new column to this left of this table.
- /// table.InsertColumn(0);
- ///
- /// // Set the new coloumns text to "Row no."
- /// table.Rows[0].Cells[table.ColumnCount - 1].Paragraph.InsertText("Row no.", false);
- ///
- /// // Loop through each row in the table.
- /// for (int i = 1; i < table.Rows.Count; i++)
- /// {
- /// // The current row.
- /// Row row = table.Rows[i];
- ///
- /// // The cell in this row that belongs to the new coloumn.
- /// Cell cell = row.Cells[table.ColumnCount - 1];
- ///
- /// // The Paragraph that this cell houses.
- /// Paragraph p = cell.Paragraph;
- ///
- /// // Insert this rows index.
- /// p.InsertText(i.ToString(), false);
- /// }
- ///
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void InsertColumn(int index)
- {
- if (rows.Count > 0)
- {
- foreach (Row r in rows)
- {
- if(columnCount == index)
- r.Cells[index - 1].xml.AddAfterSelf(new XElement(XName.Get("tc", DocX.w.NamespaceName), new XElement(XName.Get("p", DocX.w.NamespaceName))));
- else
- r.Cells[index].xml.AddBeforeSelf(new XElement(XName.Get("tc", DocX.w.NamespaceName), new XElement(XName.Get("p", DocX.w.NamespaceName))));
- }
-
- rows = (from r in xml.Elements(XName.Get("tr", DocX.w.NamespaceName))
- select new Row(document, r)).ToList();
-
- rowCount = rows.Count;
-
- if (rows.Count > 0)
- if (rows[0].Cells.Count > 0)
- columnCount = rows[0].Cells.Count;
- }
- }
-
- /// <summary>
- /// Insert a page break after a Table.
- /// </summary>
- /// <example>
- /// Insert a Table and a Paragraph into a document with a page break between them.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a new Table.
- /// Table t1 = document.InsertTable(2, 2);
- /// t1.Design = TableDesign.LightShadingAccent1;
- ///
- /// // Insert a page break after this Table.
- /// t1.InsertPageBreakAfterSelf();
- ///
- /// // Insert a new Paragraph.
- /// Paragraph p1 = document.InsertParagraph("Paragraph", false);
- ///
- /// // Save this document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void InsertPageBreakAfterSelf()
- {
- XElement p = new XElement
- (
- XName.Get("p", DocX.w.NamespaceName),
- new XElement
- (
- XName.Get("r", DocX.w.NamespaceName),
- new XElement
- (
- XName.Get("br", DocX.w.NamespaceName),
- new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
- )
- )
- );
-
- xml.AddAfterSelf(p);
- }
-
- /// <summary>
- /// Insert a page break before a Table.
- /// </summary>
- /// <example>
- /// Insert a Table and a Paragraph into a document with a page break between them.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a new Paragraph.
- /// Paragraph p1 = document.InsertParagraph("Paragraph", false);
- ///
- /// // Insert a new Table.
- /// Table t1 = document.InsertTable(2, 2);
- /// t1.Design = TableDesign.LightShadingAccent1;
- ///
- /// // Insert a page break before this Table.
- /// t1.InsertPageBreakBeforeSelf();
- ///
- /// // Save this document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public void InsertPageBreakBeforeSelf()
- {
- XElement p = new XElement
- (
- XName.Get("p", DocX.w.NamespaceName),
- new XElement
- (
- XName.Get("r", DocX.w.NamespaceName),
- new XElement
- (
- XName.Get("br", DocX.w.NamespaceName),
- new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
- )
- )
- );
-
- xml.AddBeforeSelf(p);
- }
-
- /// <summary>
- /// Insert a new Table before this Table, this Table can be from this document or another document.
- /// </summary>
- /// <param name="t">The Table t to be inserted</param>
- /// <returns>A new Table inserted before this Table.</returns>
- /// <example>
- /// Insert a new Table before this Table.
- /// <code>
- /// // Place holder for a Table.
- /// Table t;
- ///
- /// // Load document a.
- /// using (DocX documentA = DocX.Load(@"a.docx"))
- /// {
- /// // Get the first Table from this document.
- /// t = documentA.Tables[0];
- /// }
- ///
- /// // Load document b.
- /// using (DocX documentB = DocX.Load(@"b.docx"))
- /// {
- /// // Get the first Table in document b.
- /// Table t2 = documentB.Tables[0];
- ///
- /// // Insert the Table from document a before this Table.
- /// Table newTable = t2.InsertTableBeforeSelf(t);
- ///
- /// // Save all changes made to document b.
- /// documentB.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Table InsertTableBeforeSelf(Table t)
- {
- xml.AddBeforeSelf(t.xml);
- XElement newlyInserted = xml.ElementsBeforeSelf().First();
-
- t.xml = newlyInserted;
- DocX.RebuildTables(document);
- DocX.RebuildParagraphs(document);
-
- return t;
- }
-
- /// <summary>
- /// Insert a new Table into this document before this Table.
- /// </summary>
- /// <param name="rowCount">The number of rows this Table should have.</param>
- /// <param name="coloumnCount">The number of coloumns this Table should have.</param>
- /// <returns>A new Table inserted before this Table.</returns>
- /// <example>
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// //Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- /// t.Design = TableDesign.LightShadingAccent1;
- /// t.Alignment = Alignment.center;
- ///
- /// // Insert a new Table before this Table.
- /// Table newTable = t.InsertTableBeforeSelf(2, 2);
- /// newTable.Design = TableDesign.LightShadingAccent2;
- /// newTable.Alignment = Alignment.center;
- ///
- /// // Save all changes made to this document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Table InsertTableBeforeSelf(int rowCount, int coloumnCount)
- {
- XElement newTable = DocX.CreateTable(rowCount, coloumnCount);
- xml.AddBeforeSelf(newTable);
- XElement newlyInserted = xml.ElementsBeforeSelf().First();
-
- DocX.RebuildTables(document);
- DocX.RebuildParagraphs(document);
- return new Table(document, newlyInserted);
- }
-
- /// <summary>
- /// Insert a new Table after this Table, this Table can be from this document or another document.
- /// </summary>
- /// <param name="t">The Table t to be inserted</param>
- /// <returns>A new Table inserted after this Table.</returns>
- /// <example>
- /// Insert a new Table after this Table.
- /// <code>
- /// // Place holder for a Table.
- /// Table t;
- ///
- /// // Load document a.
- /// using (DocX documentA = DocX.Load(@"a.docx"))
- /// {
- /// // Get the first Table from this document.
- /// t = documentA.Tables[0];
- /// }
- ///
- /// // Load document b.
- /// using (DocX documentB = DocX.Load(@"b.docx"))
- /// {
- /// // Get the first Table in document b.
- /// Table t2 = documentB.Tables[0];
- ///
- /// // Insert the Table from document a after this Table.
- /// Table newTable = t2.InsertTableAfterSelf(t);
- ///
- /// // Save all changes made to document b.
- /// documentB.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Table InsertTableAfterSelf(Table t)
- {
- xml.AddAfterSelf(t.xml);
- XElement newlyInserted = xml.ElementsAfterSelf().First();
-
- t.xml = newlyInserted;
- DocX.RebuildTables(document);
- DocX.RebuildParagraphs(document);
-
- return t;
- }
-
- /// <summary>
- /// Insert a new Table into this document after this Table.
- /// </summary>
- /// <param name="rowCount">The number of rows this Table should have.</param>
- /// <param name="coloumnCount">The number of coloumns this Table should have.</param>
- /// <returns>A new Table inserted before this Table.</returns>
- /// <example>
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// //Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- /// t.Design = TableDesign.LightShadingAccent1;
- /// t.Alignment = Alignment.center;
- ///
- /// // Insert a new Table after this Table.
- /// Table newTable = t.InsertTableAfterSelf(2, 2);
- /// newTable.Design = TableDesign.LightShadingAccent2;
- /// newTable.Alignment = Alignment.center;
- ///
- /// // Save all changes made to this document.
- /// document.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Table InsertTableAfterSelf(int rowCount, int coloumnCount)
- {
- XElement newTable = DocX.CreateTable(rowCount, coloumnCount);
- xml.AddAfterSelf(newTable);
- XElement newlyInserted = xml.ElementsAfterSelf().First();
-
- DocX.RebuildTables(document);
- DocX.RebuildParagraphs(document);
- return new Table(document, newlyInserted);
- }
-
- /// <summary>
- /// Insert a Paragraph before this Table, this Paragraph may have come from the same or another document.
- /// </summary>
- /// <param name="p">The Paragraph to insert.</param>
- /// <returns>The Paragraph now associated with this document.</returns>
- /// <example>
- /// Take a Paragraph from document a, and insert it into document b before this Table.
- /// <code>
- /// // Place holder for a Paragraph.
- /// Paragraph p;
- ///
- /// // Load document a.
- /// using (DocX documentA = DocX.Load(@"a.docx"))
- /// {
- /// // Get the first paragraph from this document.
- /// p = documentA.Paragraphs[0];
- /// }
- ///
- /// // Load document b.
- /// using (DocX documentB = DocX.Load(@"b.docx"))
- /// {
- /// // Get the first Table in document b.
- /// Table t = documentB.Tables[0];
- ///
- /// // Insert the Paragraph from document a before this Table.
- /// Paragraph newParagraph = t.InsertParagraphBeforeSelf(p);
- ///
- /// // Save all changes made to document b.
- /// documentB.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphBeforeSelf(Paragraph p)
- {
- xml.AddBeforeSelf(p.xml);
- XElement newlyInserted = xml.ElementsBeforeSelf().First();
-
- p.xml = newlyInserted;
- DocX.RebuildParagraphs(document);
-
- return p;
- }
-
- /// <summary>
- /// Insert a new Paragraph before this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <returns>A new Paragraph inserted before this Table.</returns>
- /// <example>
- /// Insert a new Paragraph before the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// t.InsertParagraphBeforeSelf("I was inserted before the next Table.");
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphBeforeSelf(string text)
- {
- return InsertParagraphBeforeSelf(text, false, new Formatting());
- }
-
- /// <summary>
- /// Insert a new Paragraph before this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <param name="trackChanges">Should this insertion be tracked as a change?</param>
- /// <returns>A new Paragraph inserted before this Table.</returns>
- /// <example>
- /// Insert a new paragraph before the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// t.InsertParagraphBeforeSelf("I was inserted before the next Table.", false);
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphBeforeSelf(string text, bool trackChanges)
- {
- return InsertParagraphBeforeSelf(text, trackChanges, new Formatting());
- }
-
- /// <summary>
- /// Insert a new Paragraph before this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <param name="trackChanges">Should this insertion be tracked as a change?</param>
- /// <param name="formatting">The formatting to apply to this insertion.</param>
- /// <returns>A new Paragraph inserted before this Table.</returns>
- /// <example>
- /// Insert a new paragraph before the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// Formatting boldFormatting = new Formatting();
- /// boldFormatting.Bold = true;
- ///
- /// t.InsertParagraphBeforeSelf("I was inserted before the next Table.", false, boldFormatting);
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphBeforeSelf(string text, bool trackChanges, Formatting formatting)
- {
- XElement newParagraph = new XElement
- (
- XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName)), DocX.FormatInput(text, formatting.Xml)
- );
-
- if (trackChanges)
- newParagraph = Paragraph.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
-
- xml.AddBeforeSelf(newParagraph);
- XElement newlyInserted = xml.ElementsBeforeSelf().First();
-
- Paragraph p = new Paragraph(document, -1, newlyInserted);
- DocX.RebuildParagraphs(document);
-
- return p;
- }
-
- /// <summary>
- /// Insert a Paragraph after this Table, this Paragraph may have come from the same or another document.
- /// </summary>
- /// <param name="p">The Paragraph to insert.</param>
- /// <returns>The Paragraph now associated with this document.</returns>
- /// <example>
- /// Take a Paragraph from document a, and insert it into document b after this Table.
- /// <code>
- /// // Place holder for a Paragraph.
- /// Paragraph p;
- ///
- /// // Load document a.
- /// using (DocX documentA = DocX.Load(@"a.docx"))
- /// {
- /// // Get the first paragraph from this document.
- /// p = documentA.Paragraphs[0];
- /// }
- ///
- /// // Load document b.
- /// using (DocX documentB = DocX.Load(@"b.docx"))
- /// {
- /// // Get the first Table in document b.
- /// Table t = documentB.Tables[0];
- ///
- /// // Insert the Paragraph from document a after this Table.
- /// Paragraph newParagraph = t.InsertParagraphAfterSelf(p);
- ///
- /// // Save all changes made to document b.
- /// documentB.Save();
- /// }// Release this document from memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphAfterSelf(Paragraph p)
- {
- xml.AddAfterSelf(p.xml);
- XElement newlyInserted = xml.ElementsAfterSelf().First();
-
- p.xml = newlyInserted;
- DocX.RebuildParagraphs(document);
-
- return p;
- }
-
- /// <summary>
- /// Insert a new Paragraph after this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <param name="trackChanges">Should this insertion be tracked as a change?</param>
- /// <param name="formatting">The formatting to apply to this insertion.</param>
- /// <returns>A new Paragraph inserted after this Table.</returns>
- /// <example>
- /// Insert a new paragraph after the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// Formatting boldFormatting = new Formatting();
- /// boldFormatting.Bold = true;
- ///
- /// t.InsertParagraphAfterSelf("I was inserted after the previous Table.", false, boldFormatting);
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphAfterSelf(string text, bool trackChanges, Formatting formatting)
- {
- XElement newParagraph = new XElement
- (
- XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName)), DocX.FormatInput(text, formatting.Xml)
- );
-
- if (trackChanges)
- newParagraph = Paragraph.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
-
- xml.AddAfterSelf(newParagraph);
- XElement newlyInserted = xml.ElementsAfterSelf().First();
-
- Paragraph p = new Paragraph(document, -1, newlyInserted);
- DocX.RebuildParagraphs(document);
-
- return p;
- }
-
- /// <summary>
- /// Insert a new Paragraph after this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <param name="trackChanges">Should this insertion be tracked as a change?</param>
- /// <returns>A new Paragraph inserted after this Table.</returns>
- /// <example>
- /// Insert a new paragraph after the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// t.InsertParagraphAfterSelf("I was inserted after the previous Table.", false);
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphAfterSelf(string text, bool trackChanges)
- {
- return InsertParagraphAfterSelf(text, trackChanges, new Formatting());
- }
-
- /// <summary>
- /// Insert a new Paragraph after this Table.
- /// </summary>
- /// <param name="text">The initial text for this new Paragraph.</param>
- /// <returns>A new Paragraph inserted after this Table.</returns>
- /// <example>
- /// Insert a new Paragraph after the first Table in this document.
- /// <code>
- /// // Create a new document.
- /// using (DocX document = DocX.Create(@"Test.docx"))
- /// {
- /// // Insert a Table into this document.
- /// Table t = document.InsertTable(2, 2);
- ///
- /// t.InsertParagraphAfterSelf("I was inserted after the previous Table.");
- ///
- /// // Save all changes made to this new document.
- /// document.Save();
- /// }// Release this new document form memory.
- /// </code>
- /// </example>
- public Paragraph InsertParagraphAfterSelf(string text)
- {
- return InsertParagraphAfterSelf(text, false, new Formatting());
- }
- }
-
- /// <summary>
- /// Represents a single row in a Table.
- /// </summary>
- public class Row
- {
- DocX document;
- internal XElement xml;
- private List<Cell> cells;
-
- /// <summary>
- /// A list of Cells in this Row.
- /// </summary>
- public List<Cell> Cells { get { return cells; } }
-
- internal Row(DocX document, XElement xml)
- {
- this.document = document;
- this.xml = xml;
- cells = (from c in xml.Elements(XName.Get("tc", DocX.w.NamespaceName))
- select new Cell(document, c)).ToList();
- }
- }
-
- public class Cell
- {
- private Paragraph p;
- private DocX document;
- internal XElement xml;
-
- public Paragraph Paragraph
- {
- get { return p; }
- set { p = value; }
- }
-
- internal Cell(DocX document, XElement xml)
- {
- this.document = document;
- this.xml = xml;
-
- XElement properties = xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
-
- p = new Paragraph(document, 0, xml.Element(XName.Get("p", DocX.w.NamespaceName)));
- }
- }
- }
|