I want to delete the ROW data from excel by reading Column in the same sheet

1 回表示 (過去 30 日間)
Hello
%%raw is having data of excel size 10X20
%%SummaryResult.xlsx is excel havinnd "aaa" is sheet name
If aaa sheet contains initial with "Z" WORD then I will delete that ROW.
try
Index = find(contains(raw(1:numrow1,1:1),'Z'));
if (Index(:))
xlswrite('SummaryResult.xlsx',raw(~Index,:),'aaa','A2')   %%here I am trying to delete to delete those rows which is having Z letter
else
0;
end
end
Thank You

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 27 日
xlsread() does not create a table; none of the columns will have column names. You should use readtable
tab = readtable('SummaryResult.xlsx', 'sheetname', 'aaa', 'VariableRenaming', 'Preserve');
tab(startsWith(tab.('Analysis Target or not'),["Z"]),:) = [];
writetable('SummaryResult.xlsx', tab, 'sheetname', 'aaa')
numrow3 = size(tab,1);
  4 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 28 日
tab = readtable('SummaryResult.xlsx', 'sheetname', 'aaa', 'VariableRenaming', 'Preserve');
tab(startsWith(tab.('var5'),["Z"]),:) = [];
writetable('SummaryResult.xlsx', tab, 'sheetname', 'aaa')
numrow3 = size(tab,1);
Santosh Biradar
Santosh Biradar 2022 年 7 月 28 日
Thank you so much.
It worked.
Very thankful for your time and response.

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

その他の回答 (1 件)

Githin George
Githin George 2022 年 7 月 27 日
Hi Santosh,
My understanding is that you will be importing the table, editing it and then writing it back to the excel sheet.
You can try out the following idea for removing the rows you want to
% tab is the imported column
% This line just deletes the rows for which YourColName of the table
% contains "Z"
tab(contains(tab.YourColName,["Z"]),:) = []
You can write the modified table to your excel sheet.
Hope it helps
  3 件のコメント
Githin George
Githin George 2022 年 7 月 27 日
The issue could be your column name. Please verify whether column name in 'tab' is matching 'Analysis Target or not'
Santosh Biradar
Santosh Biradar 2022 年 7 月 28 日
Thank you@Githin George for your help.

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

カテゴリ

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