| public void SetText(string newText) | public void SetText(string newText) | ||||
| { | { | ||||
| string x = this.Tag; | |||||
| XElement el = Xml; | |||||
| Xml.Descendants(XName.Get("t", DocX.w.NamespaceName)).First().Value = newText; | Xml.Descendants(XName.Get("t", DocX.w.NamespaceName)).First().Value = newText; | ||||
| } | } | ||||
| } | } |
| { | { | ||||
| public class CustomProperty | public class CustomProperty | ||||
| { | { | ||||
| private string name; | |||||
| private object value; | |||||
| private string type; | |||||
| /// <summary> | /// <summary> | ||||
| /// The name of this CustomProperty. | /// The name of this CustomProperty. | ||||
| /// </summary> | /// </summary> | ||||
| public string Name { get { return name;} } | |||||
| public string Name { get; } | |||||
| /// <summary> | /// <summary> | ||||
| /// The value of this CustomProperty. | /// The value of this CustomProperty. | ||||
| /// </summary> | /// </summary> | ||||
| public object Value { get { return value; } } | |||||
| public object Value { get; } | |||||
| internal string Type { get { return type; } } | |||||
| internal string Type { get; } | |||||
| internal CustomProperty(string name, string type, string value) | internal CustomProperty(string name, string type, string value) | ||||
| { | { | ||||
| default: throw new Exception(); | default: throw new Exception(); | ||||
| } | } | ||||
| this.name = name; | |||||
| this.type = type; | |||||
| this.value = realValue; | |||||
| Name = name; | |||||
| Type = type; | |||||
| Value = realValue; | |||||
| } | } | ||||
| private CustomProperty(string name, string type, object value) | private CustomProperty(string name, string type, object value) | ||||
| { | { | ||||
| this.name = name; | |||||
| this.type = type; | |||||
| this.value = value; | |||||
| Name = name; | |||||
| Type = type; | |||||
| Value = value; | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="name">The name of this CustomProperty.</param> | /// <param name="name">The name of this CustomProperty.</param> | ||||
| /// <param name="value">The value of this CustomProperty.</param> | /// <param name="value">The value of this CustomProperty.</param> | ||||
| public CustomProperty(string name, int value) : this(name, "i4", value as object) { } | |||||
| public CustomProperty(string name, int value) : this(name, "i4", value) { } | |||||
| /// <summary> | /// <summary> | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="name">The name of this CustomProperty.</param> | /// <param name="name">The name of this CustomProperty.</param> | ||||
| /// <param name="value">The value of this CustomProperty.</param> | /// <param name="value">The value of this CustomProperty.</param> | ||||
| public CustomProperty(string name, double value) : this(name, "r8", value as object) { } | |||||
| public CustomProperty(string name, double value) : this(name, "r8", value) { } | |||||
| /// <summary> | /// <summary> | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="name">The name of this CustomProperty.</param> | /// <param name="name">The name of this CustomProperty.</param> | ||||
| /// <param name="value">The value of this CustomProperty.</param> | /// <param name="value">The value of this CustomProperty.</param> | ||||
| public CustomProperty(string name, DateTime value) : this(name, "filetime", value.ToUniversalTime() as object) { } | |||||
| public CustomProperty(string name, DateTime value) : this(name, "filetime", value.ToUniversalTime()) { } | |||||
| /// <summary> | /// <summary> | ||||
| /// Create a new CustomProperty to hold a bool. | /// Create a new CustomProperty to hold a bool. | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="name">The name of this CustomProperty.</param> | /// <param name="name">The name of this CustomProperty.</param> | ||||
| /// <param name="value">The value of this CustomProperty.</param> | /// <param name="value">The value of this CustomProperty.</param> | ||||
| public CustomProperty(string name, bool value) : this(name, "bool", value as object) { } | |||||
| public CustomProperty(string name, bool value) : this(name, "bool", value) { } | |||||
| } | } | ||||
| } | } |
| public class DocProperty: DocXElement | public class DocProperty: DocXElement | ||||
| { | { | ||||
| internal Regex extractName = new Regex(@"DOCPROPERTY (?<name>.*) "); | internal Regex extractName = new Regex(@"DOCPROPERTY (?<name>.*) "); | ||||
| private string name; | |||||
| /// <summary> | /// <summary> | ||||
| /// The custom property to display. | /// The custom property to display. | ||||
| /// </summary> | /// </summary> | ||||
| public string Name { get { return name; } } | |||||
| public string Name { get; } | |||||
| internal DocProperty(DocX document, XElement xml):base(document, xml) | internal DocProperty(DocX document, XElement xml):base(document, xml) | ||||
| { | { | ||||
| string instr = Xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value; | string instr = Xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value; | ||||
| this.name = extractName.Match(instr.Trim()).Groups["name"].Value; | |||||
| Name = extractName.Match(instr.Trim()).Groups["name"].Value; | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| { | { | ||||
| var element = this.GetOrCreate_pPr(); | var element = this.GetOrCreate_pPr(); | ||||
| var styleElement = element.Element(XName.Get("pStyle", DocX.w.NamespaceName)); | var styleElement = element.Element(XName.Get("pStyle", DocX.w.NamespaceName)); | ||||
| if (styleElement != null) | |||||
| var attr = styleElement?.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||||
| if (!string.IsNullOrEmpty(attr?.Value)) | |||||
| { | { | ||||
| var attr = styleElement.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||||
| if (attr != null && !string.IsNullOrEmpty(attr.Value)) | |||||
| { | |||||
| return attr.Value; | |||||
| } | |||||
| return attr.Value; | |||||
| } | } | ||||
| return "Normal"; | return "Normal"; | ||||
| } | } | ||||
| XElement pPr = GetOrCreate_pPr(); | XElement pPr = GetOrCreate_pPr(); | ||||
| XElement bidi = pPr.Element(XName.Get("bidi", DocX.w.NamespaceName)); | XElement bidi = pPr.Element(XName.Get("bidi", DocX.w.NamespaceName)); | ||||
| if (bidi == null) | |||||
| return Direction.LeftToRight; | |||||
| else | |||||
| return Direction.RightToLeft; | |||||
| return bidi == null ? Direction.LeftToRight : Direction.RightToLeft; | |||||
| } | } | ||||
| set | set | ||||
| if (bidi == null) | if (bidi == null) | ||||
| pPr.Add(new XElement(XName.Get("bidi", DocX.w.NamespaceName))); | pPr.Add(new XElement(XName.Get("bidi", DocX.w.NamespaceName))); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| if (bidi != null) | |||||
| bidi.Remove(); | |||||
| bidi?.Remove(); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| { | { | ||||
| pPr.Add(new XElement(XName.Get("keepLines", DocX.w.NamespaceName))); | pPr.Add(new XElement(XName.Get("keepLines", DocX.w.NamespaceName))); | ||||
| } | } | ||||
| if (!keepTogether && keepLinesE != null) | |||||
| if (!keepTogether) | |||||
| { | { | ||||
| keepLinesE.Remove(); | |||||
| keepLinesE?.Remove(); | |||||
| } | } | ||||
| return this; | return this; | ||||
| } | } | ||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| XElement pPr = GetOrCreate_pPr(); | |||||
| GetOrCreate_pPr(); | |||||
| XElement ind = GetOrCreate_pPr_ind(); | XElement ind = GetOrCreate_pPr_ind(); | ||||
| XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | ||||
| // Paragraph can either be firstLine or hanging (Remove hanging). | // Paragraph can either be firstLine or hanging (Remove hanging). | ||||
| XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | ||||
| if (hanging != null) | |||||
| hanging.Remove(); | |||||
| hanging?.Remove(); | |||||
| string indentation = ((indentationFirstLine / 0.1) * 57).ToString(); | string indentation = ((indentationFirstLine / 0.1) * 57).ToString(); | ||||
| XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | ||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| XElement pPr = GetOrCreate_pPr(); | |||||
| GetOrCreate_pPr(); | |||||
| XElement ind = GetOrCreate_pPr_ind(); | XElement ind = GetOrCreate_pPr_ind(); | ||||
| XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | ||||
| } | } | ||||
| } | } | ||||
| private float indentationAfter = 0.0f; | |||||
| private float indentationAfter; | |||||
| /// <summary> | /// <summary> | ||||
| /// Set the after indentation in cm for this Paragraph. | /// Set the after indentation in cm for this Paragraph. | ||||
| /// </summary> | /// </summary> | ||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| XElement pPr = GetOrCreate_pPr(); | |||||
| GetOrCreate_pPr(); | |||||
| XElement ind = GetOrCreate_pPr_ind(); | XElement ind = GetOrCreate_pPr_ind(); | ||||
| XAttribute right = ind.Attribute(XName.Get("right", DocX.w.NamespaceName)); | XAttribute right = ind.Attribute(XName.Get("right", DocX.w.NamespaceName)); |
| { | { | ||||
| return new Paragraph(Document, newlyInserted, (this as Paragraph).endIndex); | return new Paragraph(Document, newlyInserted, (this as Paragraph).endIndex); | ||||
| } | } | ||||
| else | |||||
| { | |||||
| p.Xml = newlyInserted; //IMPORTANT: I think we have return new paragraph in any case, but I dont know what to put as startIndex parameter into Paragraph constructor | |||||
| return p; | |||||
| } | |||||
| p.Xml = newlyInserted; //IMPORTANT: I think we have return new paragraph in any case, but I dont know what to put as startIndex parameter into Paragraph constructor | |||||
| return p; | |||||
| } | } | ||||
| public virtual Paragraph InsertParagraphBeforeSelf(string text) | public virtual Paragraph InsertParagraphBeforeSelf(string text) | ||||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | XElement newlyInserted = Xml.ElementsAfterSelf().First(); | ||||
| //Dmitchern | //Dmitchern | ||||
| return new Table(Document, newlyInserted) { mainPart = mainPart }; //return new table, dont affect parameter table | return new Table(Document, newlyInserted) { mainPart = mainPart }; //return new table, dont affect parameter table | ||||
| //t.Xml = newlyInserted; | |||||
| //return t; | |||||
| } | } | ||||
| public virtual Table InsertTableBeforeSelf(int rowCount, int columnCount) | public virtual Table InsertTableBeforeSelf(int rowCount, int columnCount) |
| { | { | ||||
| XNamespace ab = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; | XNamespace ab = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; | ||||
| var tempElement = document.PageLayout.Xml.Descendants(ab + "pgMar"); | var tempElement = document.PageLayout.Xml.Descendants(ab + "pgMar"); | ||||
| var e = tempElement.GetEnumerator(); | |||||
| foreach (var item in tempElement) | foreach (var item in tempElement) | ||||
| { | { |