導入多個文件親愛的大家,
我的問題之前可能已經提出,因為它非常基本,但我找不到解決我確切問題的方法。
我想導入具有相同結構的多個文件,以相同的方式操作它們,然後將它們的一個子集粘合在一起。 我以以下通用方式完成了導入和數據操作部分:
dt = Open(
"PATH/File1.xlsx",
Worksheets( "Table1" ),
XXX
);
// New operation e.g. New column: Column 2
dt << New Column( "Column 2",
Numeric,
"Continuous",
Format( "Best", 12 )
);<BR /><BR />File1 = dt;<BR />File1 << Set Name("File1");<BR />為了導入更多文件,我會將相同的代碼複製到腳本中,並且只用“File2”、“File3”等交換“File1”。 它有效,但腳本長度變得相當大,因為我有很多文件要導入。
我還嘗試了 IMF 選項。 當我選擇“打開多個表”(我不希望它堆疊)時,我已經將數據錶鍊接到特定名稱,並且無法使用上述通用代碼對其進行操作。
關於更優雅的解決方案的任何想法?
非常感謝!
數據表Re: 導入多個文件你可以嘗試使用函數()(jmp.com)或 expr()。 以下是使用 function() 的幾個選項:
Names Default To Here(1);
open_and_modify = function({file_path}, {Default Local},
dt = Open(file_path, Worksheets("Table1"), XXX);
// New operation e.g. New column: Column 2
dt << New Column("Column 2", Numeric, "Continuous", Format("Best", 12));
dt << Set Name("File1");
return(dt);
);
dt1 = open_and_modify("PATH/File1.xlsx");
dt2 = open_and_modify("PATH/File2.xlsx");
dt3 = open_and_modify("PATH/File3.xlsx");
//or have a list of paths
file_paths = {"PATH/File1.xlsx", "PATH/File2.xlsx", "PATH/File3.xlsx"};
//create first concatenate before
table_list = {};
For Each({new_file_path}, files,
Insert Into(table_list, open_and_modify(new_file_path));
);