06-26-2020, 12:05 PM | #1 |
Join Date: Jun 2008
|
Car Wars Vehicle Designer and Python
Hi all.
This may be of no interest, in which case I apologise for wasting your bandwidth. Over the years I have used CWVD to generate many different designs. Unless I am missing something, the CWVD needs a separate spreadsheet for each design. Over time this has become unwieldy. As part of an up-skilling exercise I decided to see if I could do something to extract the summary text from every file in the directory automatically and append them to a single text file. I was learning python at the time (which has the advantage of being compact and cost free. To use it, jut put your XLS or XLSM files into the directory indicated and run the programme (using your python shell). It will extract the summary text from each file (separating them with line feeds and "***" so you can find them easily) and put it into a combined.txt file (where you can reformat it as you wish). You may need to pip install "xlrd" and "os" before you can use it (depending on your python environment - Anaconda has them by default). import xlrd import os directory = 'C:\python\cwvd' for entry in os.scandir(directory): if (entry.path.endswith(".xlsm") or entry.path.endswith(".xls")) and entry.is_file(): print(entry.path) file=entry.path try: book = xlrd.open_workbook(file,encoding_override="cp1251" ) except: book = xlrd.open_workbook(file) sh = book.sheet_by_name("Summaries") print("Cell a5 is {0}".format(sh.cell_value(rowx=4, colx=1))) filen = open("c:\python\cwvd\combined.txt","a") filen.write(str(sh.cell_value(rowx=4, colx=1))) filen.write("\n***\n") filen.close() In pasting in the python code you need to ensure that you add in appropriate indenting (as this forum mucks up formatting). If you know any Python, this should be obvious anyway. I hope you find it useful. Last edited by swordtart; 06-26-2020 at 12:11 PM. |
Thread Tools | |
Display Modes | |
|
|