Save Excel worksheet as csv Using com Object

13 ビュー (過去 30 日間)
Philip
Philip 2018 年 10 月 6 日
回答済み: Philip 2018 年 10 月 6 日
I'm trying to save an Excel worksheet as a CSV. Here's my code:
% Connect Matlab to Excel
e = actxGetRunningServer('Excel.Application');
% Select 1st sheet
eSheets = e.ActiveWorkbook.Sheets;
eSheet1 = eSheets.get('Item',1);
eSheet1.Activate
% Save as csv
SaveAs(eSheet1,'C:\myfile.xlsx') % Works - Saves Excel as xlsx
SaveAs(eSheet1,'C:\myfile.csv','xlCSV') % Does not work
I'm going off the documentation here: WorkSheet.SaveAs. It must be a simple formatting issue of how to actually call Excel methods, but I cannot figure out how to save the worksheet as a csv. Any help would be greatly appreciated.

採用された回答

Philip
Philip 2018 年 10 月 6 日
Apparently 'xlCSV' just stands for '6', which Excel interprets as saving as CSV format. So if I do:
SaveAs(eSheet1,'C:\myfile.csv','6') % Saves as CSV
this works and solves my issue. I have no idea why 'xlCSV' does not work, but I'll leave this post in case others have similar issues in the future.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by