How do I change the save file format in excel using activeX in Matlab
Show older comments
I currently have the following code.
file = 'C:\example\somefile.xlsx';
sheet = 'Sheet1'; %can be name or numeric index
row = 1;
excel = actxserver('Excel.Application');
workbook = excel.Workbooks.Open(file);
worksheet = workbook.Worksheets.Item(sheet);
worksheet.Rows.Item(row).Delete;
workbook.Save;
excel.Quit;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I want to change the default
"Save files in this format" : Excel Workbook (*.xlsx)
to
"Save files in this format" : CSV (Comma delimited)(*.csv)
Answers (3)
Fangjun Jiang
on 16 Jan 2019
Edited: Fangjun Jiang
on 16 Jan 2019
Worked like a charm, in R2018b, MS Office 2016.
file = 'Book1.xlsx';
sheet = 'Sheet1';
excel = actxserver('Excel.Application');
workbook = excel.Workbooks.Open(fullfile(pwd,file));
worksheet = workbook.Worksheets.Item(sheet);
xlCSV=6; %this constant is defined by MS Excel
ExcelApp.DisplayAlerts=false;% ignore prompt
workbook.SaveAs(fullfile(pwd,'Book2'),xlCSV);
excel.Quit;
3 Comments
Matthew Isaman
on 16 Jan 2019
Fangjun Jiang
on 16 Jan 2019
I don't know if you can change the default save option. But the statement ExcelApp.DisplayAlerts=false will get rid of that pop dialog.
Matthew Isaman
on 21 Jan 2019
Matthew Isaman
on 16 Jan 2019
0 votes
Matthew Isaman
on 16 Jan 2019
0 votes
1 Comment
Fangjun Jiang
on 16 Jan 2019
You need to do some experiments. See the updated answer.
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!