Tagged: XLSX

XPS to XLSX

A tool for converting XPS files to XLSX files. Specifically, this maps out the location of data within the XPS and collates based on X and Y coordinates. This is useful for automating data capture fom XPS documents without having to manually copy and paste. Specific areas of the page can be targeted and content pulled.

Combine XLSX Files

A script to combine all XLSX files in a given folder into a single file. Each original XLSX file becomes a worksheet or worksheets in the final file. ##The Basics import xlrd import csv import os import re import pandas as pd def dfs_from_excels(folder, v = True): if v: print(“Parsing “, folder) output = {} for file in os.listdir(folder): if file.endswith(“.xlsx”) or file.endswith(“.XLSX”): if v: print(“Parsing:”, file) name = os.path.splitext(file)[0] wb = xlrd.open_workbook(os.path.join(folder,file)) for sheet in wb.sheet_names(): if v: print(‘Sheet:’, sheet) content = pd.read_excel(open(os.path.join(folder,file), ‘rb’),sheet_name=sheet) index = name + “-” + sheet output[index] = content if len(output) > 0: return […]

XLSX to CSV

A simple script to create CSV versions of any XLSX files in a given folder. #The Basics import xlrd import csv import os import re # Create empty variables and hash tables we’ll need later Location = {} # Location to output CSV file when all is done Location[‘input’] = input(‘Folder: ‘) Location[‘output’] = os.path.join(Location[‘input’],’csv’) def csv_from_excel(file): print(“Parsing “, file) wb = xlrd.open_workbook(file) for sheet in wb.sheet_names(): print(‘Exporting Sheet:’, sheet) sh = wb.sheet_by_name(sheet) fileout = os.path.splitext(file)[0] + ” ” + sheet + “.csv” with open(fileout, “w”, newline=””) as csvfile: wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL) for rownum in range(sh.nrows): wr.writerow(sh.row_values(rownum)) csvfile.close() # […]