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

51 views (last 30 days)
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

Accepted Answer

KSSV
KSSV on 3 Aug 2022
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
  2 Comments
Nisarga
Nisarga on 9 Mar 2024 at 11:08
It shows no error but it contains value in excel sheet
can we delete the values in the sheet

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!