소스 검색

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 10 년 전
부모
커밋
897641745f
2개의 변경된 파일13개의 추가작업 그리고 8개의 파일을 삭제
  1. 8
    4
      DocX/DocX.cs
  2. 5
    4
      DocX/Paragraph.cs

+ 8
- 4
DocX/DocX.cs 파일 보기

@@ -1113,6 +1113,7 @@ namespace Novacode
/// Insert the contents of another document at the end of this document.
/// </summary>
/// <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>
/// Create a new document and insert an old document into it.
/// <code>
@@ -1134,7 +1135,7 @@ namespace Novacode
/// 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>
/// </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.
XDocument remote_mainDoc = new XDocument(remote_document.mainDoc);
@@ -1340,10 +1341,13 @@ namespace Novacode
// Add the remote documents contents to this document.
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)
{

+ 5
- 4
DocX/Paragraph.cs 파일 보기

@@ -3892,7 +3892,7 @@ namespace Novacode
{
string repl = newValue;
//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);
if (m.Groups.Count > 0)
@@ -3920,9 +3920,10 @@ namespace Novacode
repl = repl.Replace("$_", tText);
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);
}
}
}

Loading…
취소
저장