Quellcode durchsuchen

Added ability to insert document at the beggining

Fixed an issue in Replace when the match length is 0 + some optimizations
master
fitdev@hotmail.com vor 10 Jahren
Ursprung
Commit
897641745f
2 geänderte Dateien mit 13 neuen und 8 gelöschten Zeilen
  1. 8
    4
      DocX/DocX.cs
  2. 5
    4
      DocX/Paragraph.cs

+ 8
- 4
DocX/DocX.cs Datei anzeigen

/// Insert the contents of another document at the end of this document. /// Insert the contents of another document at the end of this document.
/// </summary> /// </summary>
/// <param name="remote_document">The document to insert at the end of this document.</param> /// <param name="remote_document">The document to insert at the end of this document.</param>
/// <param name="append">If true, document is inserted at the end, otherwise document is inserted at the beginning.</param>
/// <example> /// <example>
/// Create a new document and insert an old document into it. /// Create a new document and insert an old document into it.
/// <code> /// <code>
/// If the document being inserted contains Images, CustomProperties and or custom styles, these will be correctly inserted into the new document. In the case of Images, new ID's are generated for the Images being inserted to avoid ID conflicts. CustomProperties with the same name will be ignored not replaced. /// If the document being inserted contains Images, CustomProperties and or custom styles, these will be correctly inserted into the new document. In the case of Images, new ID's are generated for the Images being inserted to avoid ID conflicts. CustomProperties with the same name will be ignored not replaced.
/// </remarks> /// </remarks>
/// </example> /// </example>
public void InsertDocument(DocX remote_document)
public void InsertDocument(DocX remote_document, bool append = true)
{ {
// We don't want to effect the origional XDocument, so create a new one from the old one. // We don't want to effect the origional XDocument, so create a new one from the old one.
XDocument remote_mainDoc = new XDocument(remote_document.mainDoc); XDocument remote_mainDoc = new XDocument(remote_document.mainDoc);
// Add the remote documents contents to this document. // Add the remote documents contents to this document.
XElement local_body = mainDoc.Root.Element(XName.Get("body", DocX.w.NamespaceName)); XElement local_body = mainDoc.Root.Element(XName.Get("body", DocX.w.NamespaceName));
local_body.Add(remote_body.Elements());
if (append)
local_body.Add(remote_body.Elements());
else
local_body.AddFirst(remote_body.Elements());
// Copy any missing root attributes to the local document.
foreach (XAttribute a in remote_mainDoc.Root.Attributes())
// Copy any missing root attributes to the local document.
foreach (XAttribute a in remote_mainDoc.Root.Attributes())
{ {
if (mainDoc.Root.Attribute(a.Name) == null) if (mainDoc.Root.Attribute(a.Name) == null)
{ {

+ 5
- 4
DocX/Paragraph.cs Datei anzeigen

{ {
string repl = newValue; string repl = newValue;
//perform RegEx substitutions. Only named groups are not supported. Everything else is supported. However character escapes are not covered. //perform RegEx substitutions. Only named groups are not supported. Everything else is supported. However character escapes are not covered.
if (useRegExSubstitutions)
if (useRegExSubstitutions && !String.IsNullOrEmpty(repl))
{ {
repl = repl.Replace("$&", m.Value); repl = repl.Replace("$&", m.Value);
if (m.Groups.Count > 0) if (m.Groups.Count > 0)
repl = repl.Replace("$_", tText); repl = repl.Replace("$_", tText);
repl = repl.Replace("$$", "$"); repl = repl.Replace("$$", "$");
} }
InsertText(m.Index + m.Length, repl, trackChanges, newFormatting);
RemoveText(m.Index, m.Length, trackChanges);
if (!String.IsNullOrEmpty(repl))
InsertText(m.Index + m.Length, repl, trackChanges, newFormatting);
if (m.Length > 0)
RemoveText(m.Index, m.Length, trackChanges);
} }
} }
} }

Laden…
Abbrechen
Speichern