I have word document in that In headings and titles, capitalize the second part of a hyphenated compound.
kindly find the below attachments.
Input(1)_word_document.docx (12.3 KB)
Expected_output(2)_Document.docx (12.2 KB)
@Yuvarajshivananjappa please consider the following code
FindReplaceOptions options = new FindReplaceOptions();
options.ApplyFont.AllCaps = true;
options.UseSubstitutions = true;
doc.Range.Replace(new Regex("-[a-zA-Z0-9_.-]"), "$0", options);
Your given code capitalize the second part of a hyphenated compound even normal text also I want only capitalize the second part of a hyphenated compound that In headings and titles.
kindly help me. Below code is not filtering headings and titles.
Document doc = new Document(“C:\Users\Yuvaraj\Documents\POC\Input(1)_word_document.docx”);
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph para in paragraphs)
{
if(para.ParagraphFormat.StyleIdentifier==StyleIdentifier.Title|para.ParagraphFormat.StyleIdentifier==StyleIdentifier.Header)
{
FindReplaceOptions options = new FindReplaceOptions();
options.ApplyFont.AllCaps = true;
options.UseSubstitutions = true;
doc.Range.Replace(new Regex("-[a-zA-Z0-9_.-]"), "$0", options);
}
}
string dataDir = @"C:\Users\Yuvaraj\Downloads\Test_5.docx";
doc.Save(dataDir);
Kindly update?
@Yuvarajshivananjappa
Please consider the following code
FindReplaceOptions options = new FindReplaceOptions();
options.ApplyFont.AllCaps = true;
options.UseSubstitutions = true;
foreach (Node node in doc.GetChildNodes(NodeType.Paragraph, true))
{
Paragraph para = node as Paragraph;
if (para.ParagraphFormat.IsHeading || para.ParagraphFormat.StyleIdentifier == StyleIdentifier.Title)
para.Range.Replace(new Regex("-[a-zA-Z0-9_.-]"), "$0", options);
}