如何将多个 PDF 文件中的数据导入到一个表格中,并用 PDF 文件名标记?你好呀,
我有一个包含 100 多个 PDF 的文件夹,所有这些都以一致的格式列出。 每个 PDF 的文件名代表一个我想要使用的批号,并且在每个 PDF 中都有一个我想要提取的特定数据表。
我的目标是为每个 PDF 提取相同的数据表,然后连接所有提取的数据表,并用 PDF 文件名(批号)标记。 最后,我想拆分串联表中的列,并按 PDF 文件名对其进行分组,以得到最终表。
我尝试过手动执行此操作,并且可以获得我需要的最终表格,但是这非常耗时,因为我必须分别打开并选择每个 PDF 中的表格。
因此,我想知道是否有一些 JSL 可以帮助解决这个问题?
我是脚本编写的新手,但已经能够创建一个脚本,该脚本可以准确地提供前两个 PDF 文件所需的内容:
//Opening up the first two files (Batch Number 1 & Batch Number 2) from the folder
Open(
"C:\Example folder\Batch 1.pdf",
PDF Tables(
Table(
table name( "Batch 1" ),
add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
)
)
)
;
Open(
"C:\Example folder\Batch 2.pdf",
PDF Tables(
Table(
table name( "Batch 2" ),
add rows( page( 1 ), Rect( 0.4143, 5.3995, 7.5889, 6.6781 ) )
)
)
)
;
//Concatenating the data for the first 2 batches into one table and adding a source column:
Data Table( "Batch 1" ) << Concatenate(
Data Table( "Batch 2" ),
Create source column,
Output table("Concat")
)
;
//Splitting by the concatenated table by the Characteristic column and grouping by source column (batch number) to create a Final table:
Data Table( "Concat" ) << Split(
Split By( :Characteristic ),
Split( :Value ),
Group( :Source Table ),
Remaining Columns( Drop All ),
Sort by Column Property,
Output table("Final")
)
;
//Close all other tables
Close("Batch 1", no save)
;
Close("Batch 2", no save)
;
Close("Concat", no save)我需要调整此脚本以打开所有 PDF 文件(不仅仅是前两个文件)以创建最终数据表,并以 PDF 文件名标记。
有没有人可以帮助我?
非常感谢,
艾丽西亚
数据表脚本回复:如何将多个 PDF 文件中的数据导入到一个表格中,并用 PDF 文件名标记?非常感谢@Craige_Hales和@乔治您的帮助。 我会去看看我是否可以改编剧本。 非常感谢!
回复:如何将多个 PDF 文件中的数据导入到一个表格中,并用 PDF 文件名标记?下面是一个示例,其中包含您需要的步骤。 的职位@Craige_Hales有助于理解这些东西是如何工作的。
Names Default To Here( 1 );
// Prepare a directory
tempdir = "$TEMP\pdf_test";
If( !Directory Exists( tempdir ),
Create Directory( tempdir ),
file_lst = Files In Directory( tempdir );
For( i = 1, i <= N Items( file_lst ), i++,
Delete File( tempdir || "/" || file_lst[i] )
);
);
// Open sample Table
cdt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Prepare PDF's
For( i = 1, i <= 10, i++,
jrn = cdt << Journal;
jrn << save pdf( tempdir || "/" || Char( i ) || "_Big Class.pdf" );
jrn << close window;
);
// Read PDF's
file_lst = Files In Directory( tempdir );
table_lst = {};
For( i = 1, i <= N Items( file_lst ), i++,
Insert Into( table_lst, Open( tempdir || "/" || file_lst[i], PDF All Tables() ) )
);
// Concat PDF's
If( N Items( table_lst ) > 1,
result_table = table_lst[1] << concatenate( table_lst[2 :: N Items( table_lst )], Output Table( "ResultTable" ), Create Source Column )
);
// Close single PDF's
For( i = 1, i <= N Items( table_lst ), i++,
Close( table_lst[i], noSave )
);
split_table = result_table << Split(
Split By( :sex ),
Group( :Source Table ),
Split( :age ),
Remaining Columns( Drop All ),
Sort by Column Property, output table("Split_Result")
);回复:如何将多个 PDF 文件中的数据导入到一个表格中,并用 PDF 文件名标记?如果你有两个工作,代码在连接数据表可能会把你带到那里。 FilesInDirectory() 可能是您需要的功能。
有很多类似的例子;在目录中搜索文件可能会找到它们。
再问一次,如果那不能让你到达那里,我认为你很接近。