在MS Word中填写表格需要花费很多时间 [英] Filling table takes a lot of time in MS Word

查看:104
本文介绍了在MS Word中填写表格需要花费很多时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了以下代码,将外部数据表添加到MS Word文档中的另一个表中,它可以正常工作,但是在行数大于100的情况下以及在添加有行的表的情况下会花费很多时间计数超过500,它会非常缓慢地填充ms字表,并且无法完成任务.

I made the following code to add external data table to another table in MS word document, its working fine but takes a lot of time in case that the number of rows is more than 100, and in case of adding table with rows count more that 500 it fills the ms word table really slow and can't complete the task.

我试图隐藏文档并禁用该文档的屏幕更新,但仍然无法解决性能降低的问题.

I tried to hide the document and disable the screen update for the document but still no solution for the slow performance.

//Get the required external data to the DT data table            
DataTable DT = XDt.GetData();
Word.Table TB;
int X = 1;
foreach (DataRow Rw in DT.Rows)
{
    Word.Row Rn = TB.Rows.Add(TB.Rows[X + 1]);

    for(int i=0;i<=DT.Columns.Count-1;i++)
        {
           Rn.Cells[i+1].Range.Text = Rw[i].ToString()); 
        }
    X++;
}

那么有没有办法使这个过程更快?

So is there a way to make this process go faster ?

推荐答案

向Word中添加表的最有效方法是首先将数据连接到带分隔符的文本字符串中,其中"/n"必须是结束符行(记录分隔符).单元格结尾(字段分隔符)可以是您喜欢的任何字符,但不在组成表的字符串内容中.

The most efficient way to add a table to Word is to first concatenate the data in a delimited text string, where "/n" must be the symbol for end-of-row (record separator). The end-of-cell (field separator) can be any character you like that's not in the string content that makes up the table.

将此字符串分配给Range对象,然后使用ConvertToTable()方法创建表.

Assign this string to a Range object, then use the ConvertToTable() method to create the table.

这篇关于在MS Word中填写表格需要花费很多时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