2012-02-17 60 views
1

什么是最快的方式创建,填充和着色行的MS Word表格通过ActiveX - > VBA(在我的具体情况下,我通过MATLAB做)?(MATLAB)ActiveX - > VBA - >填写/逐行着色MS Word表格最快的方法?

现在,我使用它以下列方式

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)表...那么如何提高填表的表现呢?

由于提前,

回答

0

我可以解决很简单的策略上面的问题:

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. 

这解决了填满问题。

背景着色问题可能会超过预定义的表格格式和行方向选择和着色(不是细胞方向)。

Regards,

0

我正在寻找自己的答案。

制作单词应用invisble

wordApp.Visible = 0;     
wordApp.ScreenUpdating = 0; 

减少我的文档的创建时间为50分钟(真的..有很多表)到13