2012-02-17 63 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