How to use the openpyxl.Workbook function in openpyxl

To help you get started, we’ve selected a few openpyxl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gwax / mtg_ssm / tests / serialization / test_xlsx.py View on Github external
def test_create_all_cards_sheet(oracle: Oracle) -> None:
    book = openpyxl.Workbook()
    sheet = book.create_sheet()
    xlsx.create_all_cards(sheet, oracle.index)
    assert sheet.title == "All Cards"
    rows = [[cell.value for cell in row] for row in sheet.rows]
    assert rows == [
        ["name", "have"],
        ["Air Elemental", '=IF(\'LEA\'!A2>0,"LEA: "&\'LEA\'!A2&", ","")'],
        ["Akroma's Vengeance", '=IF(\'HOP\'!A2>0,"HOP: "&\'HOP\'!A2&", ","")'],
        [
            "Dark Ritual",
            '=IF(\'LEA\'!A3>0,"LEA: "&\'LEA\'!A3&", ","")&'
            'IF(\'ICE\'!A2>0,"ICE: "&\'ICE\'!A2&", ","")&'
            'IF(\'HOP\'!A3>0,"HOP: "&\'HOP\'!A3&", ","")',
        ],
        ["Forest", None],
        ["Rhox", '=IF(\'S00\'!A2>0,"S00: "&\'S00\'!A2&", ","")'],
github abenassi / xlseries / tests / strategies / get / test_data.py View on Github external
def test_fill_implicit_missings_horizontal(self):
        strategy = GetSingleFrequencyContinuous
        wb = Workbook()
        ws = wb.active

        ws["A1"] = arrow.get(2015, 6, 13).datetime
        ws["B1"] = arrow.get(2015, 6, 14).datetime
        ws["C1"] = arrow.get(2015, 6, 15).datetime
        ws["D1"] = arrow.get(2015, 6, 18).datetime
        ws["E1"] = arrow.get(2015, 6, 19).datetime
        ws["F1"] = arrow.get(2015, 6, 20).datetime
        ws["G1"] = arrow.get(2015, 6, 22).datetime
        ws["H1"] = arrow.get(2015, 6, 23).datetime

        values = range(8)
        frequency = "D"
        time_header_coord = "A1"
        ini_col = 1
        end_col = 8
github associatedpress / geomancer / geomancer / worker.py View on Github external
def writeXLSX(fpath, output):
    with open(fpath, 'wb') as f:
        workbook = Workbook()
        sheet = workbook.active
        sheet.title = 'Geomancer Output'
        numcols = len(output[0])
        for r, row in enumerate(output):
            sheet.append([row[col_idx] for col_idx in range(numcols)])
        workbook.save(fpath)
github pretix / pretix / src / pretix / base / exporter.py View on Github external
def _render_xlsx(self, form_data, output_file=None):
        wb = Workbook()
        ws = wb.get_active_sheet()
        wb.remove(ws)
        for s, l in self.sheets:
            ws = wb.create_sheet(str(l))
            for i, line in enumerate(self.iterate_sheet(form_data, sheet=s)):
                for j, val in enumerate(line):
                    ws.cell(row=i + 1, column=j + 1).value = str(val) if not isinstance(val, KNOWN_TYPES) else val

        if output_file:
            wb.save(output_file)
            return self.get_filename() + '.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', None
        else:
            with tempfile.NamedTemporaryFile(suffix='.xlsx') as f:
                wb.save(f.name)
                f.seek(0)
                return self.get_filename() + '.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', f.read()
github gil9red / SimplePyScripts / office__excel__openpyxl__xlwt / xlsx__merge_cells__and__formula_cell__SUM_function.py View on Github external
# -*- coding: utf-8 -*-

__author__ = 'ipetrash'


import openpyxl


columns = ['Language', 'Text', 'Total']
rows = [
    ['python', 1],
    ['java', 2],
    ['c#', 3],
]

wb = openpyxl.Workbook()
ws = wb.get_active_sheet()

for i, value in enumerate(columns, 1):
    ws.cell(row=1, column=i).value = value

for i, row in enumerate(rows, 2):
    for j, value in enumerate(row, 1):
        cell = ws.cell(row=i, column=j)
        cell.value = value

ws.merge_cells('C2:C4')

# Total:
ws['C2'].value = '=SUM(B2:B4)'

wb.save('excel.xlsx')
github BCV-Uniandes / AUNets / utils.py View on Github external
def createxls(config, mode):
    sheet = 'OF_' + config.OF_option if not config.HYDRA else 'Hydra_OF_'\
        + config.OF_option
    try:
        wb = openpyxl.load_workbook(
            config.xlsfile.replace('.xlsx', '_' + mode + '.xlsx'))
    except BaseException:
        wb = openpyxl.Workbook()
        wb.remove_sheet(wb.active)

    try:
        ws = wb.get_sheet_by_name(sheet)
    except BaseException:
        ws = wb.create_sheet(sheet)

    count = 1
    start_pos = [count]
    count = createSectionxls(ws, '0.5', count)
    start_pos.append(count)
    count = createSectionxls(ws, 'median3', count)
    start_pos.append(count)
    count = createSectionxls(ws, 'median5', count)
    start_pos.append(count)
    count = createSectionxls(ws, 'median7', count)
github TheKnightCoder / Ansible-Networking / lib / modules / poe_devices.py View on Github external
def WriteDictToXl(file_path, hostname, data):
  
  bold = Font(bold=True)
  file_exists = os.path.isfile(file_path)
  if file_exists:
    wb = load_workbook(file_path)
    ws = wb.create_sheet(hostname)
  else:
    wb = Workbook()
    ws = wb.active
    ws.title = hostname
    
  for i in range(0,len(data[0])): #adding column headers
    cell=ws.cell(row=1, column=i+1, value=data[0].keys()[i])
    cell.font = bold
 
  greenFill = PatternFill(fill_type='solid', start_color='c6efce', end_color='c6efce')
  for item in data:
    cur_row = ws.max_row+1
    for i in range(0,len(item)):
      if(isinstance(item.values()[i], list)): #if values in col is a list convert to a string
        item.values()[i]= str('\n'.join(item.values()[i]))
      cell = ws.cell(row=cur_row, column=i+1, value=str(item.values()[i]))
      if item.values()[i] == "on":
        cell.fill = greenFill
github ALSETLab / Nordic44-Nordpool / nordic44 / n44.py View on Github external
def create_excel_sheet(self):
        """Function to set up the summary excel sheet.
        """

        self.wb = openpyxl.Workbook()
        sheet = self.wb.active
        # Row and column headings
        sheet['A3'] = 'NO1'
        sheet['A4'] = 'NO2'
        sheet['A5'] = 'NO3'
        sheet['A6'] = 'NO4'
        sheet['A7'] = 'NO5'
        sheet['A8'] = 'SE1'
        sheet['A9'] = 'SE2'
        sheet['A10'] = 'SE3'
        sheet['A11'] = 'SE4'
        sheet['A12'] = 'FI1'
        sheet['A14'] = 'Additional loads'
        sheet['A15'] = 'Bus 3020, area SE3, HVDC link SE3-FI'
        sheet['A16'] = 'Bus 3360, area SE3, HVDC link SE3-DK1'
        sheet['A17'] = 'Bus 5610, area NO2, HVDC link NO-DK'
github gil9red / SimplePyScripts / office__excel__openpyxl__xlwt / xlsx__set_sheet_zoom_scale.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'ipetrash'


import openpyxl

wb = openpyxl.Workbook()

ws = wb.get_active_sheet()
ws.title = '10'
ws.sheet_view.zoomScale = 10

ws = wb.create_sheet('20')
ws.sheet_view.zoomScale = 20

ws = wb.create_sheet('50')
ws.sheet_view.zoomScale = 50

ws = wb.create_sheet('100')
# ws.sheet_view.zoomScale = 100

ws = wb.create_sheet('200')
ws.sheet_view.zoomScale = 200