- This can be done by looping through each cell of the range of the excel sheet and checking as well as replacing the text in the cell with required text.
- Another approach can be to read the data from the excel file using 'readcell' function and the apply the tranformation to all the cells using 'cellfun' with a custom helper function to replace the text. Then 'writecell' can be used to write the modified data back to the excel sheet. Here is an example:
Find and Replace a specific String from excel work book
5 ビュー (過去 30 日間)
古いコメントを表示
I have to find and replace a specific String from an excel work book which contains n number of sheets. The string is available in random location in different sheet's.Example I want to replace the string Rana_1 from all sheets with Akash_1 .One more thing format of the work book should not change. I tried regexp but it is not usefull .
0 件のコメント
回答 (1 件)
Rahul
2025 年 2 月 19 日 7:07
I understand that you wish to replace centrain cells with a particular text with a different text. To achieve this, consider using:
FileName = 'yourFile.xlsx';
oldString = 'Rana_1';
newString = 'Akash_1';
% Read, modify and write the data
data = readcell(FileName);
modifiedData = cellfun(@(x) replaceIfMatch(x, oldString, newString), data, 'UniformOutput', false);
writecell(modifiedData, FileName);
% Helper function to replace matching strings
function output = replaceIfMatch(input, oldStr, newStr)
if ischar(input) && strcmp(input, oldStr)
output = newStr;
else
output = input;
end
end
Additionally, the following MATLAb Answer and File Exchange submission can be referred:
The following MathWorks documentations can be referred to know more:
Hope this helps! Thanks.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!