开发人员, 您好!
想询问一个功能, 在WPS办公软件中, 有非常方便的查找替换字体, 查找替换颜色的功能, 这个在MSoffice中好像是没有,
请问在spire doc中有类似的函数可以实现吗?
具体一点描述:
我想把打开的文件中, 使用宋体的文字,全部替换为黑体, 所有红颜色的文字全部替换为蓝颜色
提前感谢!
Document document = new Document();
document.LoadFromFile(inputFile);
TextSelection[] selections = document.FindAllString("查找文本", false,true);
foreach (TextSelection selection in selections)
{
TextRange range = selection.GetAsOneRange();
//设置字体
range.CharacterFormat.FontName = "黑体";
//设置文本颜色
range.CharacterFormat.TextColor = System.Drawing.Color.Blue;
}
document.SaveToFile(outputFile, FileFormat.Docx2010);Annika.Zhou wrote:您好,
感谢您的咨询。
我们的Spire.Doc遵循MS Word的规则,功能特性也基本参照MS Word的功能,所以你提到的替换字体和替换文字颜色的功能我们的Spire.Doc目前还不支持。但我已将这个新功能提交给我们的开发团队,问题编号为SPIREDOC-7575,我们的开发人员会调查并确定是否能实现。一旦有任何更新,我会及时通知你的。
另外,我们的Spire.Doc支持通过查找文本来替换字体或文字颜色,请参考下面的代码:
- Code: Select all
Document document = new Document();
document.LoadFromFile(inputFile);
TextSelection[] selections = document.FindAllString("查找文本", false,true);
foreach (TextSelection selection in selections)
{
TextRange range = selection.GetAsOneRange();
//设置字体
range.CharacterFormat.FontName = "黑体";
//设置文本颜色
range.CharacterFormat.TextColor = System.Drawing.Color.Blue;
}
document.SaveToFile(outputFile, FileFormat.Docx2010);
Sincerely,
Annika
E-iceblue support team