<s> import os <EOL> import sys <EOL> cwd = os . getcwd ( ) <EOL> if not hasattr ( sys , '<STR_LIT>' ) : <EOL> os . chdir ( sys . exec_prefix ) <EOL> import win32api <EOL> os . chdir ( cwd ) <EOL> from warnings import warn <EOL> import pywintypes <EOL> import pythoncom <EOL> from win32com . client import dynamic , Dispatch , CDispatch , DispatchBaseClass <EOL> import win32timezone <EOL> import win32gui <EOL> import datetime as dt <EOL> from . constants import Direction , ColorIndex <EOL> from . utils import rgb_to_int , int_to_rgb , get_duplicates , np_datetime_to_datetime <EOL> from ctypes import oledll , PyDLL , py_object , byref , POINTER <EOL> from comtypes import IUnknown <EOL> from comtypes . automation import IDispatch <EOL> try : <EOL> import pandas as pd <EOL> except ImportError : <EOL> pd = None <EOL> try : <EOL> import numpy as np <EOL> except ImportError : <EOL> np = None <EOL> from . import PY3 <EOL> time_types = ( dt . date , dt . datetime , type ( pywintypes . Time ( <NUM_LIT:0> ) ) ) <EOL> if np : <EOL> time_types = time_types + ( np . datetime64 , ) <EOL> OBJID_NATIVEOM = - <NUM_LIT:16> <EOL> def accessible_object_from_window ( hwnd ) : <EOL> ptr = POINTER ( IDispatch ) ( ) <EOL> res = oledll . oleacc . AccessibleObjectFromWindow ( <EOL> hwnd , OBJID_NATIVEOM , <EOL> byref ( IDispatch . _iid_ ) , byref ( ptr ) ) <EOL> return ptr <EOL> def comtypes_to_pywin ( ptr , interface = None ) : <EOL> _PyCom_PyObjectFromIUnknown = PyDLL ( pythoncom . __file__ ) . PyCom_PyObjectFromIUnknown <EOL> _PyCom_PyObjectFromIUnknown . restype = py_object <EOL> if interface is None : <EOL> interface = IUnknown <EOL> return _PyCom_PyObjectFromIUnknown ( ptr , byref ( interface . _iid_ ) , True ) <EOL> def get_xl_app_from_hwnd ( hwnd ) : <EOL> child_hwnd = win32gui . FindWindowEx ( hwnd , <NUM_LIT:0> , '<STR_LIT>' , None ) <EOL> child_hwnd = win32gui . FindWindowEx ( child_hwnd , <NUM_LIT:0> , '<STR_LIT>' , None ) <EOL> ptr = accessible_object_from_window ( child_hwnd ) <EOL> p = comtypes_to_pywin ( ptr , interface = IDispatch ) <EOL> disp = Dispatch ( p ) <EOL> return disp . Application <EOL> def get_excel_hwnds ( ) : <EOL> hwnds = [ ] <EOL> win32gui . EnumWindows ( lambda hwnd , result_list : result_list . append ( hwnd ) , hwnds ) <EOL> excel_hwnds = [ ] <EOL> for hwnd in hwnds : <EOL> try : <EOL> if win32gui . FindWindowEx ( hwnd , <NUM_LIT:0> , '<STR_LIT>' , None ) : <EOL> excel_hwnds . append ( hwnd ) <EOL> except pywintypes . error : <EOL> pass <EOL> return excel_hwnds <EOL> def get_xl_apps ( ) : <EOL> xl_apps = [ ] <EOL> hwnds = get_excel_hwnds ( ) <EOL> for hwnd in hwnds : <EOL> try : <EOL> xl_app = get_xl_app_from_hwnd ( hwnd ) <EOL> xl_apps . append ( xl_app ) <EOL> except WindowsError : <EOL> pass <EOL> return xl_apps <EOL> def get_all_open_xl_workbooks ( xl_app ) : <EOL> return [ xl_workbook for xl_workbook in xl_app . Workbooks ] <EOL> def is_file_open ( fullname ) : <EOL> if not PY3 : <EOL> if isinstance ( fullname , str ) : <EOL> fullname = unicode ( fullname , '<STR_LIT>' ) <EOL> open_workbooks = [ ] <EOL> for xl_app in get_xl_apps ( ) : <EOL> open_fullnames = [ i . FullName . lower ( ) for i in get_all_open_xl_workbooks ( xl_app ) ] <EOL> for fn in open_fullnames : <EOL> open_workbooks . append ( fn ) <EOL> return fullname . lower ( ) in open_workbooks <EOL> def get_duplicate_fullnames ( ) : <EOL> """<STR_LIT>""" <EOL> open_xl_workbooks = [ ] <EOL> for xl_app in get_xl_apps ( ) : <EOL> for xl_workbook in get_all_open_xl_workbooks ( xl_app ) : <EOL> open_xl_workbooks . append ( xl_workbook ) <EOL> return get_duplicates ( [ i . FullName . lower ( ) for i in open_xl_workbooks ] ) <EOL> def get_open_workbook ( fullname , app_target = None , hwnd = None ) : <EOL> """<STR_LIT>""" <EOL> if app_target is not None : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> if not PY3 : <EOL> if isinstance ( fullname , str ) : <EOL> fullname = unicode ( fullname , '<STR_LIT>' ) <EOL> duplicate_fullnames = get_duplicate_fullnames ( ) <EOL> if hwnd is None : <EOL> xl_apps = get_xl_apps ( ) <EOL> else : <EOL> hwnd = int ( hwnd ) <EOL> xl_apps = [ get_xl_app_from_hwnd ( hwnd ) ] <EOL> for xl_app in xl_apps : <EOL> for xl_workbook in get_all_open_xl_workbooks ( xl_app ) : <EOL> if ( <EOL> xl_workbook . FullName . lower ( ) == fullname . lower ( ) or <EOL> xl_workbook . Name . lower ( ) == fullname . lower ( ) <EOL> ) : <EOL> if ( xl_workbook . FullName . lower ( ) not in duplicate_fullnames ) or ( hwnd is not None ) : <EOL> return xl_app , xl_workbook <EOL> else : <EOL> warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return xl_app , xl_workbook <EOL> def get_active_workbook ( app_target = None ) : <EOL> if app_target is not None : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> hwnd_active_workbook = get_excel_hwnds ( ) [ <NUM_LIT:0> ] <EOL> xl_app = get_xl_app_from_hwnd ( hwnd_active_workbook ) <EOL> return xl_app . ActiveWorkbook <EOL> def get_workbook_name ( xl_workbook ) : <EOL> return xl_workbook . Name <EOL> def get_worksheet_name ( xl_sheet ) : <EOL> return xl_sheet . Name <EOL> def is_range_instance ( xl_range ) : <EOL> pyid = getattr ( xl_range , '<STR_LIT>' , None ) <EOL> if pyid is None : <EOL> return False <EOL> return xl_range . _oleobj_ . GetTypeInfo ( ) . GetTypeAttr ( ) . iid == pywintypes . IID ( '<STR_LIT>' ) <EOL> def get_sheet_workbook ( xl_sheet ) : <EOL> return xl_sheet . Parent <EOL> def get_range_sheet ( xl_range ) : <EOL> return xl_range . Worksheet <EOL> def get_range_coordinates ( xl_range ) : <EOL> row1 = xl_range . Row <EOL> col1 = xl_range . Column <EOL> row2 = row1 + xl_range . Rows . Count - <NUM_LIT:1> <EOL> col2 = col1 + xl_range . Columns . Count - <NUM_LIT:1> <EOL> return ( row1 , col1 , row2 , col2 ) <EOL> def get_xl_sheet ( xl_workbook , sheet_name_or_index ) : <EOL> return xl_workbook . Sheets ( sheet_name_or_index ) <EOL> def set_worksheet_name ( xl_sheet , value ) : <EOL> xl_sheet . Name = value <EOL> def get_worksheet_index ( xl_sheet ) : <EOL> return xl_sheet . Index <EOL> def get_app ( xl_workbook , app_target ) : <EOL> if app_target is not None : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> return xl_workbook . Application <EOL> def _get_latest_app ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return xl_workbook_current . Application <EOL> except ( NameError , AttributeError , pywintypes . com_error ) : <EOL> return dynamic . Dispatch ( '<STR_LIT>' ) <EOL> def open_workbook ( fullname , app_target ) : <EOL> if app_target is not None : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> xl_app = _get_latest_app ( ) <EOL> xl_workbook = xl_app . Workbooks . Open ( fullname ) <EOL> return xl_app , xl_workbook <EOL> def close_workbook ( xl_workbook ) : <EOL> xl_workbook . Close ( SaveChanges = False ) <EOL> def new_workbook ( app_target ) : <EOL> if app_target is not None : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> xl_app = _get_latest_app ( ) <EOL> xl_workbook = xl_app . Workbooks . Add ( ) <EOL> return xl_app , xl_workbook <EOL> def get_active_sheet ( xl_workbook ) : <EOL> return xl_workbook . ActiveSheet <EOL> def activate_sheet ( xl_workbook , sheet ) : <EOL> return xl_workbook . Sheets ( sheet ) . Activate ( ) <EOL> def get_worksheet ( xl_workbook , sheet ) : <EOL> return xl_workbook . Sheets ( sheet ) <EOL> def get_first_row ( xl_sheet , range_address ) : <EOL> return xl_sheet . Range ( range_address ) . Row <EOL> def get_first_column ( xl_sheet , range_address ) : <EOL> return xl_sheet . Range ( range_address ) . Column <EOL> def count_rows ( xl_sheet , range_address ) : <EOL> return xl_sheet . Range ( range_address ) . Rows . Count <EOL> def count_columns ( xl_sheet , range_address ) : <EOL> return xl_sheet . Range ( range_address ) . Columns . Count <EOL> def get_range_from_indices ( xl_sheet , first_row , first_column , last_row , last_column ) : <EOL> return xl_sheet . Range ( xl_sheet . Cells ( first_row , first_column ) , <EOL> xl_sheet . Cells ( last_row , last_column ) ) <EOL> def get_value_from_range ( xl_range ) : <EOL> return xl_range . Value <EOL> def clean_value_data ( data , datetime_builder , empty_as , number_builder ) : <EOL> if number_builder is not None : <EOL> return [ <EOL> [ <EOL> _com_time_to_datetime ( c , datetime_builder ) <EOL> if isinstance ( c , time_types ) else <EOL> number_builder ( c ) <EOL> if type ( c ) == float else <EOL> empty_as <EOL> if c is None else <EOL> c <EOL> for c in row <EOL> ] <EOL> for row in data <EOL> ] <EOL> else : <EOL> return [ <EOL> [ <EOL> _com_time_to_datetime ( c , datetime_builder ) <EOL> if isinstance ( c , time_types ) <EOL> else empty_as <EOL> if c is None <EOL> else c <EOL> for c in row <EOL> ] <EOL> for row in data <EOL> ] <EOL> def get_value_from_index ( xl_sheet , row_index , column_index ) : <EOL> return xl_sheet . Cells ( row_index , column_index ) . Value <EOL> def set_value ( xl_range , data ) : <EOL> xl_range . Value = data <EOL> def _com_time_to_datetime ( com_time , datetime_builder ) : <EOL> """<STR_LIT>""" <EOL> if PY3 : <EOL> return datetime_builder ( month = com_time . month , day = com_time . day , year = com_time . year , <EOL> hour = com_time . hour , minute = com_time . minute , second = com_time . second , <EOL> microsecond = com_time . microsecond , tzinfo = None ) <EOL> else : <EOL> assert com_time . msec == <NUM_LIT:0> , "<STR_LIT>" <EOL> return datetime_builder ( month = com_time . month , day = com_time . day , year = com_time . year , <EOL> hour = com_time . hour , minute = com_time . minute , second = com_time . second ) <EOL> def _datetime_to_com_time ( dt_time ) : <EOL> """<STR_LIT>""" <EOL> if np : <EOL> if type ( dt_time ) is np . datetime64 : <EOL> dt_time = np_datetime_to_datetime ( dt_time ) <EOL> if type ( dt_time ) is dt . date : <EOL> dt_time = dt . datetime ( dt_time . year , dt_time . month , dt_time . day , <EOL> tzinfo = win32timezone . TimeZoneInfo . utc ( ) ) <EOL> if PY3 : <EOL> if pd and isinstance ( dt_time , pd . tslib . Timestamp ) : <EOL> dt_time = dt_time . to_datetime ( ) <EOL> dt_time = dt_time . replace ( tzinfo = None ) <EOL> dt_time = dt_time . replace ( tzinfo = win32timezone . TimeZoneInfo . utc ( ) ) <EOL> return dt_time <EOL> else : <EOL> assert dt_time . microsecond == <NUM_LIT:0> , "<STR_LIT>" <EOL> return pywintypes . Time ( dt_time . timetuple ( ) ) <EOL> def prepare_xl_data_element ( x ) : <EOL> if isinstance ( x , time_types ) : <EOL> return _datetime_to_com_time ( x ) <EOL> elif np and isinstance ( x , np . generic ) : <EOL> return float ( x ) <EOL> elif x is None : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return x <EOL> def get_selection_address ( xl_app ) : <EOL> return str ( xl_app . Selection . Address ) <EOL> def clear_contents_worksheet ( xl_workbook , sheet_name_or_index ) : <EOL> xl_workbook . Sheets ( sheet_name_or_index ) . Cells . ClearContents ( ) <EOL> def clear_worksheet ( xl_workbook , sheet_name_or_index ) : <EOL> xl_workbook . Sheets ( sheet_name_or_index ) . Cells . Clear ( ) <EOL> def clear_contents_range ( xl_range ) : <EOL> xl_range . ClearContents ( ) <EOL> def clear_range ( xl_range ) : <EOL> xl_range . Clear ( ) <EOL> def get_formula ( xl_range ) : <EOL> return xl_range . Formula <EOL> def set_formula ( xl_range , value ) : <EOL> xl_range . Formula = value <EOL> def get_formula_array ( xl_range ) : <EOL> return xl_range . FormulaArray <EOL> def set_formula_array ( xl_range , value ) : <EOL> xl_range . FormulaArray = value <EOL> def get_row_index_end_down ( xl_sheet , row_index , column_index ) : <EOL> return xl_sheet . Cells ( row_index , column_index ) . End ( Direction . xlDown ) . Row <EOL> def get_column_index_end_right ( xl_sheet , row_index , column_index ) : <EOL> return xl_sheet . Cells ( row_index , column_index ) . End ( Direction . xlToRight ) . Column <EOL> def get_current_region_address ( xl_sheet , row_index , column_index ) : <EOL> return str ( xl_sheet . Cells ( row_index , column_index ) . CurrentRegion . Address ) <EOL> def get_chart_object ( xl_workbook , sheet_name_or_index , chart_name_or_index ) : <EOL> return xl_workbook . Sheets ( sheet_name_or_index ) . ChartObjects ( chart_name_or_index ) <EOL> def get_chart_index ( xl_chart ) : <EOL> return xl_chart . Index <EOL> def get_chart_name ( xl_chart ) : <EOL> return xl_chart . Name <EOL> def add_chart ( xl_workbook , sheet_name_or_index , left , top , width , height ) : <EOL> return xl_workbook . Sheets ( sheet_name_or_index ) . ChartObjects ( ) . Add ( left , top , width , height ) <EOL> def set_chart_name ( xl_chart , name ) : <EOL> xl_chart . Name = name <EOL> def set_source_data_chart ( xl_chart , xl_range ) : <EOL> xl_chart . Chart . SetSourceData ( xl_range ) <EOL> def get_chart_type ( xl_chart ) : <EOL> return xl_chart . Chart . ChartType <EOL> def set_chart_type ( xl_chart , chart_type ) : <EOL> xl_chart . Chart . ChartType = chart_type <EOL> def activate_chart ( xl_chart ) : <EOL> xl_chart . Activate ( ) <EOL> def get_column_width ( xl_range ) : <EOL> return xl_range . ColumnWidth <EOL> def set_column_width ( xl_range , value ) : <EOL> xl_range . ColumnWidth = value <EOL> def get_row_height ( xl_range ) : <EOL> return xl_range . RowHeight <EOL> def set_row_height ( xl_range , value ) : <EOL> xl_range . RowHeight = value <EOL> def get_width ( xl_range ) : <EOL> return xl_range . Width <EOL> def get_height ( xl_range ) : <EOL> return xl_range . Height <EOL> def get_left ( xl_range ) : <EOL> return xl_range . Left <EOL> def get_top ( xl_range ) : <EOL> return xl_range . Top <EOL> def autofit ( range_ , axis ) : <EOL> if axis == '<STR_LIT>' or axis == '<STR_LIT:r>' : <EOL> range_ . xl_range . Rows . AutoFit ( ) <EOL> elif axis == '<STR_LIT>' or axis == '<STR_LIT:c>' : <EOL> range_ . xl_range . Columns . AutoFit ( ) <EOL> elif axis is None : <EOL> range_ . xl_range . Columns . AutoFit ( ) <EOL> range_ . xl_range . Rows . AutoFit ( ) <EOL> def autofit_sheet ( sheet , axis ) : <EOL> if axis == '<STR_LIT>' or axis == '<STR_LIT:r>' : <EOL> sheet . xl_sheet . Rows . AutoFit ( ) <EOL> elif axis == '<STR_LIT>' or axis == '<STR_LIT:c>' : <EOL> sheet . xl_sheet . Columns . AutoFit ( ) <EOL> elif axis is None : <EOL> sheet . xl_sheet . Rows . AutoFit ( ) <EOL> sheet . xl_sheet . Columns . AutoFit ( ) <EOL> xl_workbook_current = None <EOL> def set_xl_workbook_current ( xl_workbook ) : <EOL> global xl_workbook_current <EOL> xl_workbook_current = xl_workbook <EOL> def get_xl_workbook_current ( ) : <EOL> try : <EOL> return xl_workbook_current <EOL> except NameError : <EOL> return None <EOL> def get_number_format ( range_ ) : <EOL> return range_ . xl_range . NumberFormat <EOL> def set_number_format ( range_ , value ) : <EOL> range_ . xl_range . NumberFormat = value <EOL> def get_address ( xl_range , row_absolute , col_absolute , external ) : <EOL> return xl_range . GetAddress ( row_absolute , col_absolute , <NUM_LIT:1> , external ) <EOL> def add_sheet ( xl_workbook , before , after ) : <EOL> if before : <EOL> return xl_workbook . Worksheets . Add ( Before = before . xl_sheet ) <EOL> else : <EOL> count = xl_workbook . Worksheets . Count <EOL> new_sheet_index = after . xl_sheet . Index + <NUM_LIT:1> <EOL> if new_sheet_index > count : <EOL> xl_sheet = xl_workbook . Worksheets . Add ( Before = xl_workbook . Sheets ( after . xl_sheet . Index ) ) <EOL> xl_workbook . Worksheets ( xl_workbook . Worksheets . Count ) . Move ( Before = xl_workbook . Sheets ( xl_workbook . Worksheets . Count - <NUM_LIT:1> ) ) <EOL> xl_workbook . Worksheets ( xl_workbook . Worksheets . Count ) . Activate ( ) <EOL> else : <EOL> xl_sheet = xl_workbook . Worksheets . Add ( Before = xl_workbook . Sheets ( after . xl_sheet . Index + <NUM_LIT:1> ) ) <EOL> return xl_sheet <EOL> def count_worksheets ( xl_workbook ) : <EOL> return xl_workbook . Worksheets . Count <EOL> def get_hyperlink_address ( xl_range ) : <EOL> try : <EOL> return xl_range . Hyperlinks ( <NUM_LIT:1> ) . Address <EOL> except pywintypes . com_error : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def set_hyperlink ( xl_range , address , text_to_display = None , screen_tip = None ) : <EOL> link = xl_range . Hyperlinks . Add ( Anchor = xl_range , Address = address ) <EOL> link . TextToDisplay = text_to_display <EOL> link . ScreenTip = screen_tip <EOL> def set_color ( xl_range , color_or_rgb ) : <EOL> if color_or_rgb is None : <EOL> xl_range . Interior . ColorIndex = ColorIndex . xlColorIndexNone <EOL> elif isinstance ( color_or_rgb , int ) : <EOL> xl_range . Interior . Color = color_or_rgb <EOL> else : <EOL> xl_range . Interior . Color = rgb_to_int ( color_or_rgb ) <EOL> def get_color ( xl_range ) : <EOL> if xl_range . Interior . ColorIndex == ColorIndex . xlColorIndexNone : <EOL> return None <EOL> else : <EOL> return int_to_rgb ( xl_range . Interior . Color ) <EOL> def save_workbook ( xl_workbook , path ) : <EOL> saved_path = xl_workbook . Path <EOL> alerts_state = xl_workbook . Application . DisplayAlerts <EOL> if ( saved_path != '<STR_LIT>' ) and ( path is None ) : <EOL> xl_workbook . Save ( ) <EOL> elif ( saved_path == '<STR_LIT>' ) and ( path is None ) : <EOL> path = os . path . join ( os . getcwd ( ) , xl_workbook . Name + '<STR_LIT>' ) <EOL> xl_workbook . Application . DisplayAlerts = False <EOL> xl_workbook . SaveAs ( path ) <EOL> xl_workbook . Application . DisplayAlerts = alerts_state <EOL> elif path : <EOL> xl_workbook . Application . DisplayAlerts = False <EOL> xl_workbook . SaveAs ( path ) <EOL> xl_workbook . Application . DisplayAlerts = alerts_state <EOL> def open_template ( fullpath ) : <EOL> os . startfile ( fullpath ) <EOL> def set_visible ( xl_app , visible ) : <EOL> xl_app . Visible = visible <EOL> def get_visible ( xl_app ) : <EOL> return xl_app . Visible <EOL> def get_fullname ( xl_workbook ) : <EOL> return xl_workbook . FullName <EOL> def quit_app ( xl_app ) : <EOL> alerts_state = xl_app . DisplayAlerts <EOL> xl_app . DisplayAlerts = False <EOL> xl_app . Quit ( ) <EOL> xl_app . DisplayAlerts = alerts_state <EOL> def get_screen_updating ( xl_app ) : <EOL> return xl_app . ScreenUpdating <EOL> def set_screen_updating ( xl_app , value ) : <EOL> xl_app . ScreenUpdating = value <EOL> def get_calculation ( xl_app ) : <EOL> return xl_app . Calculation <EOL> def set_calculation ( xl_app , value ) : <EOL> xl_app . Calculation = value <EOL> def calculate ( xl_app ) : <EOL> xl_app . Calculate ( ) <EOL> def get_named_range ( range_ ) : <EOL> try : <EOL> name = range_ . xl_range . Name . Name <EOL> except pywintypes . com_error : <EOL> name = None <EOL> return name <EOL> def set_named_range ( range_ , value ) : <EOL> range_ . xl_range . Name = value <EOL> def set_names ( xl_workbook , names ) : <EOL> for i in xl_workbook . Names : <EOL> names [ i . Name ] = i <EOL> def delete_name ( xl_workbook , name ) : <EOL> xl_workbook . Names ( name ) . Delete ( ) <EOL> def get_picture ( picture ) : <EOL> return picture . xl_workbook . Sheets ( picture . sheet_name_or_index ) . Pictures ( picture . name_or_index ) <EOL> def get_picture_index ( picture ) : <EOL> return picture . xl_picture . Index <EOL> def get_picture_name ( xl_picture ) : <EOL> return xl_picture . Name <EOL> def get_shape ( shape ) : <EOL> return shape . xl_workbook . Sheets ( shape . sheet_name_or_index ) . Shapes ( shape . name_or_index ) <EOL> def get_shape_name ( shape ) : <EOL> return shape . xl_shape . Name <EOL> def set_shape_name ( xl_workbook , sheet_name_or_index , xl_shape , value ) : <EOL> xl_workbook . Sheets ( sheet_name_or_index ) . Shapes ( xl_shape . Name ) . Name = value <EOL> return xl_workbook . Sheets ( sheet_name_or_index ) . Shapes ( value ) <EOL> def get_shapes_names ( xl_workbook , sheet ) : <EOL> shapes = xl_workbook . Sheets ( sheet ) . Shapes <EOL> if shapes is not None : <EOL> return [ i . Name for i in shapes ] <EOL> else : <EOL> return [ ] <EOL> def get_shape_left ( shape ) : <EOL> return shape . xl_shape . Left <EOL> def set_shape_left ( shape , value ) : <EOL> shape . xl_shape . Left = value <EOL> def get_shape_top ( shape ) : <EOL> return shape . xl_shape . Top <EOL> def set_shape_top ( shape , value ) : <EOL> shape . xl_shape . Top = value <EOL> def get_shape_width ( shape ) : <EOL> return shape . xl_shape . Width <EOL> def set_shape_width ( shape , value ) : <EOL> shape . xl_shape . Width = value <EOL> def get_shape_height ( shape ) : <EOL> return shape . xl_shape . Height <EOL> def set_shape_height ( shape , value ) : <EOL> shape . xl_shape . Height = value <EOL> def delete_shape ( shape ) : <EOL> shape . xl_shape . Delete ( ) <EOL> def add_picture ( xl_workbook , sheet_name_or_index , filename , link_to_file , save_with_document , left , top , width , height ) : <EOL> return xl_workbook . Sheets ( sheet_name_or_index ) . Shapes . AddPicture ( Filename = filename , <EOL> LinkToFile = link_to_file , <EOL> SaveWithDocument = save_with_document , <EOL> Left = left , <EOL> Top = top , <EOL> Width = width , <EOL> Height = height ) <EOL> def get_app_version_string ( xl_workbook ) : <EOL> return xl_workbook . Application . Version <EOL> def get_major_app_version_number ( xl_workbook ) : <EOL> return int ( get_app_version_string ( xl_workbook ) . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) <EOL> def delete_sheet ( sheet ) : <EOL> alerts_state = sheet . xl_workbook . Application . DisplayAlerts <EOL> sheet . xl_workbook . Application . DisplayAlerts = False <EOL> sheet . xl_workbook . Sheets ( sheet . name ) . Delete ( ) <EOL> sheet . xl_workbook . Application . DisplayAlerts = alerts_state <EOL> def run ( wb , command , app_ , args ) : <EOL> return app_ . xl_app . Run ( "<STR_LIT>" . format ( wb . name , command ) , * args ) </s>
