|
|
|
@@ -1797,77 +1797,80 @@ namespace Novacode |
|
|
|
/// </example>
|
|
|
|
/// <param name="borderType">The table border to set</param>
|
|
|
|
/// <param name="border">Border object to set the table border</param>
|
|
|
|
public void SetBorder(TableBorderType borderType, Border border)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
Xml.SetElementValue(XName.Get("tblPr", DocX.w.NamespaceName), string.Empty);
|
|
|
|
tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the tblBorders (table borders) element for this Table,
|
|
|
|
* null will be return if no such element exists.
|
|
|
|
*/
|
|
|
|
XElement tblBorders = tblPr.Element(XName.Get("tblBorders", DocX.w.NamespaceName));
|
|
|
|
if (tblBorders == null)
|
|
|
|
{
|
|
|
|
tblPr.SetElementValue(XName.Get("tblBorders", DocX.w.NamespaceName), string.Empty);
|
|
|
|
tblBorders = tblPr.Element(XName.Get("tblBorders", DocX.w.NamespaceName));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the 'borderType' (table border) element for this Table,
|
|
|
|
* null will be return if no such element exists.
|
|
|
|
*/
|
|
|
|
string tbordertype;
|
|
|
|
tbordertype = borderType.ToString();
|
|
|
|
// only lower the first char of string (because of insideH and insideV)
|
|
|
|
tbordertype = tbordertype.Substring(0, 1).ToLower() + tbordertype.Substring(1);
|
|
|
|
|
|
|
|
XElement tblBorderType = tblBorders.Element(XName.Get(borderType.ToString(), DocX.w.NamespaceName));
|
|
|
|
if (tblBorderType == null)
|
|
|
|
{
|
|
|
|
tblBorders.SetElementValue(XName.Get(tbordertype, DocX.w.NamespaceName), string.Empty);
|
|
|
|
tblBorderType = tblBorders.Element(XName.Get(tbordertype, DocX.w.NamespaceName));
|
|
|
|
}
|
|
|
|
|
|
|
|
// get string value of border style
|
|
|
|
string borderstyle = border.Tcbs.ToString().Substring(5);
|
|
|
|
borderstyle = borderstyle.Substring(0, 1).ToLower() + borderstyle.Substring(1);
|
|
|
|
|
|
|
|
// The val attribute is used for the border style
|
|
|
|
tblBorderType.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), borderstyle);
|
|
|
|
|
|
|
|
int size;
|
|
|
|
switch (border.Size)
|
|
|
|
{
|
|
|
|
case BorderSize.one: size = 2; break;
|
|
|
|
case BorderSize.two: size = 4; break;
|
|
|
|
case BorderSize.three: size = 6; break;
|
|
|
|
case BorderSize.four: size = 8; break;
|
|
|
|
case BorderSize.five: size = 12; break;
|
|
|
|
case BorderSize.six: size = 18; break;
|
|
|
|
case BorderSize.seven: size = 24; break;
|
|
|
|
case BorderSize.eight: size = 36; break;
|
|
|
|
case BorderSize.nine: size = 48; break;
|
|
|
|
default: size = 2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The sz attribute is used for the border size
|
|
|
|
tblBorderType.SetAttributeValue(XName.Get("sz", DocX.w.NamespaceName), (size).ToString());
|
|
|
|
|
|
|
|
// The space attribute is used for the cell spacing (probably '0')
|
|
|
|
tblBorderType.SetAttributeValue(XName.Get("space", DocX.w.NamespaceName), (border.Space).ToString());
|
|
|
|
|
|
|
|
// The color attribute is used for the border color
|
|
|
|
tblBorderType.SetAttributeValue(XName.Get("color", DocX.w.NamespaceName), ColorTranslator.ToHtml(border.Color));
|
|
|
|
}
|
|
|
|
public void SetBorder(TableBorderType borderType, Border border) |
|
|
|
{ |
|
|
|
/* |
|
|
|
* 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) |
|
|
|
{ |
|
|
|
Xml.SetElementValue(XName.Get("tblPr", DocX.w.NamespaceName), string.Empty); |
|
|
|
tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* Get the tblBorders (table borders) element for this Table, |
|
|
|
* null will be return if no such element exists. |
|
|
|
*/ |
|
|
|
XElement tblBorders = tblPr.Element(XName.Get("tblBorders", DocX.w.NamespaceName)); |
|
|
|
if (tblBorders == null) |
|
|
|
{ |
|
|
|
tblPr.SetElementValue(XName.Get("tblBorders", DocX.w.NamespaceName), string.Empty); |
|
|
|
tblBorders = tblPr.Element(XName.Get("tblBorders", DocX.w.NamespaceName)); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* Get the 'borderType' (table border) element for this Table, |
|
|
|
* null will be return if no such element exists. |
|
|
|
*/ |
|
|
|
string tbordertype; |
|
|
|
tbordertype = borderType.ToString(); |
|
|
|
// only lower the first char of string (because of insideH and insideV) |
|
|
|
tbordertype = tbordertype.Substring(0, 1).ToLower() + tbordertype.Substring(1); |
|
|
|
|
|
|
|
XElement tblBorderType = tblBorders.Element(XName.Get(borderType.ToString(), DocX.w.NamespaceName)); |
|
|
|
if (tblBorderType == null) |
|
|
|
{ |
|
|
|
tblBorders.SetElementValue(XName.Get(tbordertype, DocX.w.NamespaceName), string.Empty); |
|
|
|
tblBorderType = tblBorders.Element(XName.Get(tbordertype, DocX.w.NamespaceName)); |
|
|
|
} |
|
|
|
|
|
|
|
// get string value of border style |
|
|
|
string borderstyle = border.Tcbs.ToString().Substring(5); |
|
|
|
borderstyle = borderstyle.Substring(0, 1).ToLower() + borderstyle.Substring(1); |
|
|
|
|
|
|
|
// The val attribute is used for the border style |
|
|
|
tblBorderType.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), borderstyle); |
|
|
|
|
|
|
|
if (border.Tcbs != BorderStyle.Tcbs_nil) |
|
|
|
{ |
|
|
|
int size; |
|
|
|
switch (border.Size) |
|
|
|
{ |
|
|
|
case BorderSize.one: size = 2; break; |
|
|
|
case BorderSize.two: size = 4; break; |
|
|
|
case BorderSize.three: size = 6; break; |
|
|
|
case BorderSize.four: size = 8; break; |
|
|
|
case BorderSize.five: size = 12; break; |
|
|
|
case BorderSize.six: size = 18; break; |
|
|
|
case BorderSize.seven: size = 24; break; |
|
|
|
case BorderSize.eight: size = 36; break; |
|
|
|
case BorderSize.nine: size = 48; break; |
|
|
|
default: size = 2; break; |
|
|
|
} |
|
|
|
|
|
|
|
// The sz attribute is used for the border size |
|
|
|
tblBorderType.SetAttributeValue(XName.Get("sz", DocX.w.NamespaceName), (size).ToString()); |
|
|
|
|
|
|
|
// The space attribute is used for the cell spacing (probably '0') |
|
|
|
tblBorderType.SetAttributeValue(XName.Get("space", DocX.w.NamespaceName), (border.Space).ToString()); |
|
|
|
|
|
|
|
// The color attribute is used for the border color |
|
|
|
tblBorderType.SetAttributeValue(XName.Get("color", DocX.w.NamespaceName), ColorTranslator.ToHtml(border.Color)); |
|
|
|
} |
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a table border
|
|
|
|
@@ -2179,7 +2182,45 @@ namespace Novacode |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Set to true to make this row the table header row that will be repeated on each page |
|
|
|
/// </summary> |
|
|
|
public bool TableHeader |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); |
|
|
|
if (trPr == null) |
|
|
|
{ |
|
|
|
Xml.SetElementValue(XName.Get("trPr", DocX.w.NamespaceName), string.Empty); |
|
|
|
trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); |
|
|
|
} |
|
|
|
XElement tblHeader = trPr.Element(XName.Get("tblHeader", DocX.w.NamespaceName)); |
|
|
|
if (tblHeader == null && value) |
|
|
|
{ |
|
|
|
trPr.SetElementValue(XName.Get("tblHeader", DocX.w.NamespaceName), string.Empty); |
|
|
|
} |
|
|
|
if (tblHeader != null && !value) |
|
|
|
{ |
|
|
|
tblHeader.Remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Allow row to break across pages.
|
|
|
|
/// The default value is true: Word will break the contents of the row across pages.
|