I am creating an item catalogue of our products and need to import the item images besides their product codes'. The Image Code in the file is the same as the image saved name.
I've automated a SQL query for the table and connected it to Python, exporting it into an Excel file.
Also, if the Image Code does not map to anything, I need the code to prevent errors from occurring. If it helps, below is a similar script written on VBA Script for a similar task.
I've automated a SQL query for the table and connected it to Python, exporting it into an Excel file.
## SQL Query
sql_query = pd.read_sql_query('''
SELECT TOP 250 '' AS 'Image', LEFT(stockcode, 4)+RIGHT(stockcode, 4) AS 'Image Code', [stockcode], [Description]
FROM V_Sale_TurnOver sto
WHERE [PostingDate] BETWEEN '2022-01-01' AND getdate()
GROUP BY [Range], [stockcode], [Description]
''' ,conn)
df = pd.DataFrame(sql_query)
## Export to Folder
df.to_csv (r'G:\Outbound\Reports\Top 250 SKU/Top250SKU.csv', index = False)I need to map the product images to their image codes' (i.e., if a product Image Code = 'AURO0002', I need to import and map it to the saved image file 'AURO0002'). Also, if the Image Code does not map to anything, I need the code to prevent errors from occurring. If it helps, below is a similar script written on VBA Script for a similar task.
# VBA Code
rowNo = 1
dim ImgPath As String, NoImagePath As String
NoImagePath = "\\g_drive\Images\NoImage.jpg"
While Top250SKU.cells(rowNo, 2).Value <>
If Rs2.RecordCount <> 0 Then Rs2.MoveFirst
Do While Not Rs2.EOF
If ActiveSheet.Cells(rowNo, 2).Value = Rs2!stockcode And _
ActiveSheet.Cells(rowNo, 3).Value = Rs2!Description Then
End If
Rs2.MoveNext
Loop
ActiveSheet.Cells(4, 1).Value = "Image"
ImgPath = "\\g_drive\Images\" & ActiveSheet.Cells(rowNo, 2).Value & ".jpg"
If FileExists(ImgPath) = False Then
ImgPath = NoImagePath
End If
Rows(rowNo & ":" & rowNo).RowHeight = 60
Call InsertPictureIG(ImgPath, ActiveSheet.Cells(rowNo, 1).Address)
rowNo = rowNo + 1How can I go about coding this?
Larz60+ write Nov-17-2022, 08:50 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
