现在200-600页文档,是面包含了很多带背景颜色的表格单元格和applicationFeild,现在需要把所有颜色替换为文档的的背景色,现在的实现性能较低,96页要1分多钟,有没有更好的方式?
主要代码:
Color backColor = wordControl.BackColor;
foreach (ApplicationField appField in tempWordControl.ApplicationFields) // 去掉取数公式的背景色
{
tempWordControl.SetApplicationFieldBackColor(appField, backColor);
}
foreach (Table table in tempWordControl.Tables) // 去掉表格中取数公式的背景色
{
foreach (TableCell cell in table.Cells)
{
cell.CellFormat.BackColor = backColor;
}
}
-------------------------------------------------------------------------
/// <summary>
/// 设置ApplicationField的前景颜色.
/// </summary>
/// <param name="field">字段.</param>
/// <param name="color">颜色.</param>
public void SetApplicationFieldForeColor(ApplicationField field, Color color)
{
if (field != null)
{
Selection backSelection = this.Selection;
try
{
int start = field.Start - 1;
int length = field.Length;
this.Selection = new Selection(start, length);
this.Selection.ForeColor = color;
}
finally
{
this.Selection = backSelection;
} |
|