One More Question,
I have a RegX expression and I need to use it to replace a certain Text with a HyperLink.
Any Help on this Please ?
Regards,
Document document = new Document();
document.LoadFromFile(@"..\..\Test.docx", FileFormat.Docx2010);
Section section=document.Sections[0];
ParagraphStyle myStyle = new ParagraphStyle(document);
myStyle.Name = "myStyle";
myStyle.CharacterFormat.FontName = "Times New Roman";
document.Styles.Add(myStyle);
for (int i = 0; i < section.Paragraphs.Count; i++)
{
section.Paragraphs[i].ApplyStyle(myStyle.Name);
}
document.SaveToFile(@"..\..\TestResult.docx", FileFormat.Docx);
document.SaveToFile(@"..\..\TestResult.html", FileFormat.Html);
System.Diagnostics.Process.Start(@"..\..\TestResult.html");
Document document = new Document();
document.LoadFromFile(@"..\..\Test.docx", FileFormat.Docx2010);
Regex regex = new Regex(@"Spire.Office");
TextSelection[] selections = document.FindAllPattern(regex);
Section tempSection = document.AddSection();
for (int i = selections.Length-1; i >=0; i--)
{
ITextRange txtRange = selections[i].GetAsOneRange();
string txtVal = txtRange.Text;
txtVal = txtVal.Replace(@"Spire.Office","http://www.e-iceblue.com");
txtRange.Text = txtVal;
}
document.Sections.Remove(tempSection);
document.SaveToFile(@"..\..\TestResult.docx",FileFormat.Docx2010);
System.Diagnostics.Process.Start(@"..\..\TestResult.docx");
Tina.Lin wrote:Hello,
I have made a simple demo which may meet your requirement. Please try the following code:
- Code: Select all
Document document = new Document();
document.LoadFromFile(@"..\..\Test.docx", FileFormat.Docx2010);
Regex regex = new Regex(@"Spire.Office");
TextSelection[] selections = document.FindAllPattern(regex);
Section tempSection = document.AddSection();
for (int i = selections.Length-1; i >=0; i--)
{
ITextRange txtRange = selections[i].GetAsOneRange();
string txtVal = txtRange.Text;
txtVal = txtVal.Replace(@"Spire.Office","http://www.e-iceblue.com");
txtRange.Text = txtVal;
}
document.Sections.Remove(tempSection);
document.SaveToFile(@"..\..\TestResult.docx",FileFormat.Docx2010);
System.Diagnostics.Process.Start(@"..\..\TestResult.docx");
If you still have any other questions, please don't hesitate to contact us.
Have a nice day.