Преглед на файлове

Added support for inserting PageBreaks by using one of the 4 new functions

1) Paragraph.InsertPageBreakAfterSelf()
2) Paragraph.InsertPageBreakBeforeSelf()
3) Table.InsertPageBreakAfterSelf()
4) Table.InsertPageBreakBeforeSelf()
master
coffeycathal_cp преди 16 години
родител
ревизия
11280e286b
променени са 3 файла, в които са добавени 169 реда и са изтрити 0 реда
  1. 1
    0
      DocX/DocX.cs
  2. 82
    0
      DocX/Paragraph.cs
  3. 86
    0
      DocX/Table.cs

+ 1
- 0
DocX/DocX.cs Целия файл

@@ -266,6 +266,7 @@ namespace Novacode
}
newRuns.Add(new XElement(DocX.w + "r", rPr, breakRun));
break;
default:
sb.Append(c);
break;

+ 82
- 0
DocX/Paragraph.cs Целия файл

@@ -407,6 +407,88 @@ namespace Novacode
return p;
}
/// <summary>
/// Insert a page break after a Paragraph.
/// </summary>
/// <example>
/// Insert 2 Paragraphs into a document with a page break between them.
/// <code>
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph.
/// Paragraph p1 = document.InsertParagraph("Paragraph 1", false);
///
/// // Insert a page break after this Paragraph.
/// p1.InsertPageBreakAfterSelf();
///
/// // Insert a new Paragraph.
/// Paragraph p2 = document.InsertParagraph("Paragraph 2", false);
///
/// // Save this document.
/// document.Save();
/// }// Release this document from memory.
/// </code>
/// </example>
public void InsertPageBreakAfterSelf()
{
XElement p = new XElement
(
XName.Get("p", DocX.w.NamespaceName),
new XElement
(
XName.Get("r", DocX.w.NamespaceName),
new XElement
(
XName.Get("br", DocX.w.NamespaceName),
new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
)
)
);
xml.AddAfterSelf(p);
}
/// <summary>
/// Insert a page break before a Paragraph.
/// </summary>
/// <example>
/// Insert 2 Paragraphs into a document with a page break between them.
/// <code>
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph.
/// Paragraph p1 = document.InsertParagraph("Paragraph 1", false);
///
/// // Insert a new Paragraph.
/// Paragraph p2 = document.InsertParagraph("Paragraph 2", false);
///
/// // Insert a page break before Paragraph two.
/// p2.InsertPageBreakBeforeSelf();
///
/// // Save this document.
/// document.Save();
/// }// Release this document from memory.
/// </code>
/// </example>
public void InsertPageBreakBeforeSelf()
{
XElement p = new XElement
(
XName.Get("p", DocX.w.NamespaceName),
new XElement
(
XName.Get("r", DocX.w.NamespaceName),
new XElement
(
XName.Get("br", DocX.w.NamespaceName),
new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
)
)
);
xml.AddBeforeSelf(p);
}
/// <summary>
/// Insert a Paragraph after this Paragraph, this Paragraph may have come from the same or another document.
/// </summary>

+ 86
- 0
DocX/Table.cs Целия файл

@@ -710,6 +710,92 @@ namespace Novacode
}
}
/// <summary>
/// Insert a page break after a Table.
/// </summary>
/// <example>
/// Insert a Table and a Paragraph into a document with a page break between them.
/// <code>
/// // Create a new document.
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Table.
/// Table t1 = document.InsertTable(2, 2);
/// t1.Design = TableDesign.LightShadingAccent1;
///
/// // Insert a page break after this Table.
/// t1.InsertPageBreakAfterSelf();
///
/// // Insert a new Paragraph.
/// Paragraph p1 = document.InsertParagraph("Paragraph", false);
///
/// // Save this document.
/// document.Save();
/// }// Release this document from memory.
/// </code>
/// </example>
public void InsertPageBreakAfterSelf()
{
XElement p = new XElement
(
XName.Get("p", DocX.w.NamespaceName),
new XElement
(
XName.Get("r", DocX.w.NamespaceName),
new XElement
(
XName.Get("br", DocX.w.NamespaceName),
new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
)
)
);
xml.AddAfterSelf(p);
}
/// <summary>
/// Insert a page break before a Table.
/// </summary>
/// <example>
/// Insert a Table and a Paragraph into a document with a page break between them.
/// <code>
/// // Create a new document.
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph.
/// Paragraph p1 = document.InsertParagraph("Paragraph", false);
///
/// // Insert a new Table.
/// Table t1 = document.InsertTable(2, 2);
/// t1.Design = TableDesign.LightShadingAccent1;
///
/// // Insert a page break before this Table.
/// t1.InsertPageBreakBeforeSelf();
///
/// // Save this document.
/// document.Save();
/// }// Release this document from memory.
/// </code>
/// </example>
public void InsertPageBreakBeforeSelf()
{
XElement p = new XElement
(
XName.Get("p", DocX.w.NamespaceName),
new XElement
(
XName.Get("r", DocX.w.NamespaceName),
new XElement
(
XName.Get("br", DocX.w.NamespaceName),
new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
)
)
);
xml.AddBeforeSelf(p);
}
/// <summary>
/// Insert a new Table before this Table, this Table can be from this document or another document.
/// </summary>

Loading…
Отказ
Запис