“Lebar Otomatis OpenPyXL” Kode Jawaban

Lebar Otomatis OpenPyXL

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
Ashley Scheepers

Lebar Otomatis OpenPyXL

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
Ashley Scheepers

Lebar Otomatis OpenPyXL

#!/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)
Ashley Scheepers

Jawaban yang mirip dengan “Lebar Otomatis OpenPyXL”

Pertanyaan yang mirip dengan “Lebar Otomatis OpenPyXL”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya