How to add column header using xlswrite1?

1 回表示 (過去 30 日間)
Ganesh K Davanagege
Ganesh K Davanagege 2016 年 11 月 26 日
編集済み: Walter Roberson 2016 年 11 月 27 日
I have the problem with this code. I have used xlswrite1 to write into Excel file. I want to add column and row header to the data. I have the problem in xlswrite1 which gives the error as
Error using xlswrite1 (line 142)
Error: Object returned error code: 0x800A03EC
Error in xlswrite1 (line 142)
error('MATLAB:xlswrite:SelectDataRange',lasterr);
%%Multiple variable with label - Writing into excel file - Active X
clc
tic
Excel = actxserver ('Excel.Application');
File='testdata.xlsx';
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
end
timeVariable=20*rand(1,10)
timeVariable = timeVariable'
tempVariable = 10*rand(1,10)
tempVariable = tempVariable'
a={'Time','Temperature'}
b= [timeVariable tempVariable]
c.col = a
c.val = b
sheet = 1;
xlswrite1(filename,c.col,sheet,'A1')
xlswrite1(filename,c.val,sheet,'A2')
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
Excel.delete
clear Excel
toc

回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by