@@ -149,62 +149,8 @@ def normalize_other_data(df):
149
149
sheet = sheet [1 :- 1 ]
150
150
151
151
# Check if the file exists and the sheet exists
152
- if os .path .isfile (excel_file ):
152
+ if os .path .exists (excel_file ):
153
153
wb = load_workbook (excel_file )
154
- if "Readme" not in wb .sheetnames :
155
- # Create a new Readme sheet with instructions
156
- readme_sheet = wb .create_sheet (title = "Readme" )
157
- readme_content = """
158
- Instructions to update columns in Excel sheet
159
-
160
- For New Plan step update the row values as below:
161
- - id, steps.id - leave these row values empty column empty
162
- - Display_name : Display name for Plan Group name (mandatory)
163
- steps.display_name : Display name for the step (mandatory)
164
- steps.error_mode : STOP_ON_ERROR/CONTINUE_ON_ERROR (mandatory)
165
- steps.is_enabled : TRUE/FALSE (mandatory)
166
- steps.timeout : timeout value in seconds (mandatory)
167
- type: USER_DEFINED (mandatory)
168
- steps.user_defined_step.step_type : RUN_LOCAL_SCRIPT/RUN_OBJECTSTORE_SCRIPT/INVOKE_FUNCTION
169
-
170
- Based on the step type from above fill in the row values as mentioned :
171
- RUN_LOCAL_SCRIPT:
172
- - steps.user_defined_step.run_as_user, (description: user as which the script needs to run)
173
- - steps.user_defined_step.run_on_instance_id, (description: Instance OCID where the script is located)
174
- - steps.user_defined_step.script_command (description: script command which needs to run)
175
- RUN_OBJECTSTORE_SCRIPT:
176
- - steps.user_defined_step.run_on_instance_id, (description: Instance OCID where the script is located)
177
- - steps.user_defined_step.object_storage_script_location.bucket, (description: OCI Bucket name)
178
- - steps.user_defined_step.object_storage_script_location.namespace, (description: OCI Bucket namespace)
179
- - steps.user_defined_step.object_storage_script_location.object (description: object/scriptname name inside the bucket that needs to run)
180
- INVOKE_FUNCTION :
181
- - steps.user_defined_step.function_id, (description: OCI Functions OCID)
182
- - steps.user_defined_step.request_body (description: request which needs to be invoked)
183
-
184
- Updating existing plan :
185
-
186
- - Change the required row values(except group id and step id - these should remain the same).
187
- """
188
-
189
- # Insert the content into a single cell (A1)
190
- readme_sheet ["A1" ] = readme_content .strip ()
191
-
192
- # Expand the row height to accommodate the text
193
- readme_sheet .row_dimensions [1 ].height = 750 # You can adjust this value
194
-
195
- # Auto-adjust column width to fit the content
196
- readme_sheet .column_dimensions ['A' ].width = 150 # You can adjust this value
197
-
198
- # Set text wrapping for the cell
199
- readme_sheet ["A1" ].alignment = Alignment (wrap_text = True , vertical = 'top' )
200
- readme_sheet ["A1" ].font = Font (size = 14 , color = "FFFFFF" , bold = True ) # Set font size to 14 and color to white
201
- readme_sheet ["A1" ].fill = PatternFill (start_color = "346EC9" , end_color = "346EC9" , fill_type = "solid" ) # Set background to blue
202
- readme_index = wb .sheetnames .index ("Readme" )
203
- wb ._sheets .insert (0 , wb ._sheets .pop (readme_index ))
204
-
205
- # Save the workbook with the new Readme sheet
206
- wb .save (excel_file )
207
-
208
154
if sheet in wb .sheetnames :
209
155
with pd .ExcelWriter (excel_file , engine = 'openpyxl' , mode = 'a' , if_sheet_exists = 'replace' ) as writer :
210
156
print (f"Writing to sheet: { sheet } " )
@@ -221,8 +167,7 @@ def normalize_other_data(df):
221
167
combined_data .to_excel (writer , sheet_name = sheet , index = False )
222
168
worksheet = writer .sheets [sheet ]
223
169
224
-
225
- wb = load_workbook (excel_file )
170
+ wb = load_workbook (excel_file )
226
171
ws = wb [sheet ]
227
172
228
173
@@ -239,6 +184,7 @@ def merge_and_center(ws, col):
239
184
merged_cell = ws .cell (row = start_row , column = col )
240
185
merged_cell .alignment = Alignment (horizontal = 'center' , vertical = 'center' )
241
186
187
+
242
188
columns_to_merge = ['A' , 'B' ]
243
189
244
190
for col in columns_to_merge :
@@ -275,6 +221,64 @@ def merge_and_center(ws, col):
275
221
# Save the modified workbook
276
222
wb .save (excel_file )
277
223
print ("Excel file updated successfully." )
224
+
225
+ if "Readme" not in wb .sheetnames :
226
+ readme_sheet = wb .create_sheet (title = "Readme" )
227
+ readme_content = """
228
+ Instructions to update columns in Excel sheet
229
+
230
+ For New Plan step update the row values as below:
231
+ - id, steps.id - leave these row values empty column empty
232
+ - Display_name : Display name for Plan Group name (mandatory)
233
+ steps.display_name : Display name for the step (mandatory)
234
+ steps.error_mode : STOP_ON_ERROR/CONTINUE_ON_ERROR (mandatory)
235
+ steps.is_enabled : TRUE/FALSE (mandatory)
236
+ steps.timeout : timeout value in seconds (mandatory)
237
+ type: USER_DEFINED (mandatory)
238
+ steps.user_defined_step.step_type : RUN_LOCAL_SCRIPT/RUN_OBJECTSTORE_SCRIPT/INVOKE_FUNCTION
239
+
240
+ Based on the step type from above fill in the row values as mentioned :
241
+ RUN_LOCAL_SCRIPT:
242
+ - steps.user_defined_step.run_as_user, (description: user as which the script needs to run)
243
+ - steps.user_defined_step.run_on_instance_id, (description: Instance OCID where the script is located)
244
+ - steps.user_defined_step.script_command (description: script command which needs to run)
245
+ RUN_OBJECTSTORE_SCRIPT:
246
+ - steps.user_defined_step.run_on_instance_id, (description: Instance OCID where the script is located)
247
+ - steps.user_defined_step.object_storage_script_location.bucket, (description: OCI bucket name)
248
+ - steps.user_defined_step.object_storage_script_location.namespace, (description: OCI bucket namespace name)
249
+ - steps.user_defined_step.object_storage_script_location.object, (description: script name)
250
+ - steps.user_defined_step.run_on_instance_region, (description: Instance region name)
251
+ - steps.user_defined_step.script_command (description: script command which needs to run)
252
+ INVOKE_FUNCTION:
253
+ - steps.user_defined_step.function_id (description: OCI Function OCID which needs to be invoked)
254
+ - steps.user_defined_step.function_region (description: OCI Function region)
255
+ - steps.user_defined_step.request_body (description: OCI Function request body)
256
+ """
257
+
258
+ # Insert the content into a single cell (A1)
259
+ readme_sheet ["A1" ] = readme_content .strip ()
260
+
261
+ # Expand the row height to accommodate the text
262
+ readme_sheet .row_dimensions [1 ].height = 750 # You can adjust this value
263
+
264
+ # Auto-adjust column width to fit the content
265
+ readme_sheet .column_dimensions ['A' ].width = 150 # You can adjust this value
266
+
267
+ # Set text wrapping for the cell
268
+ readme_sheet ["A1" ].alignment = Alignment (wrap_text = True , vertical = 'top' )
269
+ readme_sheet ["A1" ].font = Font (size = 14 , color = "FFFFFF" , bold = True ) # Set font size to 14 and color to white
270
+ readme_sheet ["A1" ].fill = PatternFill (start_color = "346EC9" , end_color = "346EC9" ,
271
+ fill_type = "solid" ) # Set background to blue
272
+ readme_index = wb .sheetnames .index ("Readme" )
273
+ wb ._sheets .insert (0 , wb ._sheets .pop (readme_index ))
274
+
275
+ # Save the workbook with the new Readme sheet
276
+ wb .save (excel_file )
277
+
278
+
279
+
280
+ wb .save (excel_file )
281
+ wb .close ()
282
+
278
283
except Exception as e :
279
- print (f"An error occurred: { str (e )} " )
280
- exit (1 )
284
+ print (f"Error: { str (e )} " )
0 commit comments