ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { // Create a builder to insert the field. DocumentBuilder builder = new DocumentBuilder((Aspose.Words.Document)args.MatchNode.Document); // Move to the first node of the match. builder.MoveTo(args.MatchNode); // If the user specified text to be used in the field as display text then use that, otherwise use the // match string as the display text. string insertText; if (!string.IsNullOrEmpty(mFieldText)) { insertText = mFieldText; } else { insertText = args.Match.Value; } // Insert the TC field before this node using the specified string as the display text and user defined switches. builder.InsertField(string.Format("TC \"{0}\" {1}", insertText, mFieldSwitches)); // We have done what we want so skip replacement. return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs args) { Debug.WriteLine(args.Match.Value); args.Replacement = string.Format("{0} {1}", mCounter++, args.Match.Value); return(ReplaceAction.Replace); }
/// <summary> /// This is called during a replace operation each time a match is found. /// This method appends a number to the match string and returns it as a replacement string. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { e.Replacement = e.Match + mMatchNumber.ToString(); mMatchNumber++; return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs args) { ArrayList runs = FindAndSplitMatchRuns(args); // Create DocumentBuilder which is used to insert the field. DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document); builder.MoveTo((Run)runs[runs.Count - 1]); // Calculate the name of the field from the FieldType enumeration by removing the first instance of "Field" from the text. // This works for almost all of the field types. string fieldName = mFieldType.ToString().ToUpper().Substring(5); // Insert the field into the document using the specified field type and the match text as the field name. // If the fields you are inserting do not require this extra parameter then it can be removed from the string below. builder.InsertField(string.Format("{0} {1}", fieldName, args.Match.Groups[0])); // Now remove all runs in the sequence. foreach (Run run in runs) { run.Remove(); } // Signal to the replace engine to do nothing because we have already done all what we wanted. return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs args) { _mergeReplacePosition++; var insert = _inserts.FirstOrDefault(p => p.Attribute(SchemaConstants._INSERTS_ID).Value == _mergeReplacePosition.ToString()); if (insert != null) { if (insert.Value == "{{{") { ifLevel++; maxIf = Math.Max(ifLevel, maxIf); insert.Value = "{{" + string.Format(@"{0}", ifLevel) + "{"; currentLevel.Push(ifLevel); } if (insert.Value == "}}}") { insert.Value = "}}" + string.Format("{0}", currentLevel.Pop() + "}"); Run currentRun = args.MatchNode as Run; Paragraph paragraph = currentRun.ParentParagraph; // Reduce the indent level } args.Replacement = insert.Value; } else { _blankReplacements.Add(args.MatchNode); } return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); //插入图片 //Aspose.Words.Drawing.Shape s = //50 相对位置 pagecount if (!IsTable) { builder.InsertImage(url, Aspose.Words.Drawing.RelativeHorizontalPosition.Character, left, Aspose.Words.Drawing.RelativeVerticalPosition.Paragraph, top, width, height, Aspose.Words.Drawing.WrapType.None); } else { builder.InsertImage(url, Aspose.Words.Drawing.RelativeHorizontalPosition.Column, 0, Aspose.Words.Drawing.RelativeVerticalPosition.TableDefault, 2, width, height, Aspose.Words.Drawing.WrapType.None); } return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs args) { mCurrentReplacementNumber++; // Parse numbers int number = Convert.ToInt32(args.Match.Value); // And write it as HEX args.Replacement = $"0x{number:X} (replacement #{mCurrentReplacementNumber})"; Console.WriteLine($"Match #{mCurrentReplacementNumber}"); Console.WriteLine($"\tOriginal value:\t{args.Match.Value}"); Console.WriteLine($"\tReplacement:\t{args.Replacement}"); Console.WriteLine($"\tOffset in parent {args.MatchNode.NodeType} node:\t{args.MatchOffset}"); if (string.IsNullOrEmpty(args.GroupName)) { Console.WriteLine($"\tGroup index:\t{args.GroupIndex}"); } else { Console.WriteLine($"\tGroup name:\t{args.GroupName}"); } return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { mLog.AppendLine($"\"{args.Match.Value}\" converted to \"{args.Replacement}\" " + $"{args.MatchOffset} characters into a {args.MatchNode.NodeType} node."); args.Replacement = $"(Old value:\"{args.Match.Value}\") {args.Replacement}"; return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs e) { Node currentNode = e.MatchNode; if (currentNode.NodeType != NodeType.Run || currentNode.Range.Text.Trim() == string.Empty) { return(ReplaceAction.Skip); } if (e.MatchOffset > 0) { currentNode = SplitRun((Run)currentNode, e.MatchOffset); } List <Node> runs = new List <Node>(); int remainingLength = e.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; do { currentNode = currentNode.NextSibling; } while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } foreach (Run run in runs) { run.Text = string.Empty; run.Font.HighlightColor = CommentsQualifer.GetHighlightColor(); } ((Run)runs.First()).Text = CommentsQualifer.CommentErrorText; Aspose.Words.Comment comment = new Aspose.Words.Comment(runs.First().Document); comment.Paragraphs.Add(new Paragraph(comment.Document)); string text = e.Replacement; text = text.Replace(CommentsQualifer.CommentsBegin, string.Empty); text = text.Replace(CommentsQualifer.CommentsEnd, string.Empty); comment.FirstParagraph.SetText(text); runs.First().ParentNode.InsertBefore(new CommentRangeStart(comment.Document, comment.Id), runs.First()); runs.First().ParentNode.InsertAfter(new CommentRangeEnd(comment.Document, comment.Id), runs.Last()); runs.Last().ParentNode.AppendChild(comment); return(ReplaceAction.Skip); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document); builder.MoveTo(e.MatchNode); builder.InsertHtml(_value); e.Replacement = ""; return(ReplaceAction.Replace); }
/// <summary> /// This method is called by the Aspose.Words find and replace engine for each match. /// This method replaces the match string, even if it spans multiple runs. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // This is a Run node that contains either the beginning or the complete match. Node currentNode = e.MatchNode; // The first (and may be the only) run can contain text before the match, // in this case it is necessary to split the run. if (e.MatchOffset > 0) { currentNode = SplitRun((Run)currentNode, e.MatchOffset); } // This array is used to store all nodes of the match for further removing. ArrayList runs = new ArrayList(); // Find all runs that contain parts of the match string. int remainingLength = e.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; // Select the next Run node. // Have to loop because there could be other nodes such as BookmarkStart etc. do { currentNode = currentNode.NextSibling; }while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } // Split the last run that contains the match if there is any text left. if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } // Create Document Buidler and insert text. DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document); builder.MoveTo((Run)runs[runs.Count - 1]); builder.Write(mText); // Now remove all runs in the sequence. foreach (Run run in runs) { run.Remove(); } // Signal to the replace engine to do nothing because we have already done all what we wanted. return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs args) { // Parse numbers. int number = Convert.ToInt32(args.Match.Value); // And write it as HEX. args.Replacement = String.Format("0x{0:X}", number); return(ReplaceAction.Replace); }
//This simplistic method will only work well when the match starts at the beginning of a run. ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document); builder.MoveTo(args.MatchNode); // Replace '<CustomerName>' text with a red bold name. builder.InsertHtml("<b><font color='red'>James Bond, </font></b>"); args.Replacement = ""; return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // This is a Run node that contains either the beginning or the complete match. Node currentNode = e.MatchNode; if (builder == null) { builder = new DocumentBuilder((Document)currentNode.Document); } // The first (and may be the only) run can contain text before the match, // in this case it is necessary to split the run. if (e.MatchOffset > 0) { currentNode = SplitRun((Run)currentNode, e.MatchOffset); } ArrayList runs = new ArrayList(); // Find all runs that contain parts of the match string. int remainingLength = e.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; // Select the next Run node. // Have to loop because there could be other nodes such as BookmarkStart etc. do { currentNode = currentNode.NextSibling; }while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } // Split the last run that contains the match if there is any text left. if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } Run run = (Run)runs[0]; builder.MoveTo(run); builder.StartBookmark("bookmark_" + i); builder.EndBookmark("bookmark_" + i); i++;; // Signal to the replace engine to do nothing because we have already done all what we wanted. return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); var text = node.GetText().Trim('{', '}', ' '); var item = formItems.SingleOrDefault(c => c["Name"] == text); if (text.StartsWith("S:")) //子表开始 { builder.InsertField(@"MERGEFIELD " + "TableStart:" + text.Split(':')[1] + @" \* MERGEFORMAT"); builder.InsertField(@"MERGEFIELD " + text.Split(':')[2] + @" \* MERGEFORMAT"); } else if (text.StartsWith("E:"))//子表结束 { builder.InsertField(@"MERGEFIELD " + text.Split(':')[2] + @" \* MERGEFORMAT"); builder.InsertField(@"MERGEFIELD " + "TableEnd:" + text.Split(':')[1] + @" \* MERGEFORMAT"); } else if (text.StartsWith("F:")) //子表字段 { builder.InsertField(@"MERGEFIELD " + text.Split(':')[1] + @" \* MERGEFORMAT"); } else if (text.StartsWith("TableStart:") || text.StartsWith("TableEnd:")) //子表开头和结束 { builder.InsertField(@"MERGEFIELD " + text + @" \* MERGEFORMAT"); } else if (text.StartsWith("Field:"))//子表字段 { builder.InsertField(@"MERGEFIELD " + text.Split(':')[1] + @" \* MERGEFORMAT"); } else if (item != null) //表单字段 { if (item["ItemType"] == "ButtonEdit") { builder.InsertField(@"MERGEFIELD " + item["Code"] + "Name" + @" \* MERGEFORMAT"); } else { builder.InsertField(@"MERGEFIELD " + item["Code"] + @" \* MERGEFORMAT"); } } else { builder.InsertField(@"MERGEFIELD " + text + @" \* MERGEFORMAT"); } return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; DocumentUtility.InsertDocument(para, _subDoc); // Remove the paragraph with the match text. para.Remove(); return(ReplaceAction.Skip); }
// Token: 0x0600001A RID: 26 RVA: 0x0000308C File Offset: 0x0000128C ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Document document = new Document(this.vfilename); document.FirstSection.Body.FirstParagraph.InsertAfter(new Run(document, this.pNum + "."), null); Node matchNode = e.MatchNode; Paragraph insertAfterNode = (Paragraph)e.MatchNode.ParentNode; AsposeWordApp.InsertDocument(insertAfterNode, document); e.MatchNode.Remove(); e.MatchNode.Range.Delete(); return(ReplaceAction.Skip); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Node currentNode = e.MatchNode; DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document); builder.MoveTo(currentNode); builder.InsertHtml(e.Replacement); currentNode.Remove(); return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 if (!string.IsNullOrEmpty(Text)) { Node node = e.MatchNode; Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveTo(node); builder.Write(Text); } return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); //插入图片 builder.InsertHtml(html); return ReplaceAction.Replace; }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); builder.Write(text); return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { Document subDoc = new Document(MyDir + "Document insertion 2.docx"); // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)args.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text. para.Remove(); return(ReplaceAction.Skip); }
/// <summary> /// This method is called by the Aspose.Words find and replace engine for each match. /// This method replaces the match string, even if it spans multiple runs. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // This is a Run node that contains either the beginning or the complete match. Node currentNode = e.MatchNode; // The first (and may be the only) run can contain text before the match, // in this case it is necessary to split the run. if (e.MatchOffset > 0) currentNode = SplitRun((Run)currentNode, e.MatchOffset); // This array is used to store all nodes of the match for further removing. ArrayList runs = new ArrayList(); // Find all runs that contain parts of the match string. int remainingLength = e.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; // Select the next Run node. // Have to loop because there could be other nodes such as BookmarkStart etc. do { currentNode = currentNode.NextSibling; } while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } // Split the last run that contains the match if there is any text left. if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } // Create Document Buidler and insert text. DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document); builder.MoveTo((Run)runs[runs.Count - 1]); builder.Write(mText); // Now remove all runs in the sequence. foreach (Run run in runs) run.Remove(); // Signal to the replace engine to do nothing because we have already done all what we wanted. return ReplaceAction.Skip; }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document); builder.MoveTo(args.MatchNode); // If the user-specified text to be used in the field as display text, then use that, // otherwise use the match string as the display text. string insertText = !string.IsNullOrEmpty(mFieldText) ? mFieldText : args.Match.Value; builder.InsertField($"TC \"{insertText}\" {mFieldSwitches}"); return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); //插入图片 builder.InsertImage(url, horzPos, left, vertPos, top, width, height, wrapType); return(ReplaceAction.Replace); }
public ReplaceAction Replacing(ReplacingArgs e) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); //插入图片 builder.InsertImage(url); return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Aspose.Words.Document subDoc = new Aspose.Words.Document(MyDir + "InsertDocument2.doc"); // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text. para.Remove(); return(ReplaceAction.Skip); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { Document subDoc = new Document("C:\\Personal Development\\CV merging\\Data\\CV Out.docx"); //Insert a document after the paragraph, containing the matched text Paragraph para = (Paragraph)args.MatchNode.ParentNode; InsertDocument(para, subDoc); //Remove the paragraph with the matched text para.Remove(); return(ReplaceAction.Skip); }
/// <summary> /// This method is called by the Aspose.Words find and replace engine for each match. /// This method highlights the match string, even if it spans multiple runs. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // This is a Run node that contains either the beginning or the complete match. Node currentNode = e.MatchNode; // The first (and may be the only) run can contain text before the match, // in this case it is necessary to split the run. if (e.MatchOffset > 0) { currentNode = SplitRun((Run)currentNode, e.MatchOffset); } // This array is used to store all nodes of the match for further highlighting. ArrayList runs = new ArrayList(); // Find all runs that contain parts of the match string. int remainingLength = e.Match.Value.Length; while ( remainingLength > 0 && currentNode != null && currentNode.GetText().Length <= remainingLength) { runs.Add(currentNode); remainingLength -= currentNode.GetText().Length; // Select the next Run node. // Have to loop because there could be other nodes such as BookmarkStart etc. do { currentNode = currentNode.NextSibling; } while (currentNode != null && currentNode.NodeType != NodeType.Run); } // Split the last run that contains the match if there is any text left. if (currentNode != null && remainingLength > 0) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } // Now highlight all runs in the sequence. foreach (Run run in runs) { run.Font.HighlightColor = Color.Yellow; } // Signal to the replace engine to do nothing because we have already done all what we wanted. return(ReplaceAction.Skip); }
public ReplaceAction Replacing(ReplacingArgs args) { // Let replacement to be the same text. args.Replacement = args.Match.Value; int val = int.Parse(args.Match.Value); // Apply either red or green color depending on the number value sign. mOpt.ApplyFont.Color = (val > 0) ? Color.Green : Color.Red; return(ReplaceAction.Replace); }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Document subDoc = new Document(RunExamples.GetDataDir_WorkingWithDocument() + "InsertDocument2.doc"); // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text. para.Remove(); return(ReplaceAction.Skip); }
///<Summary> /// Replacing ///</Summary> public ReplaceAction Replacing(ReplacingArgs args) { MatchesFound += 1; if (MatchedNodes.ContainsKey(args.MatchNode)) { MatchedNodes[args.MatchNode].Add(args); return(ReplaceAction.Skip); } MatchedNodes.Add(args.MatchNode, new List <ReplacingArgs>() { args }); return(ReplaceAction.Skip); }
/// <summary> /// Finds and splits the match runs and returns them in an ArrayList. /// </summary> public ArrayList FindAndSplitMatchRuns(ReplacingArgs args) { // This is a Run node that contains either the beginning or the complete match. Node currentNode = args.MatchNode; // The first (and may be the only) run can contain text before the match, // in this case it is necessary to split the run. if (args.MatchOffset > 0) currentNode = SplitRun((Run)currentNode, args.MatchOffset); // This array is used to store all nodes of the match for further removing. ArrayList runs = new ArrayList(); // Find all runs that contain parts of the match string. int remainingLength = args.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; // Select the next Run node. // Have to loop because there could be other nodes such as BookmarkStart etc. do { currentNode = currentNode.NextSibling; } while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } // Split the last run that contains the match if there is any text left. if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } return runs; }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { // Create a builder to insert the field. DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document); // Move to the first node of the match. builder.MoveTo(args.MatchNode); // If the user specified text to be used in the field as display text then use that, otherwise use the // Match string as the display text. string insertText; if (!string.IsNullOrEmpty(mFieldText)) insertText = mFieldText; else insertText = args.Match.Value; // Insert the TC field before this node using the specified string as the display text and user defined switches. builder.InsertField(string.Format("TC \"{0}\" {1}", insertText, mFieldSwitches)); // We have done what we want so skip replacement. return ReplaceAction.Skip; }
public ReplaceAction Replacing(ReplacingArgs args) { ArrayList runs = FindAndSplitMatchRuns(args); // Create DocumentBuilder which is used to insert the field. DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document); builder.MoveTo((Run)runs[runs.Count - 1]); // Calculate the name of the field from the FieldType enumeration by removing the first instance of "Field" from the text. // This works for almost all of the field types. string fieldName = mFieldType.ToString().ToUpper().Substring(5); // Insert the field into the document using the specified field type and the match text as the field name. // If the fields you are inserting do not require this extra parameter then it can be removed from the string below. builder.InsertField(string.Format("{0} {1}", fieldName, args.Match.Groups[0])); // Now remove all runs in the sequence. foreach (Run run in runs) run.Remove(); // Signal to the replace engine to do nothing because we have already done all what we wanted. return ReplaceAction.Skip; }
/// <summary> /// NOTE: This is a simplistic method that will only work well when the match /// starts at the beginning of a run. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { DocumentBuilder builder = new DocumentBuilder((Aspose.Words.Document)e.MatchNode.Document); builder.MoveTo(e.MatchNode); // Replace '<CustomerName>' text with a red bold name. builder.InsertHtml("<b><font color='red'>James Bond</font></b>"); e.Replacement = ""; return ReplaceAction.Replace; }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Aspose.Words.Document subDoc = new Aspose.Words.Document(ExDir + "InsertDocument2.doc"); // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text. para.Remove(); return ReplaceAction.Skip; }
public ReplaceAction Replacing(ReplacingArgs e, int width, int height) { //获取当前节点 var node = e.MatchNode; //获取当前文档 Document doc = node.Document as Document; DocumentBuilder builder = new DocumentBuilder(doc); //将光标移动到指定节点 builder.MoveTo(node); //插入图片 builder.InsertImage(url, width, height); return ReplaceAction.Replace; }
/// <summary> /// This is called during a replace operation each time a match is found. /// This method appends a number to the match string and returns it as a replacement string. /// </summary> ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { e.Replacement = e.Match.ToString() + mMatchNumber.ToString(); mMatchNumber++; return ReplaceAction.Replace; }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // This is the run node that contains the found text. Note that the run might contain other // text apart from the URL. All the complexity below is just to handle that. I don't think there // is a simpler way at the moment. Run run = (Run)e.MatchNode; Paragraph para = run.ParentParagraph; string url = e.Match.Value; // We are using \xbf (inverted question mark) symbol for temporary purposes. // Any symbol will do that is non-special and is guaranteed not to be presented in the document. // The purpose is to split the matched run into two and insert a hyperlink field between them. para.Range.Replace(url, "\xbf", true, true); Run subRun = (Run)run.Clone(false); int pos = run.Text.IndexOf("\xbf"); subRun.Text = subRun.Text.Substring(0, pos); run.Text = run.Text.Substring(pos + 1, run.Text.Length - pos - 1); para.ChildNodes.Insert(para.ChildNodes.IndexOf(run), subRun); mBuilder.MoveTo(run); // Specify font formatting for the hyperlink. mBuilder.Font.Color = System.Drawing.Color.Blue; mBuilder.Font.Underline = Underline.Single; // Insert the hyperlink. mBuilder.InsertHyperlink(url, url, false); // Clear hyperlink formatting. mBuilder.Font.ClearFormatting(); // Let's remove run if it is empty. if (run.Text.Equals("")) run.Remove(); // No replace action is necessary - we have already done what we intended to do. return ReplaceAction.Skip; }
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { Document subDoc = new Document(RunExamples.GetDataDir_WorkingWithDocument() + "InsertDocument2.doc"); // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text. para.Remove(); return ReplaceAction.Skip; }