1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| # -*- coding: utf-8 -*-
#write vbscript to file
import pandas as pd
import time
from io import StringIO
import pandas as pd
import datetime as dt
vbscript="""if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
oExcel.DisplayAlerts = FALSE 'to avoid prompts
Dim oBook, local
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
local = true
call oBook.SaveAs(WScript.Arguments.Item(1), 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, local) 'this changed
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
""";
f = open('ExcelToCsv.vbs','wb')
f.write(vbscript.encode('utf-8'))
f.close()
# create a list with sheet numbers you want to process
sheets = map(str,range(1,2))
print(sheets)
time.sleep(1)
# convert each sheet to csv and then read it using read_csv
df={}
from subprocess import call
#excel='K:\\APPI\\crystal\BT\\liste_BT_202203.xlsx'
excel='C:\\Users\II1154\\Desktop\\essais_excel\\liste_BT_202203.xlsx'
for sheet in sheets:
print(sheet)
csv = 'C:\\Users\II1154\\Desktop\\essais_excel\\' + sheet + '.csv'
## csv = 'C:\\Users\II1154\\Desktop\\essais_excel\\' + sheet + '.csv'
call(['cscript.exe', 'C:\\Users\II1154\\Desktop\\essais_excel\\ExcelToCsv.vbs', excel, csv, sheet])
df=pd.read_csv('C:\\Users\II1154\\Desktop\\essais_excel\\1.csv', sep=';', encoding="ISO-8859-1")
print(df.columns)
print(df)
df =df [(df['CODE_REGION']=="NO")]
df =df [(df['AGENT_RESERVE'].notnull()) ]
df['TEMPS_RESERVATION'] = df['TEMPS_RESERVATION'].str.replace(' HEURES','')
df['TEMPS_RESERVATION'] = df['TEMPS_RESERVATION'].str.split(';')
df2 = pd.DataFrame(df)
print('df1',df['TEMPS_RESERVATION'])
h = list(range(1, 12))
m = list(range(0,46, 15))
maximum=270
I=0
df['temps_bt']=0
for horaire in df['TEMPS_RESERVATION']:
totalBt=0
for horaire1 in horaire:
totalmn = 0
decrement = ""
h, m = (int(x) for x in horaire1.split(":", 1))
h *= 60
if h+m > maximum:
h -= 75
decrement += " -1 "
totalmn += h+m
totalmin=m+(h)
totalBt=totalmin+totalBt
df.at[I, 'temps_bt'] =totalBt
print("totalBt",df.at[I, 'temps_bt'])
I=I+1
df.to_csv('C:\\Users\II1154\\Desktop\\essais_excel\\2.csv',sep=';', encoding="ISO-8859-1",index=False) |
Partager