Quellcode durchsuchen

Refactored InsertRow methods

master
DragonFire_cp vor 14 Jahren
Ursprung
Commit
da940113f7
2 geänderte Dateien mit 17 neuen und 23 gelöschten Zeilen
  1. 11
    18
      DocX/Table.cs
  2. 6
    5
      Examples/Program.cs

+ 11
- 18
DocX/Table.cs Datei anzeigen

@@ -797,23 +797,7 @@ namespace Novacode
content.Add(cell);
}
XElement e = new XElement(XName.Get("tr", DocX.w.NamespaceName), content);
Row newRow = new Row(this, Document, e);
XElement rowXml;
if (index == Rows.Count)
{
rowXml = Rows.Last().Xml;
rowXml.AddAfterSelf(newRow.Xml);
}
else
{
rowXml = Rows[index].Xml;
rowXml.AddBeforeSelf(newRow.Xml);
}
return newRow;
return InsertRow(content, index);
}
/// <summary>
@@ -824,10 +808,19 @@ namespace Novacode
/// <returns>A new Row</returns>
public Row InsertRow(Row row, int index)
{
if (row == null)
throw new ArgumentNullException("row");
if (index < 0 || index > RowCount)
throw new IndexOutOfRangeException();
Row newRow = new Row(this, Document, row.Xml);
List<XElement> 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)
{
Row newRow = new Row(this, Document, new XElement(XName.Get("tr", DocX.w.NamespaceName), content));
XElement rowXml;
if (index == Rows.Count)

+ 6
- 5
Examples/Program.cs Datei anzeigen

@@ -269,12 +269,13 @@ namespace Examples
Table table = document.AddTable(2, 2);
table.Design = TableDesign.ColorfulGridAccent2;
table.Alignment = Alignment.center;
table.Rows[0].Cells[0].Paragraphs[0].Append("3");
table.Rows[0].Cells[1].Paragraphs[0].Append("1");
table.Rows[1].Cells[0].Paragraphs[0].Append("4");
table.Rows[1].Cells[1].Paragraphs[0].Append("1");
table.Rows[0].Cells[0].Paragraphs[0].Append("1");
table.Rows[0].Cells[1].Paragraphs[0].Append("2");
table.Rows[1].Cells[0].Paragraphs[0].Append("3");
table.Rows[1].Cells[1].Paragraphs[0].Append("4");
table.InsertRow(table.Rows[1]);
Row newRow = table.InsertRow(table.Rows[1]);
newRow.ReplaceText("4", "5");
// Add an image into the document.
Novacode.Image image = document.AddImage(@"images\logo_template.png");

Laden…
Abbrechen
Speichern