Update tem.txt
Browse files
tem.txt
CHANGED
@@ -1,35 +1,39 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
def
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
# Calculate length of line A
|
8 |
-
length_A = np.linalg.norm(vec_A)
|
9 |
-
|
10 |
-
# Calculate unit vector of line A
|
11 |
-
unit_vec_A = vec_A / length_A
|
12 |
-
|
13 |
-
# Convert angle from degrees to radians
|
14 |
-
angle_rad = np.deg2rad(angle_deg)
|
15 |
-
|
16 |
-
# Calculate rotation matrix for 30-degree angle
|
17 |
-
rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)],
|
18 |
-
[np.sin(angle_rad), np.cos(angle_rad)]])
|
19 |
-
|
20 |
-
# Rotate unit vector of line A by 30 degrees
|
21 |
-
rotated_unit_vec_A = np.dot(rotation_matrix, unit_vec_A)
|
22 |
-
|
23 |
-
# Scale rotated unit vector by length of line A and add to point B to get endpoint coordinates
|
24 |
-
endpoint = np.array(B) + length_A * rotated_unit_vec_A
|
25 |
-
|
26 |
-
return endpoint
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
B = (1, 1)
|
32 |
-
angle_deg = 30
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openpyxl import load_workbook
|
2 |
+
from openpyxl.drawing.image import Image
|
3 |
|
4 |
+
def read_images_from_excel(file_path, filter_column):
|
5 |
+
# Load the workbook
|
6 |
+
wb = load_workbook(filename=file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# Iterate through each sheet in the workbook
|
9 |
+
for sheet_name in wb.sheetnames:
|
10 |
+
sheet = wb[sheet_name]
|
|
|
|
|
11 |
|
12 |
+
# Find the column index of the filter column
|
13 |
+
filter_column_index = None
|
14 |
+
for col in range(1, sheet.max_column + 1):
|
15 |
+
if sheet.cell(row=1, column=col).value == filter_column:
|
16 |
+
filter_column_index = col
|
17 |
+
break
|
18 |
+
|
19 |
+
if filter_column_index is None:
|
20 |
+
print(f"Filter column '{filter_column}' not found in sheet '{sheet_name}'")
|
21 |
+
continue
|
22 |
+
|
23 |
+
# Iterate through each row in the sheet
|
24 |
+
for row in range(2, sheet.max_row + 1):
|
25 |
+
# Check if the filter condition is met
|
26 |
+
if sheet.cell(row=row, column=filter_column_index).value == "your_filter_value":
|
27 |
+
# Iterate through each image in the row
|
28 |
+
for image in sheet._images:
|
29 |
+
# Check if the image is in the same row as the filter condition
|
30 |
+
if image.anchor._from.row == row:
|
31 |
+
# Get the image data
|
32 |
+
img_data = image.image
|
33 |
+
|
34 |
+
# You can process the image data here
|
35 |
+
# For example, you can save the image to a file
|
36 |
+
img_data.save(f"{sheet_name}_{row}_{image.anchor._from.col}.png")
|
37 |
+
|
38 |
+
# Example usage:
|
39 |
+
read_images_from_excel("example.xlsx", "Column F")
|