Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amazon_reports
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
common
amazon_reports
Commits
fe440a5b
Commit
fe440a5b
authored
Feb 28, 2025
by
邱阿朋
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '3.8.10-v2'
parents
5d960e8b
c85b17fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
2 deletions
+78
-2
spa.py
app/vc/spa.py
+2
-2
diff_spa.py
cmd/diff_spa.py
+76
-0
No files found.
app/vc/spa.py
View file @
fe440a5b
...
...
@@ -179,13 +179,13 @@ class Spa(AutoInterface):
# 写入小数据
if
sheet_data
:
log
.
info
(
f
"保存小数据,共计 {len(sheet_data)} 条"
)
self
.
__write_sheet
(
sheet_data
,
"Sheet1"
)
self
.
__write_sheet
(
writer
,
sheet_data
,
"Sheet1"
)
# 写入大数据(使用多线程并行写入不同表)
if
large_sheet_data
:
log
.
info
(
f
"保存大数据,共计 {sum(len(data) for data in large_sheet_data.values())} 条"
)
for
sheet_name
,
data
in
large_sheet_data
.
items
():
self
.
__write_sheet
(
data
,
sheet_name
)
self
.
__write_sheet
(
writer
,
data
,
sheet_name
)
# with ThreadPoolExecutor() as executor:
# for sheet_name, data in large_sheet_data.items():
# executor.submit(write_sheet, writer, data, sheet_name)
...
...
cmd/diff_spa.py
0 → 100644
View file @
fe440a5b
import
os.path
import
pandas
as
pd
import
argparse
class
InvoiceIDComparator
:
def
__init__
(
self
,
file_a
,
file_b
,
invoice_column_name
):
self
.
file_a
=
file_a
self
.
file_b
=
file_b
self
.
invoice_column_name
=
invoice_column_name
def
get_invoice_ids_from_excel
(
self
,
file_path
):
"""从Excel文件中获取所有sheet的Invoice ID"""
excel_file
=
pd
.
ExcelFile
(
file_path
)
invoice_ids
=
set
()
# 使用集合去重
for
sheet_name
in
excel_file
.
sheet_names
:
# 读取每个sheet的内容
df
=
excel_file
.
parse
(
sheet_name
)
# 确保指定的列存在
if
self
.
invoice_column_name
in
df
.
columns
:
invoice_ids
.
update
(
df
[
self
.
invoice_column_name
]
.
dropna
()
.
unique
())
invoice_ids
.
add
(
sheet_name
)
# 将sheet名也加入到集合中
return
invoice_ids
def
compare_invoice_ids
(
self
):
"""比较两个Excel文件中的Invoice ID"""
# 获取文件A中的Invoice ID和所有sheet名称
invoice_ids_a
=
self
.
get_invoice_ids_from_excel
(
self
.
file_a
)
# 获取文件B中的Invoice ID和所有sheet名称
invoice_ids_b
=
self
.
get_invoice_ids_from_excel
(
self
.
file_b
)
only_in_a
=
invoice_ids_a
-
invoice_ids_b
only_in_b
=
invoice_ids_b
-
invoice_ids_a
# 输出比较结果
print
(
"文件A中存在,但文件B中没有的 Invoice IDs:"
)
print
(
only_in_a
)
print
(
"
\n
文件B中存在,但文件A中没有的 Invoice IDs:"
)
print
(
only_in_b
)
def
main
():
# 设置命令行参数
parser
=
argparse
.
ArgumentParser
(
description
=
"比较两个Excel文件中的Invoice ID差异"
)
parser
.
add_argument
(
'--original_file'
,
default
=
"ContraCogsInvoices.xls"
,
help
=
"原文件路径"
)
parser
.
add_argument
(
'--result_file'
,
default
=
"result.xls"
,
help
=
"结果文件路径"
)
parser
.
add_argument
(
'--invoice_column'
,
default
=
'Invoice ID'
,
help
=
"Invoice ID列的名称"
)
# 解析命令行参数
args
=
parser
.
parse_args
()
if
os
.
path
.
exists
(
args
.
original_file
)
is
False
:
raise
FileExistsError
(
"源文件不存在"
)
if
os
.
path
.
exists
(
args
.
result_file
)
is
False
:
raise
FileExistsError
(
"结果文件不存在"
)
# 创建 InvoiceIDComparator 实例并进行比较
comparator
=
InvoiceIDComparator
(
args
.
original_file
,
args
.
result_file
,
args
.
invoice_column
)
comparator
.
compare_invoice_ids
()
# 程序入口
if
__name__
==
"__main__"
:
try
:
main
()
except
Exception
as
e
:
print
(
e
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment