Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cut_pic
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
dovahkiin
cut_pic
Commits
088a40c2
Commit
088a40c2
authored
Apr 12, 2024
by
dovahkiin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改生成坐标文档逻辑,为了不同的psd文件创建不同的工作表
parent
1c5d596c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
53 deletions
+76
-53
cut_pic.py
cut_pic.py
+76
-53
No files found.
cut_pic.py
View file @
088a40c2
...
...
@@ -31,6 +31,9 @@ class exc(object):
# 起始行
start_line_number
=
2
# 控制不同工作表的起始行的键
start_line_keys
=
{}
if
not
os
.
path
.
exists
(
excel_file_name
):
openpyxl
.
Workbook
()
.
save
(
excel_file_name
)
...
...
@@ -40,64 +43,84 @@ class exc(object):
def
exc_clear
(
self
):
excel_file_name
=
'image coordinate size.xlsx'
# EXCEL名称
while
(
True
):
x_coord_index
=
self
.
x_coord_column
+
str
(
self
.
start_line_number
)
y_coord_index
=
self
.
y_coord_column
+
str
(
self
.
start_line_number
)
width_index
=
self
.
width_column
+
str
(
self
.
start_line_number
)
height_index
=
self
.
height_column
+
str
(
self
.
start_line_number
)
image_name_index
=
self
.
image_name_colum
+
str
(
self
.
start_line_number
)
translation_index
=
self
.
translation_column
+
str
(
self
.
start_line_number
)
Original_index
=
self
.
Original_column
+
str
(
self
.
start_line_number
)
if
self
.
sheet1
[
image_name_index
]
.
value
!=
None
:
self
.
sheet1
[
x_coord_index
]
=
None
self
.
sheet1
[
y_coord_index
]
=
None
self
.
sheet1
[
width_index
]
=
None
self
.
sheet1
[
height_index
]
=
None
self
.
sheet1
[
image_name_index
]
=
None
self
.
sheet1
[
translation_index
]
=
None
self
.
sheet1
[
Original_index
]
=
None
self
.
start_line_number
+=
1
else
:
msgbox_flag
=
1
while
True
:
try
:
self
.
wb
.
save
(
'image coordinate size.xlsx'
)
break
except
PermissionError
:
if
msgbox_flag
:
print
(
"please close the Excel file"
)
msgbox_flag
=
0
# app = QtWidgets.QApplication(sys.argv)
msg_box
=
QMessageBox
(
QMessageBox
.
Warning
,
'Warning'
,
'please close the Excel file'
)
msg_box
.
exec_
()
sleep
(
3
)
break
self
.
image_name_colum
=
'A'
self
.
x_coord_column
=
'B'
self
.
y_coord_column
=
'C'
self
.
width_column
=
'D'
self
.
height_column
=
'E'
self
.
translation_column
=
'F'
self
.
Original_column
=
'G'
# 删除文件并新建一个空白的excel文件
if
os
.
path
.
exists
(
self
.
excel_file_name
):
os
.
remove
(
self
.
excel_file_name
)
self
.
wb
=
openpyxl
.
Workbook
()
self
.
sheet1
=
self
.
wb
.
active
self
.
sheet1
.
title
=
'Sheet1'
# 起始行
self
.
start_line_number
=
2
self
.
start_line_keys
=
{}
# while(True):
# x_coord_index = self.x_coord_column + str(self.start_line_number)
# y_coord_index = self.y_coord_column + str(self.start_line_number)
# width_index = self.width_column + str(self.start_line_number)
# height_index = self.height_column + str(self.start_line_number)
# image_name_index = self.image_name_colum + str(self.start_line_number)
# translation_index = self.translation_column + str(self.start_line_number)
# Original_index = self.Original_column + str(self.start_line_number)
# if self.sheet1[image_name_index].value != None:
# self.sheet1[x_coord_index] = None
# self.sheet1[y_coord_index] = None
# self.sheet1[width_index] = None
# self.sheet1[height_index] = None
# self.sheet1[image_name_index] = None
# self.sheet1[translation_index] = None
# self.sheet1[Original_index] = None
# self.start_line_number += 1
# else:
# msgbox_flag = 1
# while True:
# try:
# self.wb.save('image coordinate size.xlsx')
# break
# except PermissionError:
# if msgbox_flag:
# print("please close the Excel file")
# msgbox_flag = 0
# # app = QtWidgets.QApplication(sys.argv)
# msg_box = QMessageBox(QMessageBox.Warning, 'Warning', 'please close the Excel file')
# msg_box.exec_()
# sleep(3)
# break
# self.image_name_colum = 'A'
# self.x_coord_column = 'B'
# self.y_coord_column = 'C'
# self.width_column = 'D'
# self.height_column = 'E'
# self.translation_column = 'F'
# self.Original_column = 'G'
# # 起始行
# self.start_line_number = 2
def
exc_write
(
self
,
x_coord
,
y_coord
,
max_w
,
max_h
,
image_name
,
translation
,
Original
):
psd_name
=
os
.
path
.
basename
(
os
.
path
.
dirname
(
image_name
))
# 当程序进入一个空白的工作表的时候,更改工作表名称
if
len
(
self
.
start_line_keys
)
==
0
:
self
.
sheet1
.
title
=
psd_name
self
.
start_line_keys
[
psd_name
]
=
self
.
start_line_number
# 当处理一个全新的psd的时候,新建一张工作表
if
psd_name
not
in
self
.
start_line_keys
.
keys
():
self
.
sheet1
=
self
.
wb
.
create_sheet
(
title
=
psd_name
)
self
.
start_line_keys
[
psd_name
]
=
self
.
start_line_number
# 处理单元格索引
x_coord_index
=
self
.
x_coord_column
+
str
(
self
.
start_line_
number
)
y_coord_index
=
self
.
y_coord_column
+
str
(
self
.
start_line_
number
)
width_index
=
self
.
width_column
+
str
(
self
.
start_line_
number
)
height_index
=
self
.
height_column
+
str
(
self
.
start_line_
number
)
image_name_index
=
self
.
image_name_colum
+
str
(
self
.
start_line_
number
)
translation_index
=
self
.
translation_column
+
str
(
self
.
start_line_
number
)
Original_index
=
self
.
Original_column
+
str
(
self
.
start_line_
number
)
x_coord_index
=
self
.
x_coord_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
y_coord_index
=
self
.
y_coord_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
width_index
=
self
.
width_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
height_index
=
self
.
height_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
image_name_index
=
self
.
image_name_colum
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
translation_index
=
self
.
translation_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
Original_index
=
self
.
Original_column
+
str
(
self
.
start_line_
keys
[
psd_name
]
)
self
.
sheet1
[
x_coord_index
]
=
x_coord
self
.
sheet1
[
y_coord_index
]
=
y_coord
self
.
sheet1
[
width_index
]
=
max_w
...
...
@@ -105,7 +128,7 @@ class exc(object):
self
.
sheet1
[
image_name_index
]
=
image_name
self
.
sheet1
[
translation_index
]
=
translation
self
.
sheet1
[
Original_index
]
=
Original
self
.
start_line_
number
+=
1
self
.
start_line_
keys
[
psd_name
]
+=
1
msgbox_flag
=
1
while
True
:
...
...
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