如test.doc文档所示,我想对该文档第21页的一些段落设置一些样式,具体的样式参照expect.doc文档。expect.doc是我的期望文档。help.zip (41.1 KB)
还请提供一个比较屏幕截图,突出显示test.doc和Expect.doc文件之间的问题区域,并将其附加在此处以供我们参考。 还请分享您当前正在使用的源代码。 谢谢你的合作。
您可以使用以下代码在Word文档中居中对齐任何段落:
Document doc = new Document("E:\\temp\\help\\test.doc");
Paragraph targetPara = null;
foreach(Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (para.ToString(SaveFormat.Text).Trim().Equals("资产评估师签章:"))
{
targetPara = para;
break;
}
}
if (targetPara !=null)
{
targetPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
doc.Save(“E:\temp\help\19.10.docx”);
我想在两个段落之间插入空行,test.png是我的测试截图,exphelp.zip (58.8 KB)
ect.doc是我的期望截图。test.doc是我的测试文档,expect.doc是我的期望文档。
您可以在以下代码上构建逻辑以在Word文档中插入空白段落:
Document doc = new Document("E:\\temp\\help\\test.doc");
Paragraph targetPara = null;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (para.ToString(SaveFormat.Text).Trim().Equals("资产评估师签章:"))
{
targetPara = para;
break;
}
}
if (targetPara != null)
{
targetPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// insert a blank paragraph after this para
Paragraph blankPara = new Paragraph(doc);
targetPara.ParentNode.InsertAfter(blankPara, targetPara);
// add another blank para
targetPara.ParentNode.InsertAfter(blankPara.Clone(false), targetPara);
}
doc.Save("E:\\temp\\help\\19.10.docx");