tick_mark': 'none',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232', 'rotation': -45},
            'position_axis': 'on_tick',
            'interval_unit': 4,
            'line': {'color': '#bebebe'}
        })
            
        agfuel_chart2.set_y_axis({
           'major_tick_mark': 'none', 
           'minor_tick_mark': 'none',
            'name': 'PJ',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232'},
           'major_gridlines': {
                'visible': True,
                'line': {'color': '#bebebe'}
            },
            'line': {'color': '#bebebe'}
        })
            
        agfuel_chart2.set_legend({
            'font': {'font': 'Segoe UI','size': 10}
            #'none': True
        })
            
        agfuel_chart2.set_title({
            'none': True
        })
        
        # Configure the series of the chart from the dataframe data.
        for i in range(ag_fuel_rows):
            agfuel_chart2.add_series({
                'name':       [economy + '_ag_use', chart_height + i + 1, 1],
                'categories': [economy + '_ag_use', chart_height, 2, chart_height, ag_fuel_cols - 1],
                'values':     [economy + '_ag_use', chart_height + i + 1, 2, chart_height + i + 1, ag_fuel_cols - 1],
                'line':       {'color': colours_hex[i], 'width': 1}
            })    
            
        worksheet1.insert_chart('J3', agfuel_chart2)

    else:
        pass

    # Create a agriculture tech area chart
    if ag_tech_rows > 0:
        agsector_chart1 = workbook.add_chart({'type': 'area','subtype':'stacked'})
        agsector_chart1.set_size({
            'width': 500,
            'height': 300
        })
        
        agsector_chart1.set_chartarea({
            'border': {'none': True}
        })
        
        agsector_chart1.set_x_axis({
            'name': 'Year',
            'label_position': 'low',
           'major_tick_mark': 'none',
           'minor_tick_mark': 'none',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232', 'rotation': -45},
            'position_axis': 'on_tick',
            'interval_unit': 4,
            'line': {'color': '#bebebe'}
        })
            
        agsector_chart1.set_y_axis({
           'major_tick_mark': 'none', 
           'minor_tick_mark': 'none',
            'name': 'PJ',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232'},
           'major_gridlines': {
                'visible': True,
                'line': {'color': '#bebebe'}
            },
            'line': {'color': '#bebebe'}
        })
            
        agsector_chart1.set_legend({
            'font': {'font': 'Segoe UI','size': 10}
            #'none': True
        })
            
        agsector_chart1.set_title({
            'none': True
        })
        
        # Configure the series of the chart from the dataframe data.
        for i in range(ag_tech_rows):
            agsector_chart1.add_series({
                'name':       [economy + '_ag_use', chart_height + ag_fuel_rows + i + 4, 0],
                'categories': [economy + '_ag_use', chart_height + ag_fuel_rows + 3, 2, chart_height + ag_fuel_rows + 3, ag_tech_cols - 1],
                'values':     [economy + '_ag_use', chart_height + ag_fuel_rows + i + 4, 2, chart_height + ag_fuel_rows + i + 4, ag_tech_cols - 1],
                'fill':       {'color': colours_hex[i]},
                'border':     {'none': True}
            })    
            
        worksheet1.insert_chart('R3', agsector_chart1)

        # Create a ag fuel line chart 
        agsector_chart2 = workbook.add_chart({'type': 'line'})
        agsector_chart2.set_size({
            'width': 500,
            'height': 300
        })
        
        agsector_chart2.set_chartarea({
            'border': {'none': True}
        })
        
        agsector_chart2.set_x_axis({
            'name': 'Year',
            'label_position': 'low',
           'major_tick_mark': 'none',
           'minor_tick_mark': 'none',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232', 'rotation': -45},
            'position_axis': 'on_tick',
            'interval_unit': 4,
            'line': {'color': '#bebebe'}
        })
            
        agsector_chart2.set_y_axis({
           'major_tick_mark': 'none', 
           'minor_tick_mark': 'none',
            'name': 'PJ',
            'num_font': {'font': 'Segoe UI','size': 10, 'color': '#323232'},
           'major_gridlines': {
                'visible': True,
                'line': {'color': '#bebebe'}
            },
            'line': {'color': '#bebebe'}
        })
            
        agsector_chart2.set_legend({
            'font': {'font': 'Segoe UI','size': 10}
            #'none': True
        })
            
        agsector_chart2.set_title({
            'none': True
        })
        
        # Configure the series of the chart from the dataframe data.
        for i in range(ag_tech_rows):
            agsector_chart2.add_series({
                'name':       [economy + '_ag_use', chart_height + ag_fuel_rows + i + 4, 0],
                'categories': [economy + '_ag_use', chart_height + ag_fuel_rows + 3, 2, chart_height + ag_fuel_rows + 3, ag_tech_cols - 1],
                'values':     [economy + '_ag_use', chart_height + ag_fuel_rows + i + 4, 2, chart_height + ag_fuel_rows + i + 4, ag_tech_cols - 1],
                'line':       {'color': colours_hex[i], 'width': 1}
            })    
            
        worksheet1.insert_chart('Z3', agsector_chart2)

    else: 
        pass

    ############################################################################################################################

    # Access the workbook and first sheet with data from df1
    worksheet2 = writer.sheets[economy + '_bld_use']
    
    # Comma format and header format        
    comma_format = workbook.add_format({'num_format': '#,##0'})
    header_format = workbook.add_format({'font_name': 'Calibri', 'font_size': 11, 'bold': True})
    cell_format1 = workbook.add_format({'bold': True})
        
    # Apply comma format and header format to relevant data rows
    worksheet2.set_column(2, bld_fuel_cols + 1, None, comma_format)
    worksheet2.set_row(chart_height, None, header_format)
    worksheet2.set_row(chart_height + bld_fuel_rows + 3, None, header_format)
    worksheet2.write(0, 0, economy +'Buildings OSeMOSYS output by fuel and by technology', cell_format1)

    # Create a bld fuel area chart
    if bld_fuel_rows > 0:
        bldfuel_chart1 = workbook.add_chart({'type': '