Click here to Skip to main content
15,799,398 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't determine the automatic width of the excel columns and even the header of the columns is not colored, while the rest of the row is

What I have tried:

@echo off
setlocal enabledelayedexpansion

rem Set the output file name and path
set output_file=risultati_dell_estrazione.xlsx

rem Delete the output file if it already exists
if exist "%output_file%" del "%output_file%"

rem Write the column headers to the output file
echo "Nome cartella estratta","Stato estrazione">>"%output_file%"

rem Loop through all RAR and ZIP files in the current directory and its subdirectories
for /r %%f in (*.rar *.zip) do (
  rem Extract the file
  if "%%~xf"==".rar" (
    "C:\Program Files\WinRAR\WinRAR.exe" x -y "%%f" "%%~dpf%%~nf\"
  ) else if "%%~xf"==".zip" (
    "C:\Program Files\WinRAR\WinRAR.exe" x -y "%%f" "%%~dpf%%~nf\"

  rem Get the name of the extracted directory
  set "extracted_dir=%%~nxf"

  rem Write the name of the extracted directory and the status of the extraction to the output file
  if exist "!extracted_dir!" (
    echo "!extracted_dir!",Success>>"%output_file%"
  ) else (
    echo "!extracted_dir!",Error>>"%output_file%"

echo Estrazione completata. I risultati sono stati salvati in "%output_file%".

rem Convert the CSV to an Excel file using pandas
python -c "import pandas as pd; df = pd.read_csv('risultati_dell_estrazione.xlsx'); writer = pd.ExcelWriter('risultati_dell_estrazione.xlsx', engine='xlsxwriter'); df.to_excel(writer, index=False); workbook =; worksheet = writer.sheets['Sheet1']; worksheet.set_column(0, 0, 50); worksheet.set_column(1, 1, 20); header_format = workbook.add_format({'bold': True, 'text_wrap': True, 'border': 1, 'bg_color': '#D3D3D3', 'font_color': 'white'}); worksheet.set_row(0, None, header_format);"

echo La tabella è stata salvata in "risultati_dell_estrazione.xlsx". Premi un tasto per uscire.
Updated 7-Apr-23 13:11pm
Dave Kreskowiak 14-Mar-23 15:20pm    
Why are you putting the Python code in the batch file? Just put it in its own .py file and you can run that file from the batch file.
Domenico Tatone 15-Mar-23 6:13am    
You're right, I fixed it by doing this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900