How to use the tablib.Databook function in tablib

To help you get started, we’ve selected a few tablib 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 jazzband / tablib / tests / test_tablib.py View on Github external
def test_yaml_import_book(self):
        """Generate and import YAML book serialization."""
        data.append(self.john)
        data.append(self.george)
        data.headers = self.headers

        book.add_sheet(data)
        _yaml = book.yaml

        book.yaml = _yaml

        self.assertEqual(_yaml, book.yaml)
        # Same with the load interface
        book2 = tablib.Databook().load(_yaml, None)
        self.assertEqual(_yaml, book2.yaml)
github Nexedi / dream / dream / simulation / applications / FrozenSimulation / Globals.py View on Github external
import tablib

class G:
    
    Schedule={}
    MachPool = None
    PMPool = None
    Projects = None
    xlreftime = None
    OrderDates = None
    jsonInput = None
    excelInput = None
    simMode = None
    
    # reporting tabs
    reportResults = tablib.Databook()
    tabSchedule = {}
    pmSchedule = {}
    tabScheduleOrig = []
    pmScheduleOrig = []
    
    # re-initialised variables
    completionDate = {}
    seqPrjDone = None
    resAvailability = None
    seqPrjDoneOrig = None
    resAvailabilityOrig = None
github yukonhenry / datagraph / scheduler_service / util / xls_exporter.py View on Github external
for team_id in teamrange:
                team_str = div_str + str(team_id)
                datasheet = Dataset(title=team_str)
                datasheet.headers = list(headers)
                match_list = self.sdbinterface.get_schedule('team_id',
                    div_age=div_age, div_gen=div_gen, team_id=team_id)
                tabformat_list = [(x['game_date'],
                    parser.parse(x['game_date']).strftime("%a"),
                    datetime.strptime(x['start_time'], "%H:%M").strftime("%I:%M%p"),
                    div_str, x['home'], x['away'],
                    self.fieldinfo_list[self.findexerGet(x['venue'])]['field_name'])
                    for x in match_list]
                for tabformat in tabformat_list:
                    datasheet.append(tabformat)
                datasheet_list.append(datasheet)
            book = Databook(datasheet_list)
            bookname_xls_relpath = self.schedcol_name + div_str+"_byTeam.xls"
            bookname_xls_fullpath = os.path.join(self.dir_path,
                bookname_xls_relpath)
            with open(bookname_xls_fullpath,'wb') as f:
               f.write(book.xls)
            f.close()
            file_list.append({'path':bookname_xls_relpath, 'mdata':div_str})
        return file_list
