如何将多个pdf文件导入数据表警告:我是脚本编写新手
挑战:
- 我有大约 500 个 pdf 文件,每个文件都包含一个我想要导入到 JMP 并整理成单个 jmp 数据表的数据表。
工作流程及问题:
- 我制作了一个脚本(见下文),它允许我从一个 pdf 导入表格数据并将其附加到我称为的表格中最终.jmp 。 我将脚本保存为单独的文件,即不在数据表中。 每个pdf都附有最终.jmp作为单行。
- 每次导入后,我必须关闭最终.jmp表并用新的、更新的“最终”表覆盖它,该表包含新导入的 pdf 中的额外行。
- 每次导入后,我还必须手动关闭在此过程中创建的所有中间表。 (无聊的)
- 然后我在脚本中更改 pdf 文件名,按“保存”并重新运行它以导入另一个 pdf。 如此循环下去。
- 这个过程比手动复制粘贴更快,但仍然很费力,并且几乎可以肯定没有自动化到计算机科学的典型程度。
问题:
- 是否可以重复运行一个脚本,每次选择一个新的 pdf 进行导入并将其附加到同一个表中,直到一个文件夹中的所有 pdf 都已导入?
Open(
"C:\example folder\example.pdf",
PDF Tables(
Table(
table name( "1" ),
add rows( page( 1 ), Rect( 2.0419, 0.9776, 3.1993, 1.1726 ) ),
add rows( page( 1 ), Rect( 1.2137, 3.7819, 6.3603, 3.9069 ) ),
add rows( page( 1 ), Rect( 0.8717, 3.9636, 3.0796, 4.0886 ) ),
add rows(
page( 1 ),
Rect( 0.9853, 4.1436, 3.0029, 4.2686 ),
column borders( 0.9853, 2.5416, 3.0029 )
),
add rows( page( 1 ), Rect( 4.581, 4.1436, 7.297, 4.2686 ) ),
add rows(
page( 1 ),
Rect( 0.8883, 4.4136, 4.6374, 4.5386 ),
column borders( 0.8883, 1.9603, 4.6374 )
),
add rows(
page( 1 ),
Rect( 6.0143, 4.6569, 7.2498, 4.7819 ),
column borders( 6.0143, 6.5817, 7.2498 )
),
add rows( page( 1 ), Rect( 0.7556, 4.7979, 7.5908, 8.2654 ) )
)
)
);
Data Table( "1" ) << Stack(
columns( :Column 3, :Column 4, :Column 5, :Column 6 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output table("2")
);
Data Table( "2" ) << Transpose(
columns( :Data ),
Output Table( "3" )
);
Data Table( "Final" ) << Concatenate( Data Table( "3" ) )
数据存取回复:如何将多个pdf文件导入数据表我的错误......
Data table( "Final" );
应该已指定
New Table( "Final" );
回复:如何将多个pdf文件导入数据表抱歉,我必须带着更多问题回来,因为尽管经过多年的学术训练,我还是无法让这个循环发挥作用。 这是我尝试使其工作的方法:首先,我将所有文件移至本地硬盘,因为出于某种原因,我们在服务器上的一些文件夹名称中使用“()”,我的印象是这会产生问题。 最终,我使用引号“引用”了脚本中的整个目录,这似乎说服了脚本运行直到出现下一个错误消息。 然后它告诉我一些关于“路径无效......'胶水'......”的信息。 我用谷歌搜索了它,但不知道如何解决这个问题。 我可以看到错误消息中的文件名是我要使用的目录中的文件之一的名称。 首先,我认为文件名中的连字符造成了问题,但即使更改也会发生错误。
我已经粘贴在下面:
- 带有假目录名的脚本副本。 我保留了文件夹的数量以及包含括号的文件夹名称。
- 脚本窗口中的错误消息
- 调试时的错误信息
另外,如何在最终数据表中包含目录和文件名?
预先非常感谢您! (如果你觉得这个问题太琐碎而无法回答,我会理解的。)


Names default to here(1);
// Here is an example where the first thing that is done, is to create
// the list of the files to be processed
// Many different methods can be used to do this, but for this example
// the file names are read in from a directory
theFilesList = Files in directory( "C:\directory1\subdirectory1\subdirectory2\subdirectory3 (nameof aperson)\subdirectory4\subdirectory5\subdirectory6\subdirectory7\subdirectory8\subdirectory9\subdirectory10" );
// Create the Final data table that will have all of the processed files
// concatenated to it
Data Table( "Final" );
// Loop across all of the files and read them in one at a time and add them
// to the Final data table
For( i = 1, i <= N Items( theFilesList ), i++,
Open(
theFilesList[i],
PDF Tables(
Table(
table name( "1" ),
add rows( page( 1 ), Rect( 2.0419, 0.9776, 3.1993, 1.1726 ) ),
add rows( page( 1 ), Rect( 1.2137, 3.7819, 6.3603, 3.9069 ) ),
add rows( page( 1 ), Rect( 0.8717, 3.9636, 3.0796, 4.0886 ) ),
add rows( page( 1 ), Rect( 0.9853, 4.1436, 3.0029, 4.2686 ), column borders( 0.9853, 2.5416, 3.0029 ) ),
add rows( page( 1 ), Rect( 4.581, 4.1436, 7.297, 4.2686 ) ),
add rows( page( 1 ), Rect( 0.8883, 4.4136, 4.6374, 4.5386 ), column borders( 0.8883, 1.9603, 4.6374 ) ),
add rows( page( 1 ), Rect( 6.0143, 4.6569, 7.2498, 4.7819 ), column borders( 6.0143, 6.5817, 7.2498 ) ),
add rows( page( 1 ), Rect( 0.7556, 4.7979, 7.5908, 8.2654 ) )
)
)
);
Data Table( "1" ) << Stack(
columns( :Column 3, :Column 4, :Column 5, :Column 6 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output table( "2" )
);
Data Table( "2" ) << Transpose( columns( :Data ), Output Table( "3" ) );
// Concatenate the processed data to the Final data table
Data Table( "Final" ) << Concatenate( Data Table( "3" ), Append to first table( 1 ) );
// Cleanup the environment
Close( Data Table( "1" ), nosave );
Close( Data Table( "2" ), nosave );
Close( Data Table( "3" ), nosave );
);
回复:如何将多个pdf文件导入数据表@tx尼尔森,我不知道如何充分表达我的感激之情。 你非常非常善良。 再次非常感谢您的帮助!
回复:如何将多个pdf文件导入数据表所要做的就是循环代码,一个接一个地读取文件并将其添加到最终数据表中。下面的 JSL 应该为您提供如何执行此操作的良好开端。
Names default to here(1);
// Here is an example where the first thing that is done, is to create
// the list of the files to be processed
// Many different methods can be used to do this, but for this example
// the file names are read in from a directory
theFilesList = Files in directory( <PATH to="" your="" folder="" that="" has="" the="" .pdf="" files=""> );
// Create the Final data table that will have all of the processed files
// concatenated to it
Data Table( "Final" );
// Loop across all of the files and read them in one at a time and add them
// to the Final data table
For( i = 1, i <= N Items( theFilesList ), i++,
Open(
theFilesList[i],
PDF Tables(
Table(
table name( "1" ),
add rows( page( 1 ), Rect( 2.0419, 0.9776, 3.1993, 1.1726 ) ),
add rows( page( 1 ), Rect( 1.2137, 3.7819, 6.3603, 3.9069 ) ),
add rows( page( 1 ), Rect( 0.8717, 3.9636, 3.0796, 4.0886 ) ),
add rows( page( 1 ), Rect( 0.9853, 4.1436, 3.0029, 4.2686 ), column borders( 0.9853, 2.5416, 3.0029 ) ),
add rows( page( 1 ), Rect( 4.581, 4.1436, 7.297, 4.2686 ) ),
add rows( page( 1 ), Rect( 0.8883, 4.4136, 4.6374, 4.5386 ), column borders( 0.8883, 1.9603, 4.6374 ) ),
add rows( page( 1 ), Rect( 6.0143, 4.6569, 7.2498, 4.7819 ), column borders( 6.0143, 6.5817, 7.2498 ) ),
add rows( page( 1 ), Rect( 0.7556, 4.7979, 7.5908, 8.2654 ) )
)
)
);
Data Table( "1" ) << Stack(
columns( :Column 3, :Column 4, :Column 5, :Column 6 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output table( "2" )
);
Data Table( "2" ) << Transpose( columns( :Data ), Output Table( "3" ) );
// Concatenate the processed data to the Final data table
Data Table( "Final" ) << Concatenate( Data Table( "3" ), Append to first table( 1 ) );
// Cleanup the environment
Close( Data Table( "1" ), nosave );
Close( Data Table( "2" ), nosave );
Close( Data Table( "3" ), nosave );
);</PATH>