I attached document called "Doc1.docx ". In that I have Main Headings, Sub Headings and Paragraph.
Now,
I am want to change the Font Size : 13, font-format: Arial for paragraph only.
If you can see 1st page of Document. In paragraph there are bold text and there are some text in Red color also. I want keep that format as it is but want to its font-format and font-size must be change as mentioned.
If you can see 2nd page of document. Paragraph includes bullet point also. I don’t want to make any change in formats. Just want to change the “Font Size : 13, font-format: Arial”
I want to change the font-size: 16 and color: green and font-format: Arial for all sub-Heading in document. (i.e. " Where does it come from?- SubHeading - 1", “Where does it come from?- Sub Heading 2”, " Where does it come from?- Sub Heading 2.1’,“Where does it come from?- Sub Heading 2.2”)Learning.zip (21.0 KB)
It would be great If you reply early for point 1. Below I mentioned point - 1.
I am want to change the Font Size : 13, font-format: Arial for paragraph only .
If you can see 1st page of Document. In paragraph there are bold text and there are some text in Red color also. I want keep that format as it is but want to its font-format and font-size must be change as mentioned.
If you can see 2nd page of document. Paragraph includes bullet point also. I don’t want to make any change in formats. Just want to change the “Font Size : 13, font-format: Arial”
What I understand is that criteria to apply [Font Size : 13, font-format: Arial] is only the Paragraphs that are either bullet points or contain bold text or both. Please try the following code:
Document doc = new Document("C:\\Temp\\Learning\\Doc1.docx");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
// Process Headings
if (para.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading2)
{
foreach (Run run in para.GetChildNodes(NodeType.Run, true))
{
run.Font.Name = "Arial";
run.Font.Size = 16;
run.Font.Color = Color.Green;
}
}
else if (para.IsListItem || ContainsBold(para))
{
foreach (Run run in para.GetChildNodes(NodeType.Run, true))
{
run.Font.Name = "Arial";
run.Font.Size = 13;
}
}
}
doc.Save("C:\\temp\\Learning\\20.9.docx");
public static bool ContainsBold(Paragraph para)
{
bool flag = false;
foreach (Run run in para.GetChildNodes(NodeType.Run, true))
{
if (run.Font.Bold)
{
flag = true;
break;
}
}
return flag;
}
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.