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

38 visualizaciones (últimos 30 días)
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

Respuesta aceptada

KSSV
KSSV el 3 de Ag. de 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 comentarios
Santosh Biradar
Santosh Biradar el 3 de Ag. de 2022
Thank you so much @KSSV
It worked!!
Nisarga
Nisarga el 9 de Mzo. de 2024
It shows no error but it contains value in excel sheet
can we delete the values in the sheet

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by