<commit_before># _*_ coding:latin-1 _*_

import xlsxwriter
import bomlib.columns as columns
from bomlib.component import *
import os, shutil
from bomlib.preferences import BomPref

"""
Write BoM out to a XLSX file
filename = path to output file (must be a .xlsx file)
groups = [list of ComponentGroup groups]
net = netlist object
headings = [list of headings to display in the BoM file]
prefs = BomPref object
"""

def WriteXLSX(filename, groups, net, headings, prefs):

    filename = os.path.abspath(filename)

    if not filename.endswith(".xlsx"):
        return False

    nGroups = len(groups)
    nTotal = sum([g.getCount() for g in groups])
    nFitted = sum([g.getCount() for g in groups if g.isFitted()])
    nBuild = nFitted * prefs.boards

    workbook = xlsxwriter.Workbook(filename)
    worksheet = workbook.add_worksheet()

    if prefs.numberRows:
        row_headings = ["Component"] + headings
    else:
        row_headings = headings

    cellformats = {}
    column_widths = {}
    for i in range(len(row_headings)):
        cellformat = workbook.add_format()
        cellformat.set_center_across()
        cellformats[i] = cellformat
        column_widths[i] = len(row_headings[i]) + 10

        if not prefs.hideHeaders:
            worksheet.write_string( 0, i, row_headings[i], cellformats[i])

    count = 0
    rowCount = 1

    for i, group in enumerate(groups):
        if prefs.ignoreDNF and not group.isFitted(): continue

        row = group.getRow(headings)

        if prefs.numberRows:
            row = [str(rowCount)] + row

        for columnCount in range(len(row)):
            
            cell = row[columnCount].decode('utf-8')
            
            worksheet.write_string(rowCount,columnCount,cell,cellformats[columnCount])
                    
            if len(cell) > column_widths[columnCount]:
                column_widths[columnCount] = len(cell) + 10

        try:
            count += group.getCount()<commit_msg>Fix column width<commit_after># _*_ coding:latin-1 _*_

import xlsxwriter
import bomlib.columns as columns
from bomlib.component import *
import os, shutil
from bomlib.preferences import BomPref

"""
Write BoM out to a XLSX file
filename = path to output file (must be a .xlsx file)
groups = [list of ComponentGroup groups]
net = netlist object
headings = [list of headings to display in the BoM file]
prefs = BomPref object
"""

def WriteXLSX(filename, groups, net, headings, prefs):

    filename = os.path.abspath(filename)

    if not filename.endswith(".xlsx"):
        return False

    nGroups = len(groups)
    nTotal = sum([g.getCount() for g in groups])
    nFitted = sum([g.getCount() for g in groups if g.isFitted()])
    nBuild = nFitted * prefs.boards

    workbook = xlsxwriter.Workbook(filename)
    worksheet = workbook.add_worksheet()

    if prefs.numberRows:
        row_headings = ["Component"] + headings
    else:
        row_headings = headings

    cellformats = {}
    column_widths = {}
    for i in range(len(row_headings)):
        cellformat = workbook.add_format()
        cellformat.set_center_across()
        cellformats[i] = cellformat
        column_widths[i] = len(row_headings[i]) + 10

        if not prefs.hideHeaders:
            worksheet.write_string( 0, i, row_headings[i], cellformats[i])

    count = 0
    rowCount = 1

    for i, group in enumerate(groups):
        if prefs.ignoreDNF and not group.isFitted(): continue

        row = group.getRow(headings)

        if prefs.numberRows:
            row = [str(rowCount)] + row

        for columnCount in range(len(row)):
            
            cell = row[columnCount].decode('utf-8')
            
            worksheet.write_string(rowCount,columnCount,cell,cellformats[columnCount])
                    
            if len(cell) > column_widths[columnCount] - 5:
                column_widths[columnCount] = len(cell) + 5

        try:
            count += group.getCount()
{'fraction_non_alphanumeric': 0.10010136847440446, 'fraction_numerical': 0.00456158134820071, 'mean_word_length': 2.6012773722627736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2091083', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1223, 'n_words': 322}