私は AppleScript の専門家ではないので、Excel ファイルのバッチ (それぞれが 1 つのワークシートを含む) を正常に処理できる AppleScript コードの例を見つけようとしてきました。 .
これは私が念頭に置いていた疑似コードです:
pick source folder with Excel files;
pick destination Excel file;
for each file within the source folder:
copy data from default sheet;
paste data into destination sheet's first unused row
end
これが私が思いついたコードです。各ファイルは正しく開きますが、コピー/貼り付け操作は行われていません。それを機能させる方法はありますか?
set main_folder to choose folder with prompt "Please select the folder containing the Excel files:"
set target_excel to choose file with prompt "Please select target Excel file:"
set excel_extension_list to {"xls", "xlsx", "csv"}
tell application "Finder"
set excel_files to (files of main_folder whose name extension is in excel_extension_list) as alias list
end tell
tell application "Microsoft Excel"
open target_excel
repeat with a_file in excel_files
open a_file
activate a_file
tell sheet 1 of workbook a_file
set the_range to value of used range
set number_of_source_rows to count of rows of the_range
end tell
activate target_excel
tell sheet 1 of workbook target_excel
set new_range to value of used range
set number_of_destination_rows to count of rows of new_range
set destination_range to range "A" & (number_of_destination_rows + 1) & ":E" & (number_of_destination_rows + 1 + number_of_source_rows)
set value of destination_range to the_range
close workbook a_file saving no
end tell
end repeat
end tell