浏览代码

Simplifying some expressions

master
Sergii Zhevzhyk 9 年前
父节点
当前提交
fb6b2824fe
共有 2 个文件被更改,包括 110 次插入263 次删除
  1. 109
    257
      DocX/Table.cs
  2. 1
    6
      DocX/_BaseClasses.cs

+ 109
- 257
DocX/Table.cs 查看文件

@@ -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));
@@ -1118,9 +1103,6 @@ namespace Novacode
case TableDesign.ColorfulGridAccent6:
val.Value = "ColorfulGrid-Accent6";
break;
default:
break;
}
}
if (Document.styles == null)
@@ -1599,7 +1581,6 @@ namespace Novacode
}
else
{
bool directionTest = true;
var positionIndex = 1;
var actualPosition = 1;
var gridAfterVal = 0;
@@ -1622,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;
}
@@ -1680,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)
{
@@ -1689,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);
}
}
@@ -2214,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);
@@ -2271,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)
{
@@ -2295,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);
@@ -2446,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;
@@ -2481,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();
}
@@ -2527,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)
@@ -2639,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
{
@@ -2680,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
@@ -2706,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();
}
}
}
@@ -2736,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.
@@ -2827,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;
}
@@ -2895,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)
@@ -2930,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)
{
@@ -2941,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)
{
@@ -2961,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)
@@ -2993,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)
{
@@ -3033,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)
@@ -3101,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.
@@ -3161,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)
@@ -3280,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)
@@ -3399,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)
@@ -3508,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)
@@ -3525,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)
@@ -3714,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,
@@ -3740,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)
{
@@ -3892,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
@@ -3959,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;
@@ -3973,7 +3826,6 @@ namespace Novacode
{
return (TextDirection)Enum.Parse(typeof(TextDirection), val.Value, true);
}
catch
{
val.Remove();

+ 1
- 6
DocX/_BaseClasses.cs 查看文件

@@ -146,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)
@@ -202,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;
}
}

正在加载...
取消
保存