when i'm trying to save as excel xls to xlsx format in actxserver it doesnot work

5 ビュー (過去 30 日間)
Dhines
Dhines 2022 年 7 月 2 日
編集済み: dpb 2022 年 7 月 3 日
Im having file abc.xls , want to save this file as test.xlsx using actxserver it shows pop error file format extension not valid. but when i do the same in manually it works. could any one please give solution for this.
here my code.
sExcel=actxserver('Excel.Application');
EWorkBooks=sExcel.Workbooks;
EFile=EWorkBooks.Open([cd '\' 'abc.xls']);
EFile.SaveAs([cd '\' 'test.xlsx']);
EFile.Close;
sExcel.Quit;

回答 (1 件)

dpb
dpb 2022 年 7 月 3 日
編集済み: dpb 2022 年 7 月 3 日
You can't pass an OS command to be executed as the file name; my recollection is also that the .Open command needs a fully-qualifiled file name; partial file names didn't work..(that is a recollection; I didn't go recheck, but it's become an inate habit with me and I think that I discovered this some time back is why).
You also will need the second parameter to the Close call to force the action without requiring user intervention to answer the popup dialog Q?.
My preamble/close code looks something like:
WorkbookFullFileName=fullfile('path','workbookFile.xlsx');
excel=actxserver('Excel.Application');
excelWorkbook = excel.Workbooks.Open(WorkBookFullFileName);
% ... do work with workbook here...
excel.ActiveWorkbook.Save;
excel.ActiveWorkbook.Close(false);
delete(excel);
clear excel

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by