在文档doc xlsread
中描述了可以[num,txt,raw] = xlsread('example.xls')
用来将数据从 excel 表中提取到 matlab 中。
我有一张包含要复制到其他工作表的公式的工作表,但是xlread
将采用解释的公式值而不是公式本身。例如,一个公式是=AVERAGE(B8:V8)
我想以编程方式从工作表中提取的公式,但是 excel 返回的值0.810
是公式将返回的值。
是否可以使用matlab以任何方式提取公式?
这是不可能的xlsread
。
使用 COM 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)
无法使用xlsread
,您必须使用可用于读取 excel 文件或访问 excel 的 API 之一。据我所知,选择是: