フィルターのクリア

read two excel from different location using readtable

3 ビュー (過去 30 日間)
Santosh Biradar
Santosh Biradar 2022 年 7 月 29 日
コメント済み: Santosh Biradar 2022 年 7 月 29 日
Hello
I am selecting two Excel files from different locations.
Later I want to read the NEW and OLD excel data using Readtable to tNew and tOld variable respectively.
[file,path] = uigetfile('*.xlsx');
if isequal(file,0)
disp('Select NEW Summary Excel');
else
disp(['User selected ', fullfile(path,file)]);
end
[~,name,raw] = fileparts(file);
excelFile = strcat(file);
excelName = fullfile(path,excelFile);
tNew = readtable(excelFile);
[file1,path1] = uigetfile('*.xlsx');
if isequal(file,0)
disp('Select OLD Summary Excel');
else
disp(['User selected ', fullfile(path1,file1)]);
end
[~,name1,raw1] = fileparts(file1);
excelFile1 = strcat(file1);
excelName1 = fullfile(path1,excelFile1);
tOld = readtable(excelFile1);
Facing this error:
Error using readtable (line 223)
Unable to open file 'SummaryNew.xlsx' as a workbook. Check that the file exists, read access is available, and the file is
a valid spreadsheet file.
Thank you
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 29 日
What is the purpose of those strcat() calls?
I notice you do not use the output of the fileparts() calls.
Santosh Biradar
Santosh Biradar 2022 年 7 月 29 日
編集済み: Santosh Biradar 2022 年 7 月 29 日
Thank you for your response.
I was initially thought to use this
[~,name,raw] = fileparts(file);
excelFile = strcat(name,raw);
But Faced errors.
I am not sure how incorrect it is?
I thought to strcat,as I need to use readtable because,later I am using this table for ismember and writetable.
Thank you

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 29 日
excelName = fullfile(path,excelFile);
You construct the fully qualified file name
tNew = readtable(excelFile);
but you read from the name without the directory.
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 29 日
[new_file, new_path] = uigetfile('*.xlsx', 'Select NEW summary file');
if ~ischar(new_file)
error('Select NEW Summary Excel');
end
[old_file, old_path] = uigetfile('*.xlsx', 'Select OLD summary file');
if ~ischar(old_file)
error('Select OLD Summary Excel');
end
new_excelname = fullfile(new_path, new_file);
old_excelname = fullfile(old_path, old_file);
tNew = readtable(new_excelname);
tOld = readtable(old_excelname);
Santosh Biradar
Santosh Biradar 2022 年 7 月 29 日
I just did in the same way. :-)
Very thankful for pointing towards Unusable strcat() fileparts() .
Thank you so much for your time and responce @Walter Roberson.

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

その他の回答 (0 件)

カテゴリ

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