github Nexedi / dream / dream / simulation / applications / DemandPlanning / Globals.py View on Github external
for week in G.WeekList:
                G.globalMAAllocation[ma][week] = {'order':{}}
                G.globalMAAllocationIW[ma][week] = {'order':{}}
                for priority in G.priorityList['order']:
                    G.globalMAAllocation[ma][week]['order'][priority] = 0 
                    G.globalMAAllocationIW[ma][week]['order'][priority] = 0
                G.globalMAAllocation[ma][week]['forecast'] = {}
                G.globalMAAllocationIW[ma][week]['forecast'] = {}
                for priority in G.priorityList['forecast']:
                    G.globalMAAllocation[ma][week]['forecast'][priority] = 0 
                    G.globalMAAllocationIW[ma][week]['forecast'][priority] = 0

    G.LateMeasures = {'noLateOrders':0, 'lateness':[], 'noEarlyOrders':0, 'earliness':[], 'noExcess':0, 'exUnits':0}
    
    # output variables
    G.reportResults = tablib.Databook()
    G.OrderResults = tablib.Dataset(title='OrderSummary')
    G.OrderResults.headers = ('OrderID', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA','ORDERED_MA_LIST', 'LATENESS', 'EARLINESS', 'ALLOCATION')
    G.OrderResultsShort = tablib.Dataset(title='OrderResultsForDM')
    G.OrderResultsShort.headers = ('OrderID', 'MA_LIST')
    G.forecastResults = tablib.Dataset(title='ForecastSummary')
    G.forecastResults.headers = ('PPOS', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA', 'LATENESS', 'EARLINESS', 'ALLOCATION')
    G.CapacityResults = None
    G.CapacityResults = tablib.Dataset(title = 'BN_Capa')
    G.allocationResults = tablib.Dataset(title = 'Demand_coverage')
    G.Utilisation = {}
    G.Butilisation = {}
github avilaton / gtfseditor / server / tables.py View on Github external
def saveBook(sheets):
    book = tablib.Databook()
    for sheet in sheets:
        book.add_sheet(sheet)

    with open('stops.xls', 'wb') as f:
        f.write(book.xls)
github yukonhenry / datagraph / scheduler_service / legacy / sched_exporter.py View on Github external
headers = ['Match ID', 'Gameday#', 'Game Date', 'Day', 'Time', 'Division', 'Home', 'Away', 'Field', '', 'Comment']
        datasheet_list = []
        for division in self.leaguedivinfo:
            div_id = division['div_id']
            div_age = division['div_age']
            div_gen = division['div_gen']
            div_str =  div_age + div_gen
            datasheet = Dataset(title=div_str)
            datasheet.headers = list(headers)
            divdata_list = self.dbinterface.findElimTournDivisionSchedule(div_age, div_gen, min_game_id=startgameday)
            tabformat_list = [(y[match_id_CONST], x[gameday_id_CONST], tournMapGamedayIdToCalendar(x[gameday_id_CONST]), tournMapGamedayIdToDate(x[gameday_id_CONST]), datetime.strptime(x[start_time_CONST],"%H:%M").strftime("%I:%M %p"), div_str, y[home_CONST], y[away_CONST], self.fieldinfo[self.findexerGet(y[venue_CONST])]['name'], '', y[comment_CONST]) for x in divdata_list for y in x[gameday_data_CONST]]
            for tabformat in tabformat_list:
                datasheet.append(tabformat)
            datasheet.append_separator("Prefix Legend: 'S'-Seeded Team#, 'W'-Winning Team (See Match ID), 'L'-Losing Team)")
            datasheet_list.append(datasheet)
        book = Databook(datasheet_list)
        cdir = os.path.dirname(__file__)
        bookname_xls = prefix+'.xls'
        bookname_html = prefix+'.html'
        booknamefull_xls = os.path.join('/home/henry/workspace/datagraph/bottle_baseball/download/xls', bookname_xls)
        booknamefull_html = os.path.join('~/workspace/datagraph/bottle_baseball/download/html', bookname_html)
        with open(booknamefull_xls,'wb') as f:
            f.write(book.xls)
        f.close()
github CityOfNewYork / NYCOpenRecords / app / report / utils.py View on Github external
metrics = [
        ('Received for the current month', received_current_month),
        ('Total remaining open from current month', remaining_open_current_month),
        ('Closed in the current month that were received in the current month', total_opened_closed_in_month),
        ('Total closed in current month no matter when received', len(closed_in_month)),
        ('Total closed since portal started', len(total_closed)),
        ('Total remaining Open/Pending', len(remaining_open_or_pending)),
        ('Inquiries for current month', len(contact_agency_emails))
    ]
    metrics_headers = ['Metric', 'Count']
    metrics_dataset = tablib.Dataset(*metrics,
                                     headers=metrics_headers,
                                     title='Metrics')

    # Create Databook from Datasets
    excel_spreadsheet = tablib.Databook((
        metrics_dataset,
        opened_in_month_dataset,
        remaining_open_or_pending_dataset,
        closed_in_month_dataset,
        total_closed_dataset,
        opened_closed_in_month_dataset,
        contact_agency_emails_dataset
    ))

    # Email report
    send_email(subject='OpenRecords Monthly Metrics Report',
               to=email_to,
               email_content='Report attached',
               attachment=excel_spreadsheet.export('xls'),
               filename='FOIL_monthly_metrics_report_{}_{}.xls'.format(date_from, date_to),
               mimetype='application/octet-stream')
github CityOfNewYork / NYCOpenRecords / app / report / utils.py View on Github external
request.requester.name,
            request.requester.email,
            request.requester.phone_number,
            request.requester.mailing_address.get('address_one'),
            request.requester.mailing_address.get('address_two'),
            request.requester.mailing_address.get('city'),
            request.requester.mailing_address.get('state'),
            request.requester.mailing_address.get('zip'),
        ))
    date_from_string = date_from.strftime('%Y%m%d')
    date_to_string = date_to.strftime('%Y%m%d')
    dates_dataset = tablib.Dataset(*data_from_dates,
                                   headers=headers,
                                   title='{}_{}'.format(date_from_string, date_to_string))
    all_dataset = tablib.Dataset(*all_data, headers=headers, title='all')
    excel_spreadsheet = tablib.Databook((dates_dataset, all_dataset))
    send_email(subject='OpenRecords Acknowledgment Report',
               to=[current_user.email],
               template='email_templates/email_agency_report_generated',
               agency_user=current_user.name,
               attachment=excel_spreadsheet.export('xls'),
               filename='FOIL_acknowledgments_{}_{}.xls'.format(date_from_string, date_to_string),
               mimetype='application/octect-stream')