Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Openpyxl automatic width

column_widths = []
for row in workSheet.iter_rows():
    for i, cell in enumerate(row):
        try:
            column_widths[i] = max(column_widths[i], len(cell.value))
        except IndexError:
            column_widths.append(len(cell.value))

for i, column_width in enumerate(column_widths):
    workSheet.column_dimensions[get_column_letter(i + 1)].width = column_width
Comment

Openpyxl automatic width

for column_cells in worksheet.columns:
    length = max(len(as_text(cell.value)) for cell in column_cells)
    worksheet.column_dimensions[column_cells[0].column].width = length
Comment

Openpyxl automatic width

#!/usr/bin/python2.6
import csv
from openpyxl import Workbook
from openpyxl.cell import get_column_letter

f = open('users_info_cvs.txt', "rU")

csv.register_dialect('colons', delimiter=':')

reader = csv.reader(f, dialect='colons')

wb = Workbook()
dest_filename = r"account_info.xlsx"

ws = wb.worksheets[0]
ws.title = "Users Account Information"

for row_index, row in enumerate(reader):
    for column_index, cell in enumerate(row):
        column_letter = get_column_letter((column_index + 1))
        ws.cell('%s%s'%(column_letter, (row_index + 1))).value = cell

wb.save(filename = dest_filename)
Comment

PREVIOUS NEXT
Code Example
Python :: df shape 
Python :: number string array 
Python :: code pandas from url 
Python :: quotation marks n string 
Python :: python bot ban script 
Python :: python mongodb docker 
Python :: cursor python 
Python :: cin python 
Python :: keras sequential layer without input shape 
Python :: get last x elements of list python 
Python :: reverse relationship in django for one to one field for usage in Django rest serializer 
Python :: looping through strings 
Python :: re sub python 
Python :: 2d array python 
Python :: pandas series to dataframe index as column 
Python :: python remove multiple element from list by index 
Python :: fit function tensorflow 
Python :: django filter values with OR operator 
Python :: pytest for loop 
Python :: .size pandas 
Python :: tkinter insert value box 
Python :: concate the dataframe in pandas.. 
Python :: list addition within a list comprehension 
Python :: python collection 
Python :: model.predict knn 
Python :: PySimple list of elements 
Python :: django group permissions method 
Python :: geopandas with postgis 
Python :: tic tac toe pygame 
Python :: tkinter change button foreground 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =