給定資料年份,如何將表格儲存為變數名稱?例如:我有兩個Excel 檔案:2014.xlsx、2015.xlsx,並且希望在選擇這多個檔案後自動化,以命名這些檔案中的特定工作表(在本例中為{Product Events、Products、CodesFrmPLI }),用於總共 6 個不同的 JMP 表:對於本例,名稱範例為 Product_Events_2014、Product_Events_2015、Products_2014、Products_2015、CodesFrmPLI_2014、CodesFrmPLI_2015。
Names Default To Here( 1 );
Close All( data tables );
Delete Symbols();
Directory = Pick Directory( "Select a directory" );
Files = Pick File(
"Select Data Set(s)",
Directory,
{"All Files|*", "JMP Files|jmp;jsl;jrn", "Excel Files|xlsx"},
1,
0,
"",
"multiple"
);
For( i = 1, i <= N Items( Files ), i++,
Try( Open( Files[i],
Worksheets( NWorksheet = {"Product Events", "Products", "CodesFrmPLI"}),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 1 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" ),
invisible
) )
));
Show(NWorksheet);
//*** 2014 Naming convention
For( i = 1, i <= N Items( Files ), i++,
if( Contains( Files[i] , "2014") > 0,
dt = Data Table(1);
dt << Save("Codes_2014.jmp");
dt = Data Table(2);
dt << Save("Products_2014.jmp");
dt = Data Table(3);
dt << Save("Product Events_2014.jmp");
//Close All(Data Tables, No Save);
)
);
//*** 2015 Naming convention
For( i = 1, i <= N Items( Files ), i++,
if( Contains( Files[i] , "2015") > 0,
dt = Data Table(4);
dt << Save("Codes_2015.jmp");
dt = Data Table(5);
dt << Save("Products_2015.jmp");
dt = Data Table(6);
dt << Save("Product Events_2015.jmp");
//Close All(Data Tables, No Save);
)
);回覆:在給定資料年份的情況下,如何將表格儲存為變數名稱?如果你只是刪除該行
close( dt, save( extractList[1] || "_" || theYear || ".jmp" ) );
資料表將保持開啟。因此,您可以在初始 For() 迴圈的結束「)」之後新增所需的任何連線或計算。基本上,在當前腳本的最後一行之後。
回覆:在給定資料年份的情況下,如何將表格儲存為變數名稱?謝謝吉姆。 這奏效了。 快速跟進:如果我現在想執行表格連接和資料操作,哪裡是最佳位置?
問候。
回覆:在給定資料年份的情況下,如何將表格儲存為變數名稱?我認為下面對腳本的修改將讓您到達您想要的位置......我沒有非常廣泛的測試環境,但我認為程式碼非常接近您所需要的:
Names Default To Here( 1 );
Close All( data tables );
Delete Symbols();
Directory = Pick Directory( "Select a directory" );
Files = Pick File(
"Select Data Set(s)",
Directory,
{"All Files|*", "JMP Files|jmp;jsl;jrn", "Excel Files|xlsx"},
1,
0,
"",
"multiple"
);
// Place the names of the spreadsheets to be input into a list
spreadsheetList = {"Product Events", "Products", "CodesFrmPLI"};
For( i = 1, i <= N Items( Files ), i++,
// For this file, determine the year
If(
Contains( Files[i], "2014" ), theYear = "2014",
Contains( Files[i], "2015" ), theYear = "2015"
);
// Read in separately each separate spreadsheet
For( k = 1, k <= N Items( spreadsheetList ), k++,
// Create a list that will contain the current spreadsheet to
// be read in
extractList = {};
Insert Into( extractList, spreadsheetList[k] );
// Open the spreadsheet
Try(
dt = Open(
Files[i],
Worksheets( NWorksheet = extractList ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 1 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" ),
invisible
)
)
);
// The name for the JMP file is the same as the spreadsheet name,
// except for the Codes, so make the change
If( extractList[1] == "CodesFrmPLI",
extractList[1] = "Codes"
);
// Save the JMP file with the prescribed name
close( dt, save( extractList[1] || "_" || theYear || ".jmp" ) );
);
);