瀏覽代碼

Refactored InsertRow methods

master
DragonFire_cp 14 年之前
父節點
當前提交
da940113f7
共有 2 個檔案被更改,包括 17 行新增23 行删除
  1. 11
    18
      DocX/Table.cs
  2. 6
    5
      Examples/Program.cs

+ 11
- 18
DocX/Table.cs 查看文件

content.Add(cell); 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> /// <summary>
/// <returns>A new Row</returns> /// <returns>A new Row</returns>
public Row InsertRow(Row row, int index) public Row InsertRow(Row row, int index)
{ {
if (row == null)
throw new ArgumentNullException("row");
if (index < 0 || index > RowCount) if (index < 0 || index > RowCount)
throw new IndexOutOfRangeException(); 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; XElement rowXml;
if (index == Rows.Count) if (index == Rows.Count)

+ 6
- 5
Examples/Program.cs 查看文件

Table table = document.AddTable(2, 2); Table table = document.AddTable(2, 2);
table.Design = TableDesign.ColorfulGridAccent2; table.Design = TableDesign.ColorfulGridAccent2;
table.Alignment = Alignment.center; 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. // Add an image into the document.
Novacode.Image image = document.AddImage(@"images\logo_template.png"); Novacode.Image image = document.AddImage(@"images\logo_template.png");

Loading…
取消
儲存