From 1f74fba80e4238a9685d26bb5f10d8c35fbe3be2 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sat, 18 May 2019 21:38:03 +0200 Subject: [PATCH 1/8] Added XLSX output --- KiBOM_CLI.py | 4 +- README.md | 7 ++ bomlib/bom_writer.py | 8 +++ bomlib/xlsx_writer.py | 145 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 bomlib/xlsx_writer.py diff --git a/KiBOM_CLI.py b/KiBOM_CLI.py index 1535307..a24ef67 100755 --- a/KiBOM_CLI.py +++ b/KiBOM_CLI.py @@ -3,7 +3,7 @@ @package KiBOM - Bill of Materials generation for KiCad - Generate BOM in xml, csv, txt, tsv or html formats. + Generate BOM in xml, csv, txt, tsv, html or xlsx formats. - Components are automatically grouped into BoM rows (grouping is configurable) - Component groups count number of components and list component designators @@ -47,7 +47,7 @@ def say(*arg): def isExtensionSupported(filename): result = False - extensions = [".xml",".csv",".txt",".tsv",".html"] + extensions = [".xml",".csv",".txt",".tsv",".html",".xlsx"] for e in extensions: if filename.endswith(e): result = True diff --git a/README.md b/README.md index de16a2e..03ea72a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ optional arguments: * If a suffix is not specified, CSV output format will be used * HTML output can be specified within KiCad as: "%O.html" or "%O_BOM.html" (etc) * XML output can be specified within KiCad as: "%O.xml" (etc) +* XSLX output can be specified within KiCad as: "%O.xlsx" (etc) **-n --number** Specify number of boards for calculating part quantities @@ -181,6 +182,7 @@ Multiple BoM output formats are supported: * TXT (Text file output with tab separated values) * XML * HTML +* XLSX Output file format selection is set by the output filename. e.g. "bom.html" will be written to a HTML file, "bom.csv" will be written to a CSV file. @@ -352,6 +354,10 @@ An XML file output can be generated simply by changing the file extension +### XLSX Output +An XLSX file output can be generated simply by changing the file extension + + ## Contributors With thanks to the following contributors: @@ -365,3 +371,4 @@ With thanks to the following contributors: * https://github.com/marcelobarrosalmeida * https://github.com/fauxpark * https://github.com/Swij +* https://github.com/Ximi1970 diff --git a/bomlib/bom_writer.py b/bomlib/bom_writer.py index 18e0f9e..5a8c02f 100644 --- a/bomlib/bom_writer.py +++ b/bomlib/bom_writer.py @@ -1,6 +1,7 @@ from bomlib.csv_writer import WriteCSV from bomlib.xml_writer import WriteXML from bomlib.html_writer import WriteHTML +from bomlib.xlsx_writer import WriteXLSX import bomlib.columns as columns from bomlib.component import * @@ -69,6 +70,13 @@ def WriteBoM(filename, groups, net, headings = columns.ColumnList._COLUMNS_DEFAU else: print("Error writing XML output") + elif ext in ["xlsx"]: + if WriteXLSX(filename, groups, net, headings, prefs): + print("XLSX Output -> {fn}".format(fn=filename)) + result = True + else: + print("Error writing XLSX output") + else: print("Unsupported file extension: {ext}".format(ext=ext)) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py new file mode 100644 index 0000000..7e1283e --- /dev/null +++ b/bomlib/xlsx_writer.py @@ -0,0 +1,145 @@ +# _*_ 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) + + try: + count += group.getCount() + except: + pass + + rowCount += 1 + + print('Done') + + if not prefs.hideHeaders: + #blank rows + for i in range(5): + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Component Groups:", cellformats[0]) + worksheet.write_number( rowCount, 1, nGroups, cellformats[1]) + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Component Count:", cellformats[0]) + worksheet.write_number( rowCount, 1, nTotal, cellformats[1]) + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Fitted Components:", cellformats[0]) + worksheet.write_number( rowCount, 1, nFitted, cellformats[1]) + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Number of PCBs:", cellformats[0]) + worksheet.write_number( rowCount, 1, prefs.boards, cellformats[1]) + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Total components:", cellformats[0]) + worksheet.write_number( rowCount, 1, nBuild, cellformats[1]) + rowCount += 1 + + worksheet.write_string( rowCount, 0, "Schematic Version:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getVersion(), cellformats[1]) + rowCount += 1 + + if len(net.getVersion()) > column_widths[1]: + column_widths[1] = len(net.getVersion()) + + + worksheet.write_string( rowCount, 0, "Schematic Date:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getSheetDate(), cellformats[1]) + rowCount += 1 + + if len(net.getSheetDate()) > column_widths[1]: + column_widths[1] = len(net.getSheetDate()) + + + worksheet.write_string( rowCount, 0, "BoM Date:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getDate(), cellformats[1]) + rowCount += 1 + + if len(net.getDate()) > column_widths[1]: + column_widths[1] = len(net.getDate()) + + worksheet.write_string( rowCount, 0, "Schematic Source:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getSource(), cellformats[1]) + rowCount += 1 + + if len(net.getSource()) > column_widths[1]: + column_widths[1] = len(net.getSource()) + + worksheet.write_string( rowCount, 0, "KiCad Version:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getTool(), cellformats[1]) + rowCount += 1 + + if len(net.getTool()) > column_widths[1]: + column_widths[1] = len(net.getTool()) + + for i in range(len(column_widths)): + worksheet.set_column( i, i, column_widths[i]) + + workbook.close() + + return True From dc027c6c92ba312e5d2086eecbcfac2dc148aaf1 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 19 May 2019 00:56:59 +0200 Subject: [PATCH 2/8] Left jusitfy bottom headers --- bomlib/xlsx_writer.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py index 7e1283e..5c38f6a 100644 --- a/bomlib/xlsx_writer.py +++ b/bomlib/xlsx_writer.py @@ -64,7 +64,7 @@ def WriteXLSX(filename, groups, net, headings, prefs): worksheet.write_string(rowCount,columnCount,cell,cellformats[columnCount]) if len(cell) > column_widths[columnCount]: - column_widths[columnCount] = len(cell) + column_widths[columnCount] = len(cell) + 10 try: count += group.getCount() @@ -80,28 +80,30 @@ def WriteXLSX(filename, groups, net, headings, prefs): for i in range(5): rowCount += 1 + cellformat_left = workbook.add_format({'align': 'left'}) + worksheet.write_string( rowCount, 0, "Component Groups:", cellformats[0]) - worksheet.write_number( rowCount, 1, nGroups, cellformats[1]) + worksheet.write_number( rowCount, 1, nGroups, cellformat_left) rowCount += 1 worksheet.write_string( rowCount, 0, "Component Count:", cellformats[0]) - worksheet.write_number( rowCount, 1, nTotal, cellformats[1]) + worksheet.write_number( rowCount, 1, nTotal, cellformat_left) rowCount += 1 worksheet.write_string( rowCount, 0, "Fitted Components:", cellformats[0]) - worksheet.write_number( rowCount, 1, nFitted, cellformats[1]) + worksheet.write_number( rowCount, 1, nFitted, cellformat_left) rowCount += 1 worksheet.write_string( rowCount, 0, "Number of PCBs:", cellformats[0]) - worksheet.write_number( rowCount, 1, prefs.boards, cellformats[1]) + worksheet.write_number( rowCount, 1, prefs.boards, cellformat_left) rowCount += 1 worksheet.write_string( rowCount, 0, "Total components:", cellformats[0]) - worksheet.write_number( rowCount, 1, nBuild, cellformats[1]) + worksheet.write_number( rowCount, 1, nBuild, cellformat_left) rowCount += 1 worksheet.write_string( rowCount, 0, "Schematic Version:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getVersion(), cellformats[1]) + worksheet.write_string( rowCount, 1, net.getVersion(), cellformat_left) rowCount += 1 if len(net.getVersion()) > column_widths[1]: @@ -109,7 +111,7 @@ def WriteXLSX(filename, groups, net, headings, prefs): worksheet.write_string( rowCount, 0, "Schematic Date:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getSheetDate(), cellformats[1]) + worksheet.write_string( rowCount, 1, net.getSheetDate(), cellformat_left) rowCount += 1 if len(net.getSheetDate()) > column_widths[1]: @@ -117,21 +119,21 @@ def WriteXLSX(filename, groups, net, headings, prefs): worksheet.write_string( rowCount, 0, "BoM Date:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getDate(), cellformats[1]) + worksheet.write_string( rowCount, 1, net.getDate(), cellformat_left) rowCount += 1 if len(net.getDate()) > column_widths[1]: column_widths[1] = len(net.getDate()) worksheet.write_string( rowCount, 0, "Schematic Source:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getSource(), cellformats[1]) + worksheet.write_string( rowCount, 1, net.getSource(), cellformat_left) rowCount += 1 if len(net.getSource()) > column_widths[1]: column_widths[1] = len(net.getSource()) worksheet.write_string( rowCount, 0, "KiCad Version:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getTool(), cellformats[1]) + worksheet.write_string( rowCount, 1, net.getTool(), cellformat_left) rowCount += 1 if len(net.getTool()) > column_widths[1]: From 34f74cd64caf497e9e4ae50304c98b2f461b37ef Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 19 May 2019 00:59:59 +0200 Subject: [PATCH 3/8] Fix column width --- bomlib/xlsx_writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py index 5c38f6a..c1e3c19 100644 --- a/bomlib/xlsx_writer.py +++ b/bomlib/xlsx_writer.py @@ -63,8 +63,8 @@ def WriteXLSX(filename, groups, net, headings, prefs): worksheet.write_string(rowCount,columnCount,cell,cellformats[columnCount]) - if len(cell) > column_widths[columnCount]: - column_widths[columnCount] = len(cell) + 10 + if len(cell) > column_widths[columnCount] - 5: + column_widths[columnCount] = len(cell) + 5 try: count += group.getCount() From 55775addeee4e35a68100921b21875b96707257e Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 19 May 2019 12:23:42 +0200 Subject: [PATCH 4/8] Make XLSX optional. XlsxWriter automaticly detected. --- KiBOM_CLI.py | 22 +++++++++++++++++++++- README.md | 2 +- bomlib/bom_writer.py | 2 +- bomlib/preferences.py | 3 +++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/KiBOM_CLI.py b/KiBOM_CLI.py index a24ef67..3073960 100755 --- a/KiBOM_CLI.py +++ b/KiBOM_CLI.py @@ -24,6 +24,20 @@ import argparse +# Optional modules + +xlsxwriter_available = False +try: + import xlsxwriter +except: + print() + print('Module not found: xlsxwriter') + print('XLSX output format not available.') + print() +else: + xlsxwriter_available = True + +# here = os.path.abspath(os.path.dirname(sys.argv[0])) sys.path.append(here) @@ -47,7 +61,10 @@ def say(*arg): def isExtensionSupported(filename): result = False - extensions = [".xml",".csv",".txt",".tsv",".html",".xlsx"] + if xlsxwriter_available: + extensions = [".xml",".csv",".txt",".tsv",".html",".xlsx"] + else: + extensions = [".xml",".csv",".txt",".tsv",".html"] for e in extensions: if filename.endswith(e): result = True @@ -94,6 +111,9 @@ def isExtensionSupported(filename): pref.Read(config_file) say("Config:",config_file) +#pass available modules +pref.xlsxwriter_available = xlsxwriter_available + #pass various command-line options through pref.verbose = verbose if args.number is not None: diff --git a/README.md b/README.md index 03ea72a..85a9863 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ Multiple BoM output formats are supported: * TXT (Text file output with tab separated values) * XML * HTML -* XLSX +* XLSX (Needs XlsxWriter Python module) Output file format selection is set by the output filename. e.g. "bom.html" will be written to a HTML file, "bom.csv" will be written to a CSV file. diff --git a/bomlib/bom_writer.py b/bomlib/bom_writer.py index 5a8c02f..39ffec9 100644 --- a/bomlib/bom_writer.py +++ b/bomlib/bom_writer.py @@ -70,7 +70,7 @@ def WriteBoM(filename, groups, net, headings = columns.ColumnList._COLUMNS_DEFAU else: print("Error writing XML output") - elif ext in ["xlsx"]: + elif ( ext in ["xlsx"] ) and prefs.xlsxwriter_available: if WriteXLSX(filename, groups, net, headings, prefs): print("XLSX Output -> {fn}".format(fn=filename)) result = True diff --git a/bomlib/preferences.py b/bomlib/preferences.py index c9fec92..43bdfaa 100644 --- a/bomlib/preferences.py +++ b/bomlib/preferences.py @@ -59,6 +59,9 @@ def __init__(self): self.separatorCSV = None self.includeVersionNumber = True + self.xlsxwriter_available = False + self.xlsxwriter2_available = False + # Default fields used to group components self.groups = [ ColumnList.COL_PART, From 4c0c63e32374405d2b74b28e7b7427c00a9505ab Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 19 May 2019 12:32:50 +0200 Subject: [PATCH 5/8] Cleanup --- bomlib/xlsx_writer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py index c1e3c19..4a85cb6 100644 --- a/bomlib/xlsx_writer.py +++ b/bomlib/xlsx_writer.py @@ -38,9 +38,7 @@ def WriteXLSX(filename, groups, net, headings, prefs): cellformats = {} column_widths = {} for i in range(len(row_headings)): - cellformat = workbook.add_format() - cellformat.set_center_across() - cellformats[i] = cellformat + cellformats[i] = workbook.add_format({'align':'center_across'}) column_widths[i] = len(row_headings[i]) + 10 if not prefs.hideHeaders: @@ -80,7 +78,7 @@ def WriteXLSX(filename, groups, net, headings, prefs): for i in range(5): rowCount += 1 - cellformat_left = workbook.add_format({'align': 'left'}) + cellformat_left = workbook.add_format({'align':'left'}) worksheet.write_string( rowCount, 0, "Component Groups:", cellformats[0]) worksheet.write_number( rowCount, 1, nGroups, cellformat_left) From c9919ca7bc016f57ed96d94a8ee348deee7f0c55 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 19 May 2019 12:47:06 +0200 Subject: [PATCH 6/8] Fix import error --- bomlib/xlsx_writer.py | 229 +++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 112 deletions(-) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py index 4a85cb6..1c69d8f 100644 --- a/bomlib/xlsx_writer.py +++ b/bomlib/xlsx_writer.py @@ -1,145 +1,150 @@ # _*_ 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"): +try: + import xlsxwriter +except: + def WriteXLSX(filename, groups, net, headings, prefs): return False +else: + import bomlib.columns as columns + from bomlib.component import * + import os, shutil + from bomlib.preferences import BomPref - 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 + """ + 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 + """ - workbook = xlsxwriter.Workbook(filename) - worksheet = workbook.add_worksheet() + def WriteXLSX(filename, groups, net, headings, prefs): - if prefs.numberRows: - row_headings = ["Component"] + headings - else: - row_headings = headings + filename = os.path.abspath(filename) - cellformats = {} - column_widths = {} - for i in range(len(row_headings)): - cellformats[i] = workbook.add_format({'align':'center_across'}) - column_widths[i] = len(row_headings[i]) + 10 + if not filename.endswith(".xlsx"): + return False - if not prefs.hideHeaders: - worksheet.write_string( 0, i, row_headings[i], cellformats[i]) - - count = 0 - rowCount = 1 + 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 - for i, group in enumerate(groups): - if prefs.ignoreDNF and not group.isFitted(): continue - - row = group.getRow(headings) + workbook = xlsxwriter.Workbook(filename) + worksheet = workbook.add_worksheet() 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() - except: - pass - - rowCount += 1 - - print('Done') - - if not prefs.hideHeaders: - #blank rows - for i in range(5): + row_headings = ["Component"] + headings + else: + row_headings = headings + + cellformats = {} + column_widths = {} + for i in range(len(row_headings)): + cellformats[i] = workbook.add_format({'align':'center_across'}) + 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() + except: + pass + rowCount += 1 - cellformat_left = workbook.add_format({'align':'left'}) + print('Done') + + if not prefs.hideHeaders: + #blank rows + for i in range(5): + rowCount += 1 + + cellformat_left = workbook.add_format({'align':'left'}) - worksheet.write_string( rowCount, 0, "Component Groups:", cellformats[0]) - worksheet.write_number( rowCount, 1, nGroups, cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Component Groups:", cellformats[0]) + worksheet.write_number( rowCount, 1, nGroups, cellformat_left) + rowCount += 1 - worksheet.write_string( rowCount, 0, "Component Count:", cellformats[0]) - worksheet.write_number( rowCount, 1, nTotal, cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Component Count:", cellformats[0]) + worksheet.write_number( rowCount, 1, nTotal, cellformat_left) + rowCount += 1 - worksheet.write_string( rowCount, 0, "Fitted Components:", cellformats[0]) - worksheet.write_number( rowCount, 1, nFitted, cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Fitted Components:", cellformats[0]) + worksheet.write_number( rowCount, 1, nFitted, cellformat_left) + rowCount += 1 - worksheet.write_string( rowCount, 0, "Number of PCBs:", cellformats[0]) - worksheet.write_number( rowCount, 1, prefs.boards, cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Number of PCBs:", cellformats[0]) + worksheet.write_number( rowCount, 1, prefs.boards, cellformat_left) + rowCount += 1 - worksheet.write_string( rowCount, 0, "Total components:", cellformats[0]) - worksheet.write_number( rowCount, 1, nBuild, cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Total components:", cellformats[0]) + worksheet.write_number( rowCount, 1, nBuild, cellformat_left) + rowCount += 1 - worksheet.write_string( rowCount, 0, "Schematic Version:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getVersion(), cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Schematic Version:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getVersion(), cellformat_left) + rowCount += 1 - if len(net.getVersion()) > column_widths[1]: - column_widths[1] = len(net.getVersion()) + if len(net.getVersion()) > column_widths[1]: + column_widths[1] = len(net.getVersion()) - worksheet.write_string( rowCount, 0, "Schematic Date:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getSheetDate(), cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Schematic Date:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getSheetDate(), cellformat_left) + rowCount += 1 - if len(net.getSheetDate()) > column_widths[1]: - column_widths[1] = len(net.getSheetDate()) + if len(net.getSheetDate()) > column_widths[1]: + column_widths[1] = len(net.getSheetDate()) - worksheet.write_string( rowCount, 0, "BoM Date:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getDate(), cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "BoM Date:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getDate(), cellformat_left) + rowCount += 1 - if len(net.getDate()) > column_widths[1]: - column_widths[1] = len(net.getDate()) + if len(net.getDate()) > column_widths[1]: + column_widths[1] = len(net.getDate()) - worksheet.write_string( rowCount, 0, "Schematic Source:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getSource(), cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "Schematic Source:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getSource(), cellformat_left) + rowCount += 1 - if len(net.getSource()) > column_widths[1]: - column_widths[1] = len(net.getSource()) + if len(net.getSource()) > column_widths[1]: + column_widths[1] = len(net.getSource()) - worksheet.write_string( rowCount, 0, "KiCad Version:", cellformats[0]) - worksheet.write_string( rowCount, 1, net.getTool(), cellformat_left) - rowCount += 1 + worksheet.write_string( rowCount, 0, "KiCad Version:", cellformats[0]) + worksheet.write_string( rowCount, 1, net.getTool(), cellformat_left) + rowCount += 1 - if len(net.getTool()) > column_widths[1]: - column_widths[1] = len(net.getTool()) + if len(net.getTool()) > column_widths[1]: + column_widths[1] = len(net.getTool()) - for i in range(len(column_widths)): - worksheet.set_column( i, i, column_widths[i]) + for i in range(len(column_widths)): + worksheet.set_column( i, i, column_widths[i]) - workbook.close() + workbook.close() - return True + return True From e03daedcdd72b59b967db6e1d4bd6e4303aa689d Mon Sep 17 00:00:00 2001 From: Maxime Rijnders Date: Sun, 19 May 2019 13:23:18 +0200 Subject: [PATCH 7/8] Remove print --- bomlib/xlsx_writer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bomlib/xlsx_writer.py b/bomlib/xlsx_writer.py index 1c69d8f..a725366 100644 --- a/bomlib/xlsx_writer.py +++ b/bomlib/xlsx_writer.py @@ -76,8 +76,6 @@ def WriteXLSX(filename, groups, net, headings, prefs): rowCount += 1 - print('Done') - if not prefs.hideHeaders: #blank rows for i in range(5): From a32634918cfb1331e171bd2cf4a7e58e87963779 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Thu, 30 May 2019 09:48:30 +0200 Subject: [PATCH 8/8] Cleanup --- KiBOM_CLI.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/KiBOM_CLI.py b/KiBOM_CLI.py index 3073960..c99b21e 100755 --- a/KiBOM_CLI.py +++ b/KiBOM_CLI.py @@ -26,14 +26,10 @@ # Optional modules -xlsxwriter_available = False try: import xlsxwriter except: - print() - print('Module not found: xlsxwriter') - print('XLSX output format not available.') - print() + xlsxwriter_available = False else: xlsxwriter_available = True @@ -61,10 +57,9 @@ def say(*arg): def isExtensionSupported(filename): result = False + extensions = [".xml",".csv",".txt",".tsv",".html"] if xlsxwriter_available: - extensions = [".xml",".csv",".txt",".tsv",".html",".xlsx"] - else: - extensions = [".xml",".csv",".txt",".tsv",".html"] + extensions.append(".xlsx") for e in extensions: if filename.endswith(e): result = True