Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import csv
- DOf = ""
- ROf = ""
- WOf = ""
- SOf = ""
- DIf = ""
- RIf = ""
- WIf = ""
- SIf = ""
- with open("\\\\server\\..folders..\\CSV.csv") as VBAWT:
- csvreader = csv.reader(VBAWT)
- for row in csvreader:
- DOf = row[0]
- ROf = row[1]
- WOf = row[2]
- SOf = row[3]
- DIf = row[4]
- RIf = row[5]
- WIf = row[6]
- SIf = row[7]
- DO = str(int(float(DOf) * 100)) #Excel Cell D38
- RO = str(int(float(ROf) * 100)) #F38
- WO = str(int(float(WOf) * 100)) #H38
- SO = str(int(float(SOf) * 100)) #J38
- DI = str(int(float(DIf) * 100)) #N38
- RI = str(int(float(RIf) * 100)) #P38
- WI = str(int(float(WIf) * 100)) #R38
- SI = str(int(float(SIf) * 100)) #T38
- #print (DO + ' ' + RO + ' ' + WO + ' ' + SO + ' ' + DI + ' ' + RI + ' ' + WI + ' ' + SI)
- #the below lines are what we are replacing in the text file (Actually the HTML master file, so the numbers show updated)
- lin61 = " complete = htmlStringStart + \""+ DO +"%\" + htmlStringRet + \""+ RO +"%\" + htmlStringWhol + \""+ WO +"%\" + htmlStringShel + \""+ SO +"%\" + htmlStringEnd; \n"
- lin65 = " complete = htmlStringStart + \""+ DI +"%\" + htmlStringRet + \""+ RO +"%\" + htmlStringWhol + \""+ WI + "%\" + htmlStringShel + \""+ SI +"%\" + htmlStringEnd; \n"
- old61 = ""
- old65 = ""
- linarr = []
- #Creates an array of the file lines, then sets a variable to what the current lines 61, 65 are so we can identify them for replacing
- with open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "r") as fs:
- for line in fs:
- linarr.append(line)
- old61 = linarr[61]
- old65 = linarr[65]
- #Now we look for those old lines, saying if it looks like the contents of the old61 variable, replace it with lin61 (and 65)
- fr = open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "r").read()
- fr = fr.replace(old61, lin61)
- fr = fr.replace(old65, lin65)
- fw = open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "w")
- fw.write(fr)
- fw.close()
Add Comment
Please, Sign In to add comment