Ejemplo n.º 1
0
def summarize_sales():
    """
    Retrieve the account number and date ranges from the Excel sheet
    """
    # Make a connection to the calling Excel file
    wb = Book.caller()

    # Retrieve the account number and dates
    account = Range('B2').value
    start_date = Range('D2').value
    end_date = Range('F2').value

    # Output the data just to make sure it all works
    Range('A5').value = account
    Range('A6').value = start_date
    Range('A7').value = end_date
Ejemplo n.º 2
0
def main():
    print('checkmyxl project generator')
    parser = ArgumentParser(add_help=False)
    parser.add_argument('-s', '--sample', action='store_true')
    args = parser.parse_args()
    try:
        run(['xlwings', 'quickstart', 'book'], check=True)
    except FileNotFoundError:
        print('Command not found: `xlwings`.',
              'xlwings package is not installed.',
              'Online installation guide:',
              'https://docs.xlwings.org/en/stable/installation.html.',
              sep='\n')
        exit(1)
    try:
        run(['mv', join_path('book', 'book.xlsm'), 'book.xlsm'], check=True)
    except CalledProcessError:
        print('The project `book` has not been created.')
        exit(1)
    try:
        run(['rm', '-r', 'book'], check=True)
    except CalledProcessError:
        print('Temporary directory `book` cannot be removed.')
        exit(1)
    if apps.count == 0:
        App()
    Book('book.xlsm').set_mock_caller()
    book = Book.caller()
    sheets = book.sheets
    sheets.add('Sheet1.code', after='Sheet1')
    sheets.add('checkmyxl.conf', after='Sheet1.code')
    book.save()
    print('Successfully generated `book.xlsm` file.')
    if args.sample:
        sheet1, sheet1_code, checkmyxl_conf = \
            sheets['Sheet1'], sheets['Sheet1.code'], sheets['checkmyxl.conf']
        sheet1['A1'].options(index=False).value = \
            read_csv(join_path('sample', 'sample.csv'))
        sheet1_code['A1'].options(index=False).value = \
            read_csv(join_path('sample', 'sample_code.csv'))
        checkmyxl_conf['A1'].options(index=False).value = \
            read_csv(join_path('sample', 'sample_conf.csv'))
        print('Sample added.')
Ejemplo n.º 3
0
def main():
    book = Book.caller()
    active_sheet = book.sheets.active
    active_range = active_sheet.used_range
    code_sheet = book.sheets[f'{active_sheet.name}.code']
    code_range = code_sheet.used_range
    conf_sheet = book.sheets['checkmyxl.conf']
    imports = conf_sheet['B1'].value
    exec(imports)
    for cell in code_range:
        if cell.value is not None:
            this_sheet = active_sheet
            this_table = active_range
            this_row = active_sheet.range(
                (cell.row, active_range.column),
                (cell.row, active_range.last_cell.column))
            this_column = active_sheet.range(
                (active_range.row + 1, cell.column),
                (active_range.last_cell.row, cell.column))
            this_cell = active_sheet[cell.get_address(False, False)]
            exec(cell.value)