search through an excel file, and save sheet and cells as variables

조회 수: 5 (최근 30일)
avram alter
avram alter 2020년 1월 28일
답변: avram alter 2020년 1월 29일
I have an excel file that wil have up to 15 sheets in it. I have added a small example here that demonstrates what it looks like. basically, each sheet has 4x8 cells filled with an alphanumeric codes, with no codes repeating. Is there a way to enter one of the codes, and then matlab will search through the excel file, returning the sheet name and row to be saved in a variable?
for example, in the file I added here, Sheet2, row 4 begins with qwwj8434. for example
code = input('please enter code: ', 's');
>> qwwj8434
Sheet_name = Sheet2
Row_name = 4
I would specifically just be looking for the first code per row, if that helps at all.
Any help would be much appreciated.
  댓글 수: 2
Mohammad Sami
Mohammad Sami 2020년 1월 29일
The data needs to be loaded into Matlab first, before you can actually search the string you are looking for.
avram alter
avram alter 2020년 1월 29일
yeah, or course. i left that out here as I thought it was extraneous. thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

avram alter
avram alter 2020년 1월 29일
this is what the code looks like:
filename = 'examplesheet.xlsx';
[~, sheets] = xlsfinfo(filename);
rows_found = [];
sheets_found = {};
in = input('input code: ', 's');
for K = 1 : length(sheets)
this_sheet = sheets{K};
[~, ~, raw] = xlsread(filename, this_sheet);
[rowNum, colNum] = find( strcmp(in, raw));
if ~isempty(rowNum)
rows_found = [rows_found; rowNum];
sheets_found = [sheets_found; repmat({this_sheet}, length(rowNum), 1)];
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by