delete excel rows whose first column is 0
古いコメントを表示
Hi, I want to delete rows if the first column in this row is 0. I know there are some answers online, I tried actxserver, but somehow it didn't work. Here is my code:
excelfilename = 'A.xlsx';
sheet = 'Sheet1';
[num,txt,raw]=xlsread(excelfilename,'Sheet1');
columnA = num(:,1);
nrows=length(columnA);
for i=1:nrows
if (columnA(i,1)==0)
row=i;
excel = actxserver('Excel.Application');
workbook = excel.Workbooks.Open(file);
worksheet = workbook.Worksheets.Item(sheet);
worksheet.Rows.Item(row).Delete;
end
end
workbook.Save;
excel.Quit;
But I kept getting errors. May anyone kindly give me a hand? Many thanks in advance.
2 件のコメント
Bob Thompson
2018 年 3 月 5 日
Are you trying to delete the rows in excel directly? Why not just delete them in your array and then rewrite the data to a new, or the same excel file?
Actxserver is very powerful, but is also significantly more complicated than standard MATLAB, and there isn't as much online information for it.
What kind of errors are you getting?
Tian Tian
2018 年 3 月 5 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!