以堆栈格式合并来自不同工作簿的数据JMP 专家您好,
我正在寻找一种选项,通过将不同 Excel 工作簿中的数据堆叠在一个标题下,将它们合并到一个 JMP 文件中。
请建议从多个工作簿导入数据的最佳选项[请记住,这不是工作表]
顺便说一句,我在 Mac 操作系统上使用 JMP 15 pro。
提前致谢。
回复:以堆栈格式合并来自不同工作簿的数据看起来“theFiles”列表的定义不正确或不存在。theFiles 的值是多少,变量 i 的值是多少?
回复:以堆栈格式合并来自不同工作簿的数据我尝试了这个脚本,并收到以下错误。 不知道发生了什么,想知道您是否可以提供帮助。 谢谢。

回复:以堆栈格式合并来自不同工作簿的数据- 我提供的脚本基于要读入的 JSL 工作簿列表。该列表称为 theFiles。在我的脚本中,它是通过从给定目录/文件夹结构读取所有 .xlsx 文件来创建的。但您可以更改它,然后手动创建该列表。
theFiles = {"complete path to workbook 1", "complete path to workbook 2"
"complete path to workbook 3" };“工作簿 n 的完整路径”的一个虚构示例是:"C:\Excel Data\2020\January\Department21 Monthly.xlsx"
因此,您只需删除第 3-11 行中的代码并将其替换为“theFiles”列表的新定义,脚本就会为您提供所需的结果。
- 该脚本已将从其打开的任何工作簿中读取所有工作表,并将它们放入单个 JMP 数据表中,然后该脚本会将其添加到脚本创建的总体最终数据表中。
- 您需要提高 JMP JSL 技能,以便能够负责脚本的使用和维护。或者,如果这不在您的工作定义范围内,那么您需要找到预算来雇用某人来支持代码。使用刚刚传递给您的脚本是一件非常值得怀疑的事情。JMP 提供有关学习 JSL 的免费文档、示例和教程。此外,他们还提供“有偿”JSL 培训课程。JMP 社区讨论参与者可以帮助解决问题,但假设他们能够编写您可能需要的最终脚本将是错误的决定。
- 下面是对我的原始脚本的修改,将手动输入要阅读的工作簿的路径的示例代码放入其中
Names Default To Here( 1 );
theFiles = {"complete path to workbook 1", "complete path to workbook 2"
"complete path to workbook 3" };
// create the base data table that all other tables will be concatenated to
dtFinal = New Table( "All Data" );
// loop through all .xlsx files and concatenate them to dtFinal
// the Concatenate Worksheets(1) will result in a single data table
// for each workbook read in and that single data table will be concatenated
// to the dtFinal
For( i = 1, i <= N Items( theFiles ), i++,
dt = Open(
theFiles[i],
Use for all sheets( 1 ),
Concatenate Worksheets( 1 ),
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( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
// concatenate the new table with the dtFinal table
dtFinal << concatenate( dt, append to first table( 1 ) );
// delete the no longer needed data table dt
Close( dt, nosave );
);回复:以堆栈格式合并来自不同工作簿的数据感谢您的快速回复,txnelson。
但老实说,我不擅长编辑 .jsl 脚本。 我不知道在上面的共享 jsl 脚本中我必须编辑哪些步骤。
现在,我有“n”不。类似类型的 Excel 工作簿位于一个文件夹中。 每个 Excel 工作簿都有多个工作表,但我的重点是将所有工作簿中名为“数据”的工作表中的信息组合在一起。
假设这种情况,您能否进一步指导我编辑给定的脚本?
另外,如果您对“多文件导入”向导有任何想法,请针对给定场景提出建议。 如果各个工作簿只有一个工作表,我可以合并多个工作簿中的数据。 但是,我不知道,对于我在这里给出的场景,正确的步骤是什么[即。如果每个工作簿有多个工作表。]回复:以堆栈格式合并来自不同工作簿的数据下面的示例应该可以让您了解如何解决此问题。您可能需要根据实际结构的详细信息对其进行更改
Names Default To Here( 1 );
// get the workbooks to be processed
theFiles = Files in Directory(<YOUR path="">, recursive(1) );
// reduce the list to only .xlsx entries
For( i = N Items( theFiles ), i >= 1, i--,
If( Word( -1, theFiles[i], "." ) != "xlsx",
Remove From( theFiles, i, 1 )
)
);
// create the base data table that all other tables will be concatenated to
dtFinal = New Table( "All Data" );
// loop through all .xlsx files and concatenate them to dtFinal
// the Concatenate Worksheets(1) will result in a single data table
// for each workbook read in and that single data table will be concatenated
// to the dtFinal
For( i = 1, i <= N Items( theFiles ), i++,
dt = Open(
theFiles[i],
Use for all sheets( 1 ),
Concatenate Worksheets( 1 ),
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( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
// concatenate the new table with the dtFinal table
dtFinal << concatenate( dt, append to first table( 1 ) );
// delete the no longer needed data table dt
Close( dt, nosave );
);</YOUR>