| @@ -1,8 +1,4 @@ | |||
| using System; | |||
| using System.Linq; | |||
| using System.Collections.Generic; | |||
| namespace Novacode | |||
| namespace Novacode | |||
| { | |||
| public class Bookmark | |||
| { | |||
| @@ -1,5 +1,4 @@ | |||
| using System; | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using System.Collections.Generic; | |||
| using System.Xml.Linq; | |||
| @@ -23,11 +22,7 @@ namespace Novacode | |||
| public void SetText(string newText) | |||
| { | |||
| string x = this.Tag; | |||
| XElement el = Xml; | |||
| Xml.Descendants(XName.Get("t", DocX.w.NamespaceName)).First().Value = newText; | |||
| } | |||
| } | |||
| @@ -1,7 +1,6 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| namespace Novacode | |||
| { | |||
| @@ -4,21 +4,17 @@ namespace Novacode | |||
| { | |||
| public class CustomProperty | |||
| { | |||
| private string name; | |||
| private object value; | |||
| private string type; | |||
| /// <summary> | |||
| /// The name of this CustomProperty. | |||
| /// </summary> | |||
| public string Name { get { return name;} } | |||
| public string Name { get; } | |||
| /// <summary> | |||
| /// The value of this CustomProperty. | |||
| /// </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) | |||
| { | |||
| @@ -58,16 +54,16 @@ namespace Novacode | |||
| 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) | |||
| { | |||
| this.name = name; | |||
| this.type = type; | |||
| this.value = value; | |||
| Name = name; | |||
| Type = type; | |||
| Value = value; | |||
| } | |||
| /// <summary> | |||
| @@ -83,7 +79,7 @@ namespace Novacode | |||
| /// </summary> | |||
| /// <param name="name">The name 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> | |||
| @@ -91,7 +87,7 @@ namespace Novacode | |||
| /// </summary> | |||
| /// <param name="name">The name 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> | |||
| @@ -99,13 +95,13 @@ namespace Novacode | |||
| /// </summary> | |||
| /// <param name="name">The name 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> | |||
| /// Create a new CustomProperty to hold a bool. | |||
| /// </summary> | |||
| /// <param name="name">The name 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) { } | |||
| } | |||
| } | |||
| @@ -9,17 +9,16 @@ namespace Novacode | |||
| public class DocProperty: DocXElement | |||
| { | |||
| internal Regex extractName = new Regex(@"DOCPROPERTY (?<name>.*) "); | |||
| private string name; | |||
| /// <summary> | |||
| /// The custom property to display. | |||
| /// </summary> | |||
| public string Name { get { return name; } } | |||
| public string Name { get; } | |||
| internal DocProperty(DocX document, XElement xml):base(document, xml) | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,8 +1,4 @@ | |||
| using System; | |||
| using System.Linq; | |||
| using System.Collections.Generic; | |||
| namespace Novacode | |||
| namespace Novacode | |||
| { | |||
| public enum DocumentTypes | |||
| { | |||
| @@ -1,13 +1,6 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.ComponentModel; | |||
| using System.IO; | |||
| using System.Linq; | |||
| using System.Reflection; | |||
| using System.Text; | |||
| using System.Xml.Linq; | |||
| using Novacode; | |||
| namespace Novacode | |||
| { | |||
| @@ -32,10 +25,7 @@ namespace Novacode | |||
| { | |||
| return enumAttributes[0].Description; | |||
| } | |||
| else | |||
| { | |||
| return enumValue.ToString(); | |||
| } | |||
| return enumValue.ToString(); | |||
| } | |||
| /// <summary> | |||
| @@ -66,5 +56,4 @@ namespace Novacode | |||
| } | |||
| } | |||
| } | |||
| @@ -9,7 +9,6 @@ using System.Reflection; | |||
| using System.Security.Principal; | |||
| using System.Text; | |||
| using System.Xml.Linq; | |||
| using System.Xml; | |||
| namespace Novacode | |||
| { | |||
| @@ -1,5 +1,4 @@ | |||
| using System; | |||
| using System.IO; | |||
| using System.Linq; | |||
| using System.Drawing; | |||
| using System.Xml.Linq; | |||
| @@ -255,13 +254,10 @@ namespace Novacode | |||
| { | |||
| var element = this.GetOrCreate_pPr(); | |||
| 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"; | |||
| } | |||
| @@ -409,11 +405,7 @@ namespace Novacode | |||
| XElement pPr = GetOrCreate_pPr(); | |||
| 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 | |||
| @@ -428,11 +420,9 @@ namespace Novacode | |||
| if (bidi == null) | |||
| pPr.Add(new XElement(XName.Get("bidi", DocX.w.NamespaceName))); | |||
| } | |||
| else | |||
| { | |||
| if (bidi != null) | |||
| bidi.Remove(); | |||
| bidi?.Remove(); | |||
| } | |||
| } | |||
| } | |||
| @@ -515,9 +505,9 @@ namespace Novacode | |||
| { | |||
| pPr.Add(new XElement(XName.Get("keepLines", DocX.w.NamespaceName))); | |||
| } | |||
| if (!keepTogether && keepLinesE != null) | |||
| if (!keepTogether) | |||
| { | |||
| keepLinesE.Remove(); | |||
| keepLinesE?.Remove(); | |||
| } | |||
| return this; | |||
| } | |||
| @@ -587,7 +577,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| XElement pPr = GetOrCreate_pPr(); | |||
| GetOrCreate_pPr(); | |||
| XElement ind = GetOrCreate_pPr_ind(); | |||
| XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | |||
| @@ -608,8 +598,7 @@ namespace Novacode | |||
| // Paragraph can either be firstLine or hanging (Remove hanging). | |||
| XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | |||
| if (hanging != null) | |||
| hanging.Remove(); | |||
| hanging?.Remove(); | |||
| string indentation = ((indentationFirstLine / 0.1) * 57).ToString(); | |||
| XAttribute firstLine = ind.Attribute(XName.Get("firstLine", DocX.w.NamespaceName)); | |||
| @@ -646,7 +635,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| XElement pPr = GetOrCreate_pPr(); | |||
| GetOrCreate_pPr(); | |||
| XElement ind = GetOrCreate_pPr_ind(); | |||
| XAttribute hanging = ind.Attribute(XName.Get("hanging", DocX.w.NamespaceName)); | |||
| @@ -735,7 +724,7 @@ namespace Novacode | |||
| } | |||
| } | |||
| private float indentationAfter = 0.0f; | |||
| private float indentationAfter; | |||
| /// <summary> | |||
| /// Set the after indentation in cm for this Paragraph. | |||
| /// </summary> | |||
| @@ -763,7 +752,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| XElement pPr = GetOrCreate_pPr(); | |||
| GetOrCreate_pPr(); | |||
| XElement ind = GetOrCreate_pPr_ind(); | |||
| XAttribute right = ind.Attribute(XName.Get("right", DocX.w.NamespaceName)); | |||
| @@ -1,5 +1,4 @@ | |||
| using System.Collections.Generic; | |||
| using System.IO.Packaging; | |||
| using System.Xml.Linq; | |||
| namespace Novacode | |||
| @@ -55,7 +55,7 @@ namespace Novacode | |||
| * Get the tcPr (table cell properties) element for the first cell in this merge, | |||
| * null will be returned if no such element exists. | |||
| */ | |||
| XElement start_tcPr = null; | |||
| XElement start_tcPr; | |||
| if (columnIndex > Rows[startRow].Cells.Count) | |||
| start_tcPr = Rows[startRow].Cells[Rows[startRow].Cells.Count - 1].Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| else | |||
| @@ -88,7 +88,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| List<Paragraph> paragraphs = new List<Paragraph>(); | |||
| var paragraphs = new List<Paragraph>(); | |||
| foreach (Row r in Rows) | |||
| paragraphs.AddRange(r.Paragraphs); | |||
| @@ -123,7 +123,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| List<Picture> pictures = new List<Picture>(); | |||
| var pictures = new List<Picture>(); | |||
| foreach (Row r in Rows) | |||
| pictures.AddRange(r.Pictures); | |||
| @@ -186,7 +186,7 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| List<Hyperlink> hyperlinks = new List<Hyperlink>(); | |||
| var hyperlinks = new List<Hyperlink>(); | |||
| foreach (Row r in Rows) | |||
| hyperlinks.AddRange(r.Hyperlinks); | |||
| @@ -323,22 +323,18 @@ namespace Novacode | |||
| } | |||
| // remove all existing values | |||
| grid.RemoveAll(); | |||
| grid?.RemoveAll(); | |||
| // append new column widths | |||
| XElement gridCol = null; | |||
| Int32 i = 0; | |||
| Double value = width; | |||
| Double total = 0; | |||
| foreach (var w in widths) | |||
| { | |||
| value = w; | |||
| double value = w; | |||
| if (i == index) value = width; | |||
| gridCol = new XElement(XName.Get("gridCol", DocX.w.NamespaceName), | |||
| new XAttribute(XName.Get("w", DocX.w.NamespaceName), value)); | |||
| grid.Add(gridCol); | |||
| var gridCol = new XElement(XName.Get("gridCol", DocX.w.NamespaceName), | |||
| new XAttribute(XName.Get("w", DocX.w.NamespaceName), value)); | |||
| grid?.Add(gridCol); | |||
| i += 1; | |||
| total += value; | |||
| } | |||
| // remove cell widths | |||
| @@ -358,19 +354,17 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| List<Double> widths = new List<Double>(); | |||
| var widths = new List<Double>(); | |||
| // get the table grid props | |||
| XElement grid = Xml.Element(XName.Get("tblGrid", DocX.w.NamespaceName)); | |||
| if (grid == null) return null; | |||
| // get col properties | |||
| var cols = grid.Elements(XName.Get("gridCol", DocX.w.NamespaceName)); | |||
| var cols = grid?.Elements(XName.Get("gridCol", DocX.w.NamespaceName)); | |||
| if (cols == null) return null; | |||
| String value = String.Empty; | |||
| foreach (var col in cols) | |||
| { | |||
| value = col.GetAttribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| string value = col.GetAttribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| widths.Add(Convert.ToDouble(value)); | |||
| } | |||
| return widths; | |||
| @@ -434,7 +428,7 @@ namespace Novacode | |||
| XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); | |||
| XElement style = properties.Element(XName.Get("tblStyle", DocX.w.NamespaceName)); | |||
| XElement style = properties?.Element(XName.Get("tblStyle", DocX.w.NamespaceName)); | |||
| if (style != null) | |||
| { | |||
| XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| @@ -458,16 +452,18 @@ namespace Novacode | |||
| else | |||
| design = TableDesign.None; | |||
| XElement tableLook = properties.Element(XName.Get("tblLook", DocX.w.NamespaceName)); | |||
| XElement tableLook = properties?.Element(XName.Get("tblLook", DocX.w.NamespaceName)); | |||
| if (tableLook != null) | |||
| { | |||
| TableLook = new TableLook(); | |||
| TableLook.FirstRow = tableLook.GetAttribute(XName.Get("firstRow", DocX.w.NamespaceName)) == "1"; | |||
| TableLook.LastRow = tableLook.GetAttribute(XName.Get("lastRow", DocX.w.NamespaceName)) == "1"; | |||
| TableLook.FirstColumn = tableLook.GetAttribute(XName.Get("firstColumn", DocX.w.NamespaceName)) == "1"; | |||
| TableLook.LastColumn = tableLook.GetAttribute(XName.Get("lastColumn", DocX.w.NamespaceName)) == "1"; | |||
| TableLook.NoHorizontalBanding = tableLook.GetAttribute(XName.Get("noHBand", DocX.w.NamespaceName)) == "1"; | |||
| TableLook.NoVerticalBanding = tableLook.GetAttribute(XName.Get("noVBand", DocX.w.NamespaceName)) == "1"; | |||
| TableLook = new TableLook | |||
| { | |||
| FirstRow = tableLook.GetAttribute(XName.Get("firstRow", DocX.w.NamespaceName)) == "1", | |||
| LastRow = tableLook.GetAttribute(XName.Get("lastRow", DocX.w.NamespaceName)) == "1", | |||
| FirstColumn = tableLook.GetAttribute(XName.Get("firstColumn", DocX.w.NamespaceName)) == "1", | |||
| LastColumn = tableLook.GetAttribute(XName.Get("lastColumn", DocX.w.NamespaceName)) == "1", | |||
| NoHorizontalBanding = tableLook.GetAttribute(XName.Get("noHBand", DocX.w.NamespaceName)) == "1", | |||
| NoVerticalBanding = tableLook.GetAttribute(XName.Get("noVBand", DocX.w.NamespaceName)) == "1" | |||
| }; | |||
| } | |||
| } | |||
| @@ -521,13 +517,10 @@ namespace Novacode | |||
| get | |||
| { | |||
| XElement tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); | |||
| if (tblPr != null) | |||
| XElement caption = tblPr?.Element(XName.Get("tblCaption", DocX.w.NamespaceName)); | |||
| if (caption != null) | |||
| { | |||
| XElement caption = tblPr.Element(XName.Get("tblCaption", DocX.w.NamespaceName)); | |||
| if (caption != null) | |||
| { | |||
| _tableCaption = caption.GetAttribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| } | |||
| _tableCaption = caption.GetAttribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| } | |||
| return _tableCaption; | |||
| } | |||
| @@ -550,8 +543,7 @@ namespace Novacode | |||
| XElement tblDescription = | |||
| tblPr.Descendants(XName.Get("tblDescription", DocX.w.NamespaceName)).FirstOrDefault(); | |||
| if (tblDescription != null) | |||
| tblDescription.Remove(); | |||
| tblDescription?.Remove(); | |||
| tblDescription = new XElement(XName.Get("tblDescription", DocX.w.NamespaceName), | |||
| new XAttribute(XName.Get("val", DocX.w.NamespaceName), value)); | |||
| @@ -562,13 +554,10 @@ namespace Novacode | |||
| get | |||
| { | |||
| XElement tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); | |||
| if (tblPr != null) | |||
| XElement caption = tblPr?.Element(XName.Get("tblDescription", DocX.w.NamespaceName)); | |||
| if (caption != null) | |||
| { | |||
| XElement caption = tblPr.Element(XName.Get("tblDescription", DocX.w.NamespaceName)); | |||
| if (caption != null) | |||
| { | |||
| _tableDescription = caption.GetAttribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| } | |||
| _tableDescription = caption.GetAttribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| } | |||
| return _tableDescription; | |||
| } | |||
| @@ -614,8 +603,7 @@ namespace Novacode | |||
| 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?.Remove(); | |||
| jc = new XElement(XName.Get("jc", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), alignmentString)); | |||
| tblPr.Add(jc); | |||
| @@ -689,11 +677,8 @@ namespace Novacode | |||
| if (tblLayout == null) | |||
| { | |||
| XElement tmp = tblPr.Element(XName.Get("tblInd", DocX.w.NamespaceName)); | |||
| if (tmp == null) | |||
| { | |||
| tmp = tblPr.Element(XName.Get("tblW", DocX.w.NamespaceName)); | |||
| } | |||
| XElement tmp = tblPr.Element(XName.Get("tblInd", DocX.w.NamespaceName)) ?? | |||
| tblPr.Element(XName.Get("tblW", DocX.w.NamespaceName)); | |||
| tmp.AddAfterSelf(new XElement(XName.Get("tblLayout", DocX.w.NamespaceName))); | |||
| tmp = tblPr.Element(XName.Get("tblLayout", DocX.w.NamespaceName)); | |||
| @@ -794,10 +779,7 @@ namespace Novacode | |||
| design = value; | |||
| if (design == TableDesign.None) | |||
| { | |||
| if (style != null) | |||
| style.Remove(); | |||
| } | |||
| style.Remove(); | |||
| if (design == TableDesign.Custom) | |||
| { | |||
| @@ -815,7 +797,6 @@ namespace Novacode | |||
| } | |||
| else | |||
| { | |||
| switch (design) | |||
| { | |||
| case TableDesign.TableNormal: | |||
| @@ -1122,9 +1103,6 @@ namespace Novacode | |||
| case TableDesign.ColorfulGridAccent6: | |||
| val.Value = "ColorfulGrid-Accent6"; | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| if (Document.styles == null) | |||
| @@ -1603,7 +1581,6 @@ namespace Novacode | |||
| } | |||
| else | |||
| { | |||
| bool directionTest = true; | |||
| var positionIndex = 1; | |||
| var actualPosition = 1; | |||
| var gridAfterVal = 0; | |||
| @@ -1626,7 +1603,8 @@ namespace Novacode | |||
| if ((index - gridAfterVal) >= actualPosition | |||
| && (index - gridAfterVal) <= (actualPosition + gridSpanVal)) | |||
| { | |||
| if (index == (actualPosition + gridSpanVal) && direction == true) | |||
| bool directionTest; | |||
| if (index == (actualPosition + gridSpanVal) && direction) | |||
| { | |||
| directionTest = true; | |||
| } | |||
| @@ -1684,8 +1662,7 @@ namespace Novacode | |||
| /// <param name="celIndex">index of the cell you want to remove</param> | |||
| public void DeleteAndShiftCellsLeft(int rowIndex, int celIndex) | |||
| { | |||
| XAttribute gridAfterVal = new XAttribute(XName.Get("val", DocX.w.NamespaceName), 0); | |||
| var trPr = Rows[rowIndex].Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); | |||
| if (trPr != null) | |||
| { | |||
| @@ -1693,19 +1670,10 @@ namespace Novacode | |||
| if (gridAfter != null) | |||
| { | |||
| var val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| if (val != null) | |||
| { | |||
| val.Value = (int.Parse(val.Value) + 1).ToString(); | |||
| } | |||
| else | |||
| { | |||
| val.Value = "1"; | |||
| } | |||
| val.Value = (int.Parse(val.Value) + 1).ToString(); | |||
| } | |||
| else | |||
| { | |||
| var gridAfterElement = new XElement("gridAfter"); | |||
| var gridAfterValAttribute = new XAttribute("val", 1); | |||
| gridAfter.SetAttributeValue("val", 1); | |||
| } | |||
| } | |||
| @@ -2218,8 +2186,7 @@ namespace Novacode | |||
| * Get the 'borderType' (table border) element for this Table, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| string tbordertype; | |||
| tbordertype = borderType.ToString(); | |||
| var tbordertype = borderType.ToString(); | |||
| // only lower the first char of string (because of insideH and insideV) | |||
| tbordertype = tbordertype.Substring(0, 1).ToLower() + tbordertype.Substring(1); | |||
| @@ -2275,10 +2242,8 @@ namespace Novacode | |||
| // instance with default border values | |||
| Border b = new Border(); | |||
| /* | |||
| * Get the tblPr (table properties) element for this Table, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the tblPr (table properties) element for this Table, | |||
| // null will be return if no such element exists. | |||
| XElement tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); | |||
| if (tblPr == null) | |||
| { | |||
| @@ -2299,8 +2264,7 @@ namespace Novacode | |||
| * Get the 'borderType' (table border) element for this Table, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| string tbordertype; | |||
| tbordertype = borderType.ToString(); | |||
| var tbordertype = borderType.ToString(); | |||
| // only lower the first char of string (because of insideH and insideV) | |||
| tbordertype = tbordertype.Substring(0, 1).ToLower() + tbordertype.Substring(1); | |||
| @@ -2450,13 +2414,10 @@ namespace Novacode | |||
| if (trPr != null) | |||
| { | |||
| var gridAfter = trPr.Element(XName.Get("gridAfter", DocX.w.NamespaceName)); | |||
| if (gridAfter != null) | |||
| var val = gridAfter?.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| if (val != null) | |||
| { | |||
| var val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| if (val != null) | |||
| { | |||
| gridAfterValue += int.Parse(val.Value); | |||
| } | |||
| gridAfterValue += int.Parse(val.Value); | |||
| } | |||
| } | |||
| return gridAfterValue; | |||
| @@ -2485,7 +2446,7 @@ namespace Novacode | |||
| XElement table = Xml.Parent; | |||
| Xml.Remove(); | |||
| if (table.Elements(XName.Get("tr", DocX.w.NamespaceName)).Count() == 0) | |||
| if (!table.Elements(XName.Get("tr", DocX.w.NamespaceName)).Any()) | |||
| table.Remove(); | |||
| } | |||
| @@ -2531,28 +2492,18 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| /* | |||
| * Get the trPr (table row properties) element for this Row, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the trPr (table row properties) element for this Row, | |||
| // null will be return if no such element exists. | |||
| XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); | |||
| // If trPr is null, this row contains no height information. | |||
| if (trPr == null) | |||
| return double.NaN; | |||
| /* | |||
| * Get the trHeight element for this Row, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| XElement trHeight = trPr.Element(XName.Get("trHeight", DocX.w.NamespaceName)); | |||
| // Get the trHeight element for this Row, | |||
| // null will be return if no such element exists. | |||
| XElement trHeight = trPr?.Element(XName.Get("trHeight", DocX.w.NamespaceName)); | |||
| // If trHeight is null, this row contains no height information. | |||
| if (trHeight == null) | |||
| return double.NaN; | |||
| // Get the val attribute for this trHeight element. | |||
| XAttribute val = trHeight.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| XAttribute val = trHeight?.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (val == null) | |||
| @@ -2643,14 +2594,7 @@ namespace Novacode | |||
| { | |||
| XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); | |||
| XElement tblHeader = trPr.Element(XName.Get("tblHeader", DocX.w.NamespaceName)); | |||
| if (tblHeader == null) | |||
| { | |||
| return false; | |||
| } | |||
| else | |||
| { | |||
| return true; | |||
| } | |||
| return tblHeader != null; | |||
| } | |||
| set | |||
| { | |||
| @@ -2684,15 +2628,9 @@ namespace Novacode | |||
| { | |||
| XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); | |||
| if (trPr == null) | |||
| return true; | |||
| XElement trCantSplit = trPr.Element(XName.Get("cantSplit", DocX.w.NamespaceName)); | |||
| XElement trCantSplit = trPr?.Element(XName.Get("cantSplit", DocX.w.NamespaceName)); | |||
| if (trCantSplit == null) | |||
| return true; | |||
| return false; | |||
| return trCantSplit == null; | |||
| } | |||
| set | |||
| @@ -2710,16 +2648,11 @@ namespace Novacode | |||
| if (trCantSplit == null) | |||
| trPr.SetElementValue(XName.Get("cantSplit", DocX.w.NamespaceName), string.Empty); | |||
| } | |||
| if (value == true) | |||
| else | |||
| { | |||
| XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); | |||
| if (trPr != null) | |||
| { | |||
| XElement trCantSplit = trPr.Element(XName.Get("cantSplit", DocX.w.NamespaceName)); | |||
| if (trCantSplit != null) | |||
| trCantSplit.Remove(); | |||
| } | |||
| XElement trCantSplit = trPr?.Element(XName.Get("cantSplit", DocX.w.NamespaceName)); | |||
| trCantSplit?.Remove(); | |||
| } | |||
| } | |||
| } | |||
| @@ -2740,18 +2673,14 @@ namespace Novacode | |||
| foreach (Cell c in Cells.Where((z, i) => i > startIndex && i <= endIndex)) | |||
| { | |||
| XElement tcPr = c.Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| if (tcPr != null) | |||
| XElement gridSpan = tcPr?.Element(XName.Get("gridSpan", DocX.w.NamespaceName)); | |||
| if (gridSpan != null) | |||
| { | |||
| XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName)); | |||
| if (gridSpan != null) | |||
| { | |||
| XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| int value = 0; | |||
| if (val != null) | |||
| if (int.TryParse(val.Value, out value)) | |||
| gridSpanSum += value - 1; | |||
| } | |||
| int value; | |||
| if (val != null && int.TryParse(val.Value, out value)) | |||
| gridSpanSum += value - 1; | |||
| } | |||
| // Add this cells Pragraph to the merge start Cell. | |||
| @@ -2831,18 +2760,14 @@ namespace Novacode | |||
| { | |||
| var gridSpanVal = 0; | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| if (tcPr != null) | |||
| XElement gridSpan = tcPr?.Element(XName.Get("gridSpan", DocX.w.NamespaceName)); | |||
| if (gridSpan != null) | |||
| { | |||
| XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName)); | |||
| if (gridSpan != null) | |||
| { | |||
| XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| int value = 0; | |||
| if (val != null) | |||
| if (int.TryParse(val.Value, out value)) | |||
| gridSpanVal = value; | |||
| } | |||
| int value; | |||
| if (val != null && int.TryParse(val.Value, out value)) | |||
| gridSpanVal = value; | |||
| } | |||
| return gridSpanVal; | |||
| } | |||
| @@ -2899,21 +2824,13 @@ namespace Novacode | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| // If tcPr is null, this cell contains no width information. | |||
| if (tcPr == null) | |||
| return VerticalAlignment.Center; | |||
| /* | |||
| * Get the vAlign (table cell vertical alignment) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| XElement vAlign = tcPr.Element(XName.Get("vAlign", DocX.w.NamespaceName)); | |||
| // Get the vAlign (table cell vertical alignment) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement vAlign = tcPr?.Element(XName.Get("vAlign", DocX.w.NamespaceName)); | |||
| // If vAlign is null, this cell contains no vertical alignment information. | |||
| if (vAlign == null) | |||
| return VerticalAlignment.Center; | |||
| // Get the val attribute of the vAlign element. | |||
| XAttribute val = vAlign.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| XAttribute val = vAlign?.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| // If val is null, this cell contains no vAlign information. | |||
| if (val == null) | |||
| @@ -2934,10 +2851,8 @@ namespace Novacode | |||
| set | |||
| { | |||
| /* | |||
| * Get the tcPr (table cell properties) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the tcPr (table cell properties) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| if (tcPr == null) | |||
| { | |||
| @@ -2945,10 +2860,9 @@ namespace Novacode | |||
| tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| } | |||
| /* | |||
| * Get the vAlign (table cell vertical alignment) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the vAlign (table cell vertical alignment) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement vAlign = tcPr.Element(XName.Get("vAlign", DocX.w.NamespaceName)); | |||
| if (vAlign == null) | |||
| { | |||
| @@ -2965,28 +2879,18 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| /* | |||
| * Get the tcPr (table cell properties) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the tcPr (table cell properties) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| // If tcPr is null, this cell contains no Color information. | |||
| if (tcPr == null) | |||
| return Color.White; | |||
| /* | |||
| * Get the shd (table shade) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| XElement shd = tcPr.Element(XName.Get("shd", DocX.w.NamespaceName)); | |||
| // Get the shd (table shade) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement shd = tcPr?.Element(XName.Get("shd", DocX.w.NamespaceName)); | |||
| // If shd is null, this cell contains no Color information. | |||
| if (shd == null) | |||
| return Color.White; | |||
| // Get the w attribute of the tcW element. | |||
| XAttribute fill = shd.Attribute(XName.Get("fill", DocX.w.NamespaceName)); | |||
| XAttribute fill = shd?.Attribute(XName.Get("fill", DocX.w.NamespaceName)); | |||
| // If fill is null, this cell contains no Color information. | |||
| if (fill == null) | |||
| @@ -2997,10 +2901,8 @@ namespace Novacode | |||
| set | |||
| { | |||
| /* | |||
| * Get the tcPr (table cell properties) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the tcPr (table cell properties) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| if (tcPr == null) | |||
| { | |||
| @@ -3037,28 +2939,18 @@ namespace Novacode | |||
| { | |||
| get | |||
| { | |||
| /* | |||
| * Get the tcPr (table cell properties) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| // Get the tcPr (table cell properties) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| // If tcPr is null, this cell contains no width information. | |||
| if (tcPr == null) | |||
| return double.NaN; | |||
| /* | |||
| * Get the tcW (table cell width) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| XElement tcW = tcPr.Element(XName.Get("tcW", DocX.w.NamespaceName)); | |||
| // Get the tcW (table cell width) element for this Cell, | |||
| // null will be return if no such element exists. | |||
| XElement tcW = tcPr?.Element(XName.Get("tcW", DocX.w.NamespaceName)); | |||
| // If tcW is null, this cell contains no width information. | |||
| if (tcW == null) | |||
| return double.NaN; | |||
| // Get the w attribute of the tcW element. | |||
| XAttribute w = tcW.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| XAttribute w = tcW?.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (w == null) | |||
| @@ -3105,9 +2997,6 @@ namespace Novacode | |||
| // remove cell width; due to set on table prop. | |||
| tcW.Remove(); | |||
| return; | |||
| //tcW.SetAttributeValue(XName.Get("type", DocX.w.NamespaceName), "auto"); | |||
| //return; | |||
| } | |||
| // The type attribute needs to be set to dxa which represents "twips" or twentieths of a point. In other words, 1/1440th of an inch. | |||
| @@ -3165,18 +3054,12 @@ namespace Novacode | |||
| XElement tcMar = tcPr.Element(XName.Get("tcMar", DocX.w.NamespaceName)); | |||
| // If tcMar is null, this cell contains no margin information. | |||
| if (tcMar == null) | |||
| return double.NaN; | |||
| // Get the left (LeftMargin) element | |||
| XElement tcMarLeft = tcMar.Element(XName.Get("left", DocX.w.NamespaceName)); | |||
| XElement tcMarLeft = tcMar?.Element(XName.Get("left", DocX.w.NamespaceName)); | |||
| // If tcMarLeft is null, this cell contains no left margin information. | |||
| if (tcMarLeft == null) | |||
| return double.NaN; | |||
| // Get the w attribute of the tcMarLeft element. | |||
| XAttribute w = tcMarLeft.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| XAttribute w = tcMarLeft?.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (w == null) | |||
| @@ -3284,18 +3167,12 @@ namespace Novacode | |||
| XElement tcMar = tcPr.Element(XName.Get("tcMar", DocX.w.NamespaceName)); | |||
| // If tcMar is null, this cell contains no margin information. | |||
| if (tcMar == null) | |||
| return double.NaN; | |||
| // Get the right (RightMargin) element | |||
| XElement tcMarRight = tcMar.Element(XName.Get("right", DocX.w.NamespaceName)); | |||
| XElement tcMarRight = tcMar?.Element(XName.Get("right", DocX.w.NamespaceName)); | |||
| // If tcMarRight is null, this cell contains no right margin information. | |||
| if (tcMarRight == null) | |||
| return double.NaN; | |||
| // Get the w attribute of the tcMarRight element. | |||
| XAttribute w = tcMarRight.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| XAttribute w = tcMarRight?.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (w == null) | |||
| @@ -3403,18 +3280,12 @@ namespace Novacode | |||
| XElement tcMar = tcPr.Element(XName.Get("tcMar", DocX.w.NamespaceName)); | |||
| // If tcMar is null, this cell contains no margin information. | |||
| if (tcMar == null) | |||
| return double.NaN; | |||
| // Get the top (TopMargin) element | |||
| XElement tcMarTop = tcMar.Element(XName.Get("top", DocX.w.NamespaceName)); | |||
| XElement tcMarTop = tcMar?.Element(XName.Get("top", DocX.w.NamespaceName)); | |||
| // If tcMarTop is null, this cell contains no top margin information. | |||
| if (tcMarTop == null) | |||
| return double.NaN; | |||
| // Get the w attribute of the tcMarTop element. | |||
| XAttribute w = tcMarTop.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| XAttribute w = tcMarTop?.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (w == null) | |||
| @@ -3512,14 +3383,12 @@ namespace Novacode | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| // If tcPr is null, this cell contains no width information. | |||
| if (tcPr == null) | |||
| return double.NaN; | |||
| /* | |||
| * Get the tcMar | |||
| * | |||
| */ | |||
| XElement tcMar = tcPr.Element(XName.Get("tcMar", DocX.w.NamespaceName)); | |||
| XElement tcMar = tcPr?.Element(XName.Get("tcMar", DocX.w.NamespaceName)); | |||
| // If tcMar is null, this cell contains no margin information. | |||
| if (tcMar == null) | |||
| @@ -3529,11 +3398,9 @@ namespace Novacode | |||
| XElement tcMarBottom = tcMar.Element(XName.Get("bottom", DocX.w.NamespaceName)); | |||
| // If tcMarBottom is null, this cell contains no bottom margin information. | |||
| if (tcMarBottom == null) | |||
| return double.NaN; | |||
| // Get the w attribute of the tcMarBottom element. | |||
| XAttribute w = tcMarBottom.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| XAttribute w = tcMarBottom?.Attribute(XName.Get("w", DocX.w.NamespaceName)); | |||
| // If w is null, this cell contains no width information. | |||
| if (w == null) | |||
| @@ -3718,7 +3585,7 @@ namespace Novacode | |||
| public Border GetBorder(TableCellBorderType borderType) | |||
| { | |||
| // instance with default border values | |||
| Border b = new Border(); | |||
| var b = new Border(); | |||
| /* | |||
| * Get the tcPr (table cell properties) element for this Cell, | |||
| @@ -3744,8 +3611,7 @@ namespace Novacode | |||
| * Get the 'borderType' (cell border) element for this Cell, | |||
| * null will be return if no such element exists. | |||
| */ | |||
| string tcbordertype; | |||
| tcbordertype = borderType.ToString(); | |||
| var tcbordertype = borderType.ToString(); | |||
| switch (tcbordertype) | |||
| { | |||
| @@ -3896,25 +3762,12 @@ namespace Novacode | |||
| * null will be return if no such element exists. | |||
| */ | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| if (tcPr == null) | |||
| XElement shd = tcPr?.Element(XName.Get("shd", DocX.w.NamespaceName)); | |||
| XAttribute fill = shd?.Attribute(XName.Get("fill", DocX.w.NamespaceName)); | |||
| if (fill == null) | |||
| return Color.Empty; | |||
| else | |||
| { | |||
| XElement shd = tcPr.Element(XName.Get("shd", DocX.w.NamespaceName)); | |||
| if (shd == null) | |||
| return Color.Empty; | |||
| else | |||
| { | |||
| XAttribute fill = shd.Attribute(XName.Get("fill", DocX.w.NamespaceName)); | |||
| if (fill == null) | |||
| return Color.Empty; | |||
| else | |||
| { | |||
| int argb = Int32.Parse(fill.Value.Replace("#", ""), NumberStyles.HexNumber); | |||
| return Color.FromArgb(argb); | |||
| } | |||
| } | |||
| } | |||
| int argb = Int32.Parse(fill.Value.Replace("#", ""), NumberStyles.HexNumber); | |||
| return Color.FromArgb(argb); | |||
| } | |||
| set | |||
| @@ -3963,12 +3816,8 @@ namespace Novacode | |||
| XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName)); | |||
| // If tcPr is null, this cell contains no width information. | |||
| if (tcPr == null) | |||
| return TextDirection.right; | |||
| XElement textDirection = tcPr.Element(XName.Get("textDirection", DocX.w.NamespaceName)); | |||
| if (textDirection == null) | |||
| return TextDirection.right; | |||
| XAttribute val = textDirection.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| XElement textDirection = tcPr?.Element(XName.Get("textDirection", DocX.w.NamespaceName)); | |||
| XAttribute val = textDirection?.Attribute(XName.Get("val", DocX.w.NamespaceName)); | |||
| if (val == null) | |||
| return TextDirection.right; | |||
| @@ -3977,7 +3826,6 @@ namespace Novacode | |||
| { | |||
| return (TextDirection)Enum.Parse(typeof(TextDirection), val.Value, true); | |||
| } | |||
| catch | |||
| { | |||
| val.Remove(); | |||
| @@ -108,11 +108,9 @@ namespace Novacode | |||
| { | |||
| 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) | |||
| @@ -148,9 +146,7 @@ namespace Novacode | |||
| Xml.AddBeforeSelf(newParagraph); | |||
| XElement newlyInserted = Xml.ElementsBeforeSelf().Last(); | |||
| Paragraph p = new Paragraph(Document, newlyInserted, -1); | |||
| return p; | |||
| return new Paragraph(Document, newlyInserted, -1); | |||
| } | |||
| public virtual Paragraph InsertParagraphAfterSelf(string text, bool trackChanges, Formatting formatting) | |||
| @@ -186,9 +182,6 @@ namespace Novacode | |||
| XElement newlyInserted = Xml.ElementsAfterSelf().First(); | |||
| //Dmitchern | |||
| 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) | |||
| @@ -207,9 +200,6 @@ namespace Novacode | |||
| //Dmitchern | |||
| return new Table(Document, newlyInserted) { mainPart=mainPart}; //return new table, dont affect parameter table | |||
| //t.Xml = newlyInserted; | |||
| //return t; | |||
| } | |||
| } | |||
| @@ -1,10 +1,6 @@ | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Drawing; | |||
| using System.ComponentModel; | |||
| using System.IO; | |||
| using System.Reflection; | |||
| using System.Text; | |||
| using System.Xml.Linq; | |||
| namespace Novacode | |||
| @@ -83,7 +79,6 @@ namespace Novacode | |||
| { | |||
| XNamespace ab = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; | |||
| var tempElement = document.PageLayout.Xml.Descendants(ab + "pgMar"); | |||
| var e = tempElement.GetEnumerator(); | |||
| foreach (var item in tempElement) | |||
| { | |||
| @@ -21,7 +21,7 @@ namespace UnitTests | |||
| { | |||
| private readonly string _directoryDocuments; | |||
| private readonly string _directoryWithFiles; | |||
| private static Border BlankBorder = new Border(BorderStyle.Tcbs_none, 0, 0, WindowsColor.White); | |||
| private static readonly Border BlankBorder = new Border(BorderStyle.Tcbs_none, 0, 0, WindowsColor.White); | |||
| const string package_part_document = "/word/document.xml"; | |||
| @@ -57,7 +57,6 @@ namespace UnitTests | |||
| foreach (var cell in r.Cells) | |||
| { | |||
| cell.Paragraphs.First().Append("Col " + cx); | |||
| //cell.Width = colWidth; | |||
| cell.MarginBottom = 0; | |||
| cell.MarginLeft = 0; | |||
| cell.MarginRight = 0; | |||
| @@ -94,7 +93,6 @@ namespace UnitTests | |||
| foreach (var cell in r.Cells) | |||
| { | |||
| cell.Paragraphs.First().Append("Col " + cx); | |||
| //cell.Width = colWidth; | |||
| cell.MarginBottom = 0; | |||
| cell.MarginLeft = 0; | |||
| cell.MarginRight = 0; | |||
| @@ -110,7 +108,6 @@ namespace UnitTests | |||
| foreach (var cell in r.Cells) | |||
| { | |||
| cell.Paragraphs.First().Append("Col " + cx); | |||
| //cell.Width = colWidth; | |||
| cell.MarginBottom = 0; | |||
| cell.MarginLeft = 0; | |||
| cell.MarginRight = 0; | |||
| @@ -129,18 +126,11 @@ namespace UnitTests | |||
| doc.Save(); | |||
| } | |||
| } | |||
| } | |||
| [Test] | |||
| public void TestPatternFuncReplacement() | |||
| { | |||
| } | |||
| public string ReplaceFunc(string findStr) | |||
| { | |||
| Dictionary<string, string> testPatterns = new Dictionary<string, string>() | |||
| var testPatterns = new Dictionary<string, string> | |||
| { | |||
| {"COURT NAME","Fred Frump"}, | |||
| {"Case Number","cr-md-2011-1234567"} | |||
| @@ -159,14 +149,12 @@ namespace UnitTests | |||
| var findPattern = "<(.*?)>"; | |||
| var sample = "<Match This> text"; | |||
| var matchCollection = Regex.Matches(sample, findPattern, RegexOptions.IgnoreCase); | |||
| int i = 1; | |||
| } | |||
| [Test] | |||
| public void Test_Pattern_Replacement() | |||
| { | |||
| Dictionary<string, string> testPatterns = new Dictionary<string, string>() | |||
| var testPatterns = new Dictionary<string, string> | |||
| { | |||
| {"COURT NAME","Fred Frump"}, | |||
| {"Case Number","cr-md-2011-1234567"} | |||
| @@ -226,7 +214,7 @@ namespace UnitTests | |||
| Assert.IsTrue(document.CustomProperties.Count == 1); | |||
| Assert.IsTrue(document.CustomProperties.ContainsKey("fname")); | |||
| Assert.IsTrue((String)document.CustomProperties["fname"].Value == "cathal"); | |||
| Assert.IsTrue((string)document.CustomProperties["fname"].Value == "cathal"); | |||
| document.AddCustomProperty(new CustomProperty("age", 24)); | |||
| @@ -238,7 +226,7 @@ namespace UnitTests | |||
| Assert.IsTrue(document.CustomProperties.Count == 3); | |||
| Assert.IsTrue(document.CustomProperties.ContainsKey("male")); | |||
| Assert.IsTrue((bool)document.CustomProperties["male"].Value == true); | |||
| Assert.IsTrue((bool)document.CustomProperties["male"].Value); | |||
| document.AddCustomProperty(new CustomProperty("newyear2012", new DateTime(2012, 1, 1))); | |||
| @@ -342,7 +330,7 @@ namespace UnitTests | |||
| using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Test.docx"))) | |||
| { | |||
| // Add an Image to this document. | |||
| Novacode.Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| // Create a Picture from this Image. | |||
| Picture pic = img.CreatePicture(); | |||
| @@ -365,7 +353,7 @@ namespace UnitTests | |||
| using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Test.docx"))) | |||
| { | |||
| // Add an Image to this document. | |||
| Novacode.Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| // Create a Picture from this Image. | |||
| Picture pic = img.CreatePicture(); | |||
| @@ -494,27 +482,27 @@ namespace UnitTests | |||
| using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "test_add_images.docx"))) | |||
| { | |||
| // Add a png to into this document | |||
| Novacode.Image png = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Image png = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Assert.IsTrue(document.Images.Count == 1); | |||
| Assert.IsTrue(Path.GetExtension(png.pr.TargetUri.OriginalString) == ".png"); | |||
| // Add a tiff into to this document | |||
| Novacode.Image tif = document.AddImage(Path.Combine(_directoryWithFiles, "yellow.tif")); | |||
| Image tif = document.AddImage(Path.Combine(_directoryWithFiles, "yellow.tif")); | |||
| Assert.IsTrue(document.Images.Count == 2); | |||
| Assert.IsTrue(Path.GetExtension(tif.pr.TargetUri.OriginalString) == ".tif"); | |||
| // Add a gif into to this document | |||
| Novacode.Image gif = document.AddImage(Path.Combine(_directoryWithFiles, "orange.gif")); | |||
| Image gif = document.AddImage(Path.Combine(_directoryWithFiles, "orange.gif")); | |||
| Assert.IsTrue(document.Images.Count == 3); | |||
| Assert.IsTrue(Path.GetExtension(gif.pr.TargetUri.OriginalString) == ".gif"); | |||
| // Add a jpg into to this document | |||
| Novacode.Image jpg = document.AddImage(Path.Combine(_directoryWithFiles, "green.jpg")); | |||
| Image jpg = document.AddImage(Path.Combine(_directoryWithFiles, "green.jpg")); | |||
| Assert.IsTrue(document.Images.Count == 4); | |||
| Assert.IsTrue(Path.GetExtension(jpg.pr.TargetUri.OriginalString) == ".jpg"); | |||
| // Add a bitmap to this document | |||
| Novacode.Image bitmap = document.AddImage(Path.Combine(_directoryWithFiles, "red.bmp")); | |||
| Image bitmap = document.AddImage(Path.Combine(_directoryWithFiles, "red.bmp")); | |||
| Assert.IsTrue(document.Images.Count == 5); | |||
| // Word does not allow bmp make sure it was inserted as a png. | |||
| Assert.IsTrue(Path.GetExtension(bitmap.pr.TargetUri.OriginalString) == ".png"); | |||
| @@ -529,27 +517,27 @@ namespace UnitTests | |||
| // DocX will always insert Images that come from Streams as jpeg. | |||
| // Add a png to into this document | |||
| Novacode.Image png = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "purple.png"), FileMode.Open)); | |||
| Image png = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "purple.png"), FileMode.Open)); | |||
| Assert.IsTrue(document.Images.Count == 1); | |||
| Assert.IsTrue(Path.GetExtension(png.pr.TargetUri.OriginalString) == ".jpeg"); | |||
| // Add a tiff into to this document | |||
| Novacode.Image tif = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "yellow.tif"), FileMode.Open)); | |||
| Image tif = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "yellow.tif"), FileMode.Open)); | |||
| Assert.IsTrue(document.Images.Count == 2); | |||
| Assert.IsTrue(Path.GetExtension(tif.pr.TargetUri.OriginalString) == ".jpeg"); | |||
| // Add a gif into to this document | |||
| Novacode.Image gif = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "orange.gif"), FileMode.Open)); | |||
| Image gif = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "orange.gif"), FileMode.Open)); | |||
| Assert.IsTrue(document.Images.Count == 3); | |||
| Assert.IsTrue(Path.GetExtension(gif.pr.TargetUri.OriginalString) == ".jpeg"); | |||
| // Add a jpg into to this document | |||
| Novacode.Image jpg = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "green.jpg"), FileMode.Open)); | |||
| Image jpg = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "green.jpg"), FileMode.Open)); | |||
| Assert.IsTrue(document.Images.Count == 4); | |||
| Assert.IsTrue(Path.GetExtension(jpg.pr.TargetUri.OriginalString) == ".jpeg"); | |||
| // Add a bitmap to this document | |||
| Novacode.Image bitmap = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "red.bmp"), FileMode.Open)); | |||
| Image bitmap = document.AddImage(new FileStream(Path.Combine(_directoryWithFiles, "red.bmp"), FileMode.Open)); | |||
| Assert.IsTrue(document.Images.Count == 5); | |||
| // Word does not allow bmp make sure it was inserted as a png. | |||
| Assert.IsTrue(Path.GetExtension(bitmap.pr.TargetUri.OriginalString) == ".jpeg"); | |||
| @@ -581,7 +569,7 @@ namespace UnitTests | |||
| using (DocX document = DocX.Load(Path.Combine(_directoryWithFiles, "Images.docx"))) | |||
| { | |||
| // Extract Images from Document. | |||
| List<Novacode.Image> document_images = document.Images; | |||
| List<Image> document_images = document.Images; | |||
| // Make sure there are 3 Images in this document. | |||
| Assert.IsTrue(document_images.Count() == 3); | |||
| @@ -594,7 +582,7 @@ namespace UnitTests | |||
| #region Header_First | |||
| // Extract Images from the first Header. | |||
| List<Novacode.Image> header_first_images = header_first.Images; | |||
| List<Image> header_first_images = header_first.Images; | |||
| // Make sure there is 1 Image in the first header. | |||
| Assert.IsTrue(header_first_images.Count() == 1); | |||
| @@ -602,7 +590,7 @@ namespace UnitTests | |||
| #region Header_Odd | |||
| // Extract Images from the odd Header. | |||
| List<Novacode.Image> header_odd_images = header_odd.Images; | |||
| List<Image> header_odd_images = header_odd.Images; | |||
| // Make sure there is 1 Image in the first header. | |||
| Assert.IsTrue(header_odd_images.Count() == 1); | |||
| @@ -610,7 +598,7 @@ namespace UnitTests | |||
| #region Header_Even | |||
| // Extract Images from the odd Header. | |||
| List<Novacode.Image> header_even_images = header_even.Images; | |||
| List<Image> header_even_images = header_even.Images; | |||
| // Make sure there is 1 Image in the first header. | |||
| Assert.IsTrue(header_even_images.Count() == 1); | |||
| @@ -631,7 +619,7 @@ namespace UnitTests | |||
| document.DifferentOddAndEvenPages = true; | |||
| // Add an Image to this document. | |||
| Novacode.Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| // Create a Picture from this Image. | |||
| Picture pic = img.CreatePicture(); | |||
| @@ -876,7 +864,7 @@ namespace UnitTests | |||
| document.DifferentOddAndEvenPages = true; | |||
| // Add an Image to this document. | |||
| Novacode.Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| Image img = document.AddImage(Path.Combine(_directoryWithFiles, "purple.png")); | |||
| // Create a Picture from this Image. | |||
| Picture pic = img.CreatePicture(); | |||
| @@ -965,13 +953,13 @@ namespace UnitTests | |||
| Paragraph p1 = document.InsertParagraph("AC"); | |||
| p1.InsertHyperlink(h); Assert.IsTrue(p1.Text == "linkAC"); | |||
| p1.InsertHyperlink(h, p1.Text.Length); Assert.IsTrue(p1.Text == "linkAClink"); | |||
| p1.InsertHyperlink(h, p1.Text.IndexOf("C")); Assert.IsTrue(p1.Text == "linkAlinkClink"); | |||
| p1.InsertHyperlink(h, p1.Text.IndexOf("C", StringComparison.Ordinal)); Assert.IsTrue(p1.Text == "linkAlinkClink"); | |||
| // Difficult | |||
| Paragraph p2 = document.InsertParagraph("\tA\tC\t"); | |||
| p2.InsertHyperlink(h); Assert.IsTrue(p2.Text == "link\tA\tC\t"); | |||
| p2.InsertHyperlink(h, p2.Text.Length); Assert.IsTrue(p2.Text == "link\tA\tC\tlink"); | |||
| p2.InsertHyperlink(h, p2.Text.IndexOf("C")); Assert.IsTrue(p2.Text == "link\tA\tlinkC\tlink"); | |||
| p2.InsertHyperlink(h, p2.Text.IndexOf("C", StringComparison.Ordinal)); Assert.IsTrue(p2.Text == "link\tA\tlinkC\tlink"); | |||
| // Contrived | |||
| // Add a contrived Hyperlink to this document. | |||
| @@ -979,7 +967,7 @@ namespace UnitTests | |||
| Paragraph p3 = document.InsertParagraph("\tA\tC\t"); | |||
| p3.InsertHyperlink(h2); Assert.IsTrue(p3.Text == "\tlink\t\tA\tC\t"); | |||
| p3.InsertHyperlink(h2, p3.Text.Length); Assert.IsTrue(p3.Text == "\tlink\t\tA\tC\t\tlink\t"); | |||
| p3.InsertHyperlink(h2, p3.Text.IndexOf("C")); Assert.IsTrue(p3.Text == "\tlink\t\tA\t\tlink\tC\t\tlink\t"); | |||
| p3.InsertHyperlink(h2, p3.Text.IndexOf("C", StringComparison.Ordinal)); Assert.IsTrue(p3.Text == "\tlink\t\tA\t\tlink\tC\t\tlink\t"); | |||
| } | |||
| } | |||
| @@ -996,7 +984,7 @@ namespace UnitTests | |||
| Paragraph p1 = document.InsertParagraph("AC"); | |||
| p1.InsertHyperlink(h); Assert.IsTrue(p1.Text == "linkAC"); | |||
| p1.InsertHyperlink(h, p1.Text.Length); Assert.IsTrue(p1.Text == "linkAClink"); | |||
| p1.InsertHyperlink(h, p1.Text.IndexOf("C")); Assert.IsTrue(p1.Text == "linkAlinkClink"); | |||
| p1.InsertHyperlink(h, p1.Text.IndexOf("C", StringComparison.Ordinal)); Assert.IsTrue(p1.Text == "linkAlinkClink"); | |||
| // Try and remove a Hyperlink using a negative index. | |||
| // This should throw an exception. | |||
| @@ -1093,7 +1081,7 @@ namespace UnitTests | |||
| count = 0; | |||
| foreach (var p in document.Paragraphs) | |||
| { | |||
| p.ReplaceText("Text", "Replaced text", false, RegexOptions.None, null, desiredFormat, MatchFormattingOptions.SubsetMatch); | |||
| p.ReplaceText("Text", "Replaced text", false, RegexOptions.None, null, desiredFormat); | |||
| if (p.Text.StartsWith("Replaced text")) | |||
| { | |||
| ++count; | |||
| @@ -1117,7 +1105,7 @@ namespace UnitTests | |||
| Paragraph p1 = document.InsertParagraph("HelloWorld"); | |||
| p1.RemoveText(0, 1); Assert.IsTrue(p1.Text == "elloWorld"); | |||
| p1.RemoveText(p1.Text.Length - 1, 1); Assert.IsTrue(p1.Text == "elloWorl"); | |||
| p1.RemoveText(p1.Text.IndexOf("o"), 1); Assert.IsTrue(p1.Text == "ellWorl"); | |||
| p1.RemoveText(p1.Text.IndexOf("o", StringComparison.Ordinal), 1); Assert.IsTrue(p1.Text == "ellWorl"); | |||
| // Try and remove text at an index greater than the last. | |||
| // This should throw an exception. | |||
| @@ -1148,7 +1136,7 @@ namespace UnitTests | |||
| Paragraph p2 = document.InsertParagraph("A\tB\tC"); | |||
| p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == "\tB\tC"); | |||
| p2.RemoveText(p2.Text.Length - 1, 1); Assert.IsTrue(p2.Text == "\tB\t"); | |||
| p2.RemoveText(p2.Text.IndexOf("B"), 1); Assert.IsTrue(p2.Text == "\t\t"); | |||
| p2.RemoveText(p2.Text.IndexOf("B", StringComparison.Ordinal), 1); Assert.IsTrue(p2.Text == "\t\t"); | |||
| p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == "\t"); | |||
| p2.RemoveText(0, 1); Assert.IsTrue(p2.Text == ""); | |||
| @@ -1252,7 +1240,7 @@ namespace UnitTests | |||
| Paragraph p1 = document.InsertParagraph("HelloWorld"); | |||
| p1.InsertText(0, "-"); Assert.IsTrue(p1.Text == "-HelloWorld"); | |||
| p1.InsertText(p1.Text.Length, "-"); Assert.IsTrue(p1.Text == "-HelloWorld-"); | |||
| p1.InsertText(p1.Text.IndexOf("W"), "-"); Assert.IsTrue(p1.Text == "-Hello-World-"); | |||
| p1.InsertText(p1.Text.IndexOf("W", StringComparison.Ordinal), "-"); Assert.IsTrue(p1.Text == "-Hello-World-"); | |||
| // Try and insert text at an index greater than the last + 1. | |||
| // This should throw an exception. | |||
| @@ -1283,8 +1271,8 @@ namespace UnitTests | |||
| Paragraph p2 = document.InsertParagraph("A\tB\tC"); | |||
| p2.InsertText(0, "-"); Assert.IsTrue(p2.Text == "-A\tB\tC"); | |||
| p2.InsertText(p2.Text.Length, "-"); Assert.IsTrue(p2.Text == "-A\tB\tC-"); | |||
| p2.InsertText(p2.Text.IndexOf("B"), "-"); Assert.IsTrue(p2.Text == "-A\t-B\tC-"); | |||
| p2.InsertText(p2.Text.IndexOf("C"), "-"); Assert.IsTrue(p2.Text == "-A\t-B\t-C-"); | |||
| p2.InsertText(p2.Text.IndexOf("B", StringComparison.Ordinal), "-"); Assert.IsTrue(p2.Text == "-A\t-B\tC-"); | |||
| p2.InsertText(p2.Text.IndexOf("C", StringComparison.Ordinal), "-"); Assert.IsTrue(p2.Text == "-A\t-B\t-C-"); | |||
| // Contrived 1 | |||
| //<p> | |||
| @@ -1310,8 +1298,8 @@ namespace UnitTests | |||
| p3.InsertText(0, "-"); Assert.IsTrue(p3.Text == "-ABC"); | |||
| p3.InsertText(p3.Text.Length, "-"); Assert.IsTrue(p3.Text == "-ABC-"); | |||
| p3.InsertText(p3.Text.IndexOf("B"), "-"); Assert.IsTrue(p3.Text == "-A-BC-"); | |||
| p3.InsertText(p3.Text.IndexOf("C"), "-"); Assert.IsTrue(p3.Text == "-A-B-C-"); | |||
| p3.InsertText(p3.Text.IndexOf("B", StringComparison.Ordinal), "-"); Assert.IsTrue(p3.Text == "-A-BC-"); | |||
| p3.InsertText(p3.Text.IndexOf("C", StringComparison.Ordinal), "-"); Assert.IsTrue(p3.Text == "-A-B-C-"); | |||
| // Contrived 2 | |||
| //<p> | |||
| @@ -1337,8 +1325,8 @@ namespace UnitTests | |||
| p4.InsertText(0, "\t"); Assert.IsTrue(p4.Text == "\tABC"); | |||
| p4.InsertText(p4.Text.Length, "\t"); Assert.IsTrue(p4.Text == "\tABC\t"); | |||
| p4.InsertText(p4.Text.IndexOf("B"), "\t"); Assert.IsTrue(p4.Text == "\tA\tBC\t"); | |||
| p4.InsertText(p4.Text.IndexOf("C"), "\t"); Assert.IsTrue(p4.Text == "\tA\tB\tC\t"); | |||
| p4.InsertText(p4.Text.IndexOf("B", StringComparison.Ordinal), "\t"); Assert.IsTrue(p4.Text == "\tA\tBC\t"); | |||
| p4.InsertText(p4.Text.IndexOf("C", StringComparison.Ordinal), "\t"); Assert.IsTrue(p4.Text == "\tA\tB\tC\t"); | |||
| } | |||
| } | |||
| @@ -1854,7 +1842,7 @@ namespace UnitTests | |||
| { | |||
| const int level = 0; | |||
| XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; | |||
| var list = document.AddList("First Item", level, ListItemType.Numbered); | |||
| var list = document.AddList("First Item"); | |||
| document.InsertList(list); | |||
| var listNumPropNode = document.mainDoc.Descendants().First(s => s.Name.LocalName == "numPr"); | |||
| @@ -1943,13 +1931,7 @@ namespace UnitTests | |||
| Assert.AreEqual(list.Items.First().runs.First().Value, "RunText"); | |||
| } | |||
| } | |||
| [Test] | |||
| public void WhenCreatingAListTheNumberingShouldGetSaved() | |||
| { | |||
| } | |||
| [Test] | |||
| public void WhenCreatingAListTheListStyleShouldExistOrBeCreated() | |||
| { | |||
| @@ -2140,7 +2122,7 @@ namespace UnitTests | |||
| { | |||
| using (var document = DocX.Create(Path.Combine(_directoryDocuments, "HyperlinkList.docx"))) | |||
| { | |||
| var list = document.AddList("Item 1", listType: ListItemType.Numbered); | |||
| var list = document.AddList("Item 1"); | |||
| document.AddListItem(list, "Item 2"); | |||
| document.AddListItem(list, "Item 3"); | |||
| @@ -2299,11 +2281,8 @@ namespace UnitTests | |||
| [Test] | |||
| public void Test_Table_RemoveParagraphs() | |||
| { | |||
| MemoryStream memoryStream; | |||
| DocX document; | |||
| memoryStream = new MemoryStream(); | |||
| document = DocX.Create(memoryStream); | |||
| var memoryStream = new MemoryStream(); | |||
| var document = DocX.Create(memoryStream); | |||
| // Add a Table into the document. | |||
| Table table = document.AddTable(1, 4); // 1 row, 4 cells | |||
| table.Design = TableDesign.TableGrid; | |||