without writing any data, I want to create blank excel file.

51 次查看(过去 30 天)
Hello
Initially, I want to create new excel file in a desired location.
Later I will copy some of the sheets from Existing Excel i.e., 'oldExcel to 'newExcel'
excelFile1 = strcat(aaa,'.xlsx'); --------->here I am expecting to create New Blank Excel file (strcat is just written, no meaning)
excelName1 = fullfile(newPath,excelFile1); -----> newPath is already been defined in code
excel = actxserver('Excel.Application');
Workbooks = excel.Workbooks;
wbsource = Workbooks.Open(excelName); ----->excelName will be oldExcel
wbdest = Workbooks.Open(excelName1);
ws = wbsource.Worksheets.Item(newidx); ----->newidx will be having sheet name
ws.Copy(wdest.Worksheets.Item(1)); ----> trying to copy worksheet one after another... suggest here as well
wbdest.Save
Thank you

采纳的回答

KSSV
KSSV 2022-8-3
T = table ; % create empty table
fname = 'test.xlsx' ; % here you can give path as well
writetable(T,fname) ; % create a excel file with empty table
% LEts add sheets
for i = 1:5
% make your table to write
x = rand(3,1) ; y = rand(3,1) ;
T = table(x,y) ;
% now write table into sheets
writetable(T,fname,'Sheet',i)
end

更多回答(0 个)

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by