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

51 ビュー (過去 30 日間)
Santosh Biradar
Santosh Biradar 2022 年 8 月 3 日
コメント済み: Nisarga 2024 年 3 月 9 日 11:08
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
  2 件のコメント
Santosh Biradar
Santosh Biradar 2022 年 8 月 3 日
Thank you so much @KSSV
It worked!!
Nisarga
Nisarga 2024 年 3 月 9 日 11:08
It shows no error but it contains value in excel sheet
can we delete the values in the sheet

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by