(MATLAB)ActiveX->;VBA->;填充MS Word表格/按行着色的最快方法?

(MATLAB)ActiveX->;VBA->;填充MS Word表格/按行着色的最快方法?,vba,ms-word,activex,Vba,Ms Word,Activex,在ActiveX->VBA上创建、填充和按行着色MS Word表格的最快方法是什么(在我的特殊情况下,我是在MATLAB上完成的) 现在我用下面的方式使用它 hdlActiveX = actxserver('Word.Application'); ... hdlActiveX.ActiveDocument.Tables.Add(hdlActiveX.Selection.Range, nbRows, nbCols, 1, 1).Rows.Alignment = 1; ... % create da

在ActiveX->VBA上创建、填充和按行着色MS Word表格的最快方法是什么(在我的特殊情况下,我是在MATLAB上完成的)

现在我用下面的方式使用它

hdlActiveX = actxserver('Word.Application');
...
hdlActiveX.ActiveDocument.Tables.Add(hdlActiveX.Selection.Range, nbRows, nbCols, 1, 1).Rows.Alignment = 1;
...
% create dataCell{nbRows, nbCols}  containing the table values row- and columnwise
...
nrTable = ... % an integer selecting a table in the MS Word document 
...
for r = 1:nbRows
   for c = 1:nbCols
       % Write data into current cell
      hdlActiveX.ActiveDocument.Tables.Item(1).Cell(r,c).Range.Text = dataCell{r, c};

      % setting a different background color rowwise, if a condtion is met
      % this is even bigger performance reducer
      if condition
          for iCol = 1:nbCols
              hdlActiveX.ActiveDocument.Tables.Item(nrTable).Cell(r,iCol).Select;
              hdlActiveX.Selection.Shading.BackgroundPatternColor = color;
          end
      end

   end
end
但填充起来需要很长时间,特别是在MS Word(ActiveX)表中按行着色。。。那么,如何提高填写表格的性能呢


提前感谢,

我可以用非常简单的策略解决上述问题:

1) create a tab-delimitered text file with the table entries (simulate the table)
2) open over activex the text file, and copy its contents
3) create the table rows/cows
4) paste the contents of the whole table.
这就解决了填充问题

通过预定义的表格格式以及行选择和着色(而不是单元格),可以加快背景着色问题


您好,

我自己也在寻找答案

使应用程序这个词不可见

wordApp.Visible = 0;                
wordApp.ScreenUpdating = 0;
将我的文档创建时间从50分钟(真的..有很多表)减少到13分钟