Selaa lähdekoodia

Bug fixed in row Height: size in units should be integer.

Add an option to insert row cloning all formatting.
master
Viktor Loktev 9 vuotta sitten
vanhempi
commit
e58f0990b7
1 muutettua tiedostoa jossa 39 lisäystä ja 21 poistoa
  1. 39
    21
      DocX/Table.cs

+ 39
- 21
DocX/Table.cs Näytä tiedosto

return InsertRow(RowCount); return InsertRow(RowCount);
} }
/// <summary>
/// Insert a copy of a row at the end of this table.
/// </summary>
/// <returns>A new row.</returns>
public Row InsertRow(Row row)
/// <summary>
/// Insert a copy of a row at the end of this table.
/// </summary>
/// <returns>A new row.</returns>
/// <param name="row">The row to insert</param>
/// <param name="keepFormatting">True to clone everithing, False to clone cell structure only.</param>
/// <returns></returns>
public Row InsertRow(Row row, bool keepFormatting = false)
{ {
return InsertRow(row, RowCount);
return InsertRow(row, RowCount, keepFormatting);
} }
/// <summary> /// <summary>
return InsertRow(content, index); return InsertRow(content, index);
} }
/// <summary>
/// Insert a copy of a row into this table.
/// </summary>
/// <param name="row">Row to copy and insert.</param>
/// <param name="index">Index to insert row at.</param>
/// <returns>A new Row</returns>
public Row InsertRow(Row row, int index)
/// <summary>
/// Insert a copy of a row into this table.
/// </summary>
/// <param name="row">Row to copy and insert.</param>
/// <param name="index">Index to insert row at.</param>
/// <param name="keepFormatting">True to clone everithing, False to clone cell structure only.</param>
/// <returns>A new Row</returns>
public Row InsertRow(Row row, int index, bool keepFormatting = false)
{ {
if (row == null) if (row == null)
throw new ArgumentNullException(nameof(row)); throw new ArgumentNullException(nameof(row));
if (index < 0 || index > RowCount) if (index < 0 || index > RowCount)
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
List<XElement> content = row.Xml.Elements(XName.Get("tc", DocX.w.NamespaceName)).Select(element => HelperFunctions.CloneElement(element)).ToList();
return InsertRow(content, index);
List<XElement> content;
if( keepFormatting )
content = row.Xml.Elements().Select(element => HelperFunctions.CloneElement(element)).ToList();
else
content = row.Xml.Elements(XName.Get("tc", DocX.w.NamespaceName)).Select(element => HelperFunctions.CloneElement(element)).ToList();
return InsertRow(content, index);
} }
private Row InsertRow(List<XElement> content, Int32 index) private Row InsertRow(List<XElement> content, Int32 index)
XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName)); XElement trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr == null) if (trPr == null)
{ {
Xml.SetElementValue(XName.Get("trPr", DocX.w.NamespaceName), string.Empty);
trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
}
Xml.SetElementValue(XName.Get("trPr", DocX.w.NamespaceName), string.Empty);
trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
/*
// Swapping trPr and tc elements - making trPr the first
XElement tc = Xml.Element( XName.Get( "tc", DocX.w.NamespaceName ) );
if( tc != null )
{
trPr.Remove();
tc.AddBeforeSelf( trPr );
}
}
/*
* Get the trHeight element for this Row, * Get the trHeight element for this Row,
* null will be return if no such element exists. * null will be return if no such element exists.
*/ */
XElement trHeight = trPr.Element(XName.Get("trHeight", DocX.w.NamespaceName));
XElement trHeight = trPr.Element(XName.Get("trHeight", DocX.w.NamespaceName));
if (trHeight == null) if (trHeight == null)
{ {
trPr.SetElementValue(XName.Get("trHeight", DocX.w.NamespaceName), string.Empty); trPr.SetElementValue(XName.Get("trHeight", DocX.w.NamespaceName), string.Empty);
trHeight.SetAttributeValue(XName.Get("hRule", DocX.w.NamespaceName), exact ? _hRule_Exact : _hRule_AtLeast); trHeight.SetAttributeValue(XName.Get("hRule", DocX.w.NamespaceName), exact ? _hRule_Exact : _hRule_AtLeast);
// 15 "word units" is equal to one pixel. // 15 "word units" is equal to one pixel.
trHeight.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), (height * 15).ToString());
trHeight.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName),
((int)(Math.Round(height * 15,0))).ToString( CultureInfo.InvariantCulture )); // national separators anf fraction should be avoided
} }
/// <summary> /// <summary>
/// Min-Height in pixels. // Added by Nick Kusters. /// Min-Height in pixels. // Added by Nick Kusters.

Loading…
Peruuta
Tallenna