0

在文档doc xlsread中描述了可以[num,txt,raw] = xlsread('example.xls')用来将数据从 excel 表中提取到 matlab 中。

我有一张包含要复制到其他工作表的公式的工作表,但是xlread将采用解释的公式而不是公式本身。例如,一个公式是=AVERAGE(B8:V8)我想以编程方式从工作表中提取的公式,但是 excel 返回的值0.810是公式将返回的值。

是否可以使用matlab以任何方式提取公式?

4

2 回答 2

4

这是不可能的xlsread

使用 COM Excel 对象的一个​​示例:

例如,让我们使用一个简单的 Excel 表,其中包含文本、值和公式:

excel片段

然后是下面的代码:

xlfile  = 'test1.xlsx' ;
xlRange = 'B3:C6' ;

exl = actxserver('excel.application');                  %// Create a COM server
exlFile    = exl.Workbooks.Open( [pwd '\' xlfile] );    %'// Open the file
exlSheet1  = exlFile.Sheets.Item('Sheet1');             %// Choose the worksheet
strFormula = exlSheet1.Range(xlRange).Formula           %// Read the full range

产生一个很好的单元阵列:

strFormula = 
    'This is text'       'hello'          
    'this is value'      '12.5'           
    'this is value'      '29'             
    'this is formula'    '=AVERAGE(C4:C5)'

如果您直接知道特定单元格的地址,则返回一个简单的字符串:

cellFormula = exlSheet1.Range('C6').Formula             %// Read a single cell

cellFormula =
=AVERAGE(C4:C5)
于 2015-08-05T20:04:47.530 回答
1

无法使用xlsread,您必须使用可用于读取 excel 文件或访问 excel 的 API 之一。据我所知,选择是:

于 2015-08-05T19:36:38.383 回答