a script that joints multiple sheets in an Excel workbook
1 次查看(过去 30 天)
显示 更早的评论
I have an Excel workbook with, let us say, 40 worksheets. Every worksheet has a format of
Date Sheet1Data
5/1/2019 10
Date Sheet2Data
5/1/2019 20
Then I want to have a script to outerjoin all the worksheets automatically. The output will be like
Date Sheet1Data Sheet2Data
5/1/2018 10 20
Please advise.
0 个评论
回答(1 个)
Guillaume
2019-5-24
readtable (or readtimetable) the first two sheets, outerjoin them. Then readtable (or readtimetable) the remaining sheets one by one in a loop, outerjoin'ing them to the previous result.
file = 'C:\somewhere\somefile.xlsx';
numsheets = 40;
result = outerjoin(readtable(file, 'Sheet', 1), readtable(file, 'Sheet', 2), 'Keys', 1, 'MergeKeys', true);
for sheet = 3:numsheets
result = outerjoin(result, readtable(file, 'Sheet', sheet), 'Keys', 1, 'MergeKeys', true);
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!