<s> from . import BIFFRecords <EOL> from . import Style <EOL> from . Cell import StrCell , BlankCell , NumberCell , FormulaCell , MulBlankCell , BooleanCell , ErrorCell , _get_cells_biff_data_mul <EOL> from . import ExcelFormula <EOL> import datetime as dt <EOL> try : <EOL> from decimal import Decimal <EOL> except ImportError : <EOL> class Decimal ( object ) : <EOL> pass <EOL> class Row ( object ) : <EOL> __slots__ = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> def __init__ ( self , rowx , parent_sheet ) : <EOL> if not ( isinstance ( rowx , int ) and <NUM_LIT:0> <= rowx <= <NUM_LIT> ) : <EOL> raise ValueError ( "<STR_LIT>" % rowx ) <EOL> self . __idx = rowx <EOL> self . __parent = parent_sheet <EOL> self . __parent_wb = parent_sheet . get_parent ( ) <EOL> self . __cells = { } <EOL> self . __min_col_idx = <NUM_LIT:0> <EOL> self . __max_col_idx = <NUM_LIT:0> <EOL> self . __xf_index = <NUM_LIT> <EOL> self . __has_default_xf_index = <NUM_LIT:0> <EOL> self . __height_in_pixels = <NUM_LIT> <EOL> self . height = <NUM_LIT> <EOL> self . has_default_height = <NUM_LIT> <EOL> self . height_mismatch = <NUM_LIT:0> <EOL> self . level = <NUM_LIT:0> <EOL> self . collapse = <NUM_LIT:0> <EOL> self . hidden = <NUM_LIT:0> <EOL> self . space_above = <NUM_LIT:0> <EOL> self . space_below = <NUM_LIT:0> <EOL> def __adjust_height ( self , style ) : <EOL> twips = style . font . height <EOL> points = float ( twips ) / <NUM_LIT> <EOL> pix = int ( round ( points * <NUM_LIT> / <NUM_LIT> + <NUM_LIT> / <NUM_LIT> ) ) <EOL> if pix > self . __height_in_pixels : <EOL> self . __height_in_pixels = pix <EOL> def __adjust_bound_col_idx ( self , * args ) : <EOL> for arg in args : <EOL> iarg = int ( arg ) <EOL> if not ( ( <NUM_LIT:0> <= iarg <= <NUM_LIT:255> ) and arg == iarg ) : <EOL> raise ValueError ( "<STR_LIT>" % arg ) <EOL> sheet = self . __parent <EOL> if iarg < self . __min_col_idx : <EOL> self . __min_col_idx = iarg <EOL> if iarg > self . __max_col_idx : <EOL> self . __max_col_idx = iarg <EOL> if iarg < sheet . first_used_col : <EOL> sheet . first_used_col = iarg <EOL> if iarg > sheet . last_used_col : <EOL> sheet . last_used_col = iarg <EOL> def __excel_date_dt ( self , date ) : <EOL> if isinstance ( date , dt . date ) and ( not isinstance ( date , dt . datetime ) ) : <EOL> epoch = dt . date ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> elif isinstance ( date , dt . time ) : <EOL> date = dt . datetime . combine ( dt . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , date ) <EOL> epoch = dt . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> else : <EOL> epoch = dt . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> delta = date - epoch <EOL> xldate = delta . days + float ( delta . seconds ) / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) <EOL> if xldate > <NUM_LIT> : <EOL> xldate += <NUM_LIT:1> <EOL> return xldate <EOL> def get_height_in_pixels ( self ) : <EOL> return self . __height_in_pixels <EOL> def set_style ( self , style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __xf_index = self . __parent_wb . add_style ( style ) <EOL> self . __has_default_xf_index = <NUM_LIT:1> <EOL> def get_xf_index ( self ) : <EOL> return self . __xf_index <EOL> def get_cells_count ( self ) : <EOL> return len ( self . __cells ) <EOL> def get_min_col ( self ) : <EOL> return self . __min_col_idx <EOL> def get_max_col ( self ) : <EOL> return self . __max_col_idx <EOL> def get_row_biff_data ( self ) : <EOL> height_options = ( self . height & <NUM_LIT> ) <EOL> height_options |= ( self . has_default_height & <NUM_LIT> ) << <NUM_LIT:15> <EOL> options = ( self . level & <NUM_LIT> ) << <NUM_LIT:0> <EOL> options |= ( self . collapse & <NUM_LIT> ) << <NUM_LIT:4> <EOL> options |= ( self . hidden & <NUM_LIT> ) << <NUM_LIT:5> <EOL> options |= ( self . height_mismatch & <NUM_LIT> ) << <NUM_LIT:6> <EOL> options |= ( self . __has_default_xf_index & <NUM_LIT> ) << <NUM_LIT:7> <EOL> options |= ( <NUM_LIT> & <NUM_LIT> ) << <NUM_LIT:8> <EOL> options |= ( self . __xf_index & <NUM_LIT> ) << <NUM_LIT:16> <EOL> options |= ( self . space_above & <NUM_LIT:1> ) << <NUM_LIT> <EOL> options |= ( self . space_below & <NUM_LIT:1> ) << <NUM_LIT> <EOL> return BIFFRecords . RowRecord ( self . __idx , self . __min_col_idx , <EOL> self . __max_col_idx , height_options , options ) . get ( ) <EOL> def insert_cell ( self , col_index , cell_obj ) : <EOL> if col_index in self . __cells : <EOL> if not self . __parent . _cell_overwrite_ok : <EOL> msg = "<STR_LIT>" % ( self . __parent . name , self . __idx , col_index ) <EOL> raise Exception ( msg ) <EOL> prev_cell_obj = self . __cells [ col_index ] <EOL> sst_idx = getattr ( prev_cell_obj , '<STR_LIT>' , None ) <EOL> if sst_idx is not None : <EOL> self . __parent_wb . del_str ( sst_idx ) <EOL> self . __cells [ col_index ] = cell_obj <EOL> def insert_mulcells ( self , colx1 , colx2 , cell_obj ) : <EOL> self . insert_cell ( colx1 , cell_obj ) <EOL> for col_index in range ( colx1 + <NUM_LIT:1> , colx2 + <NUM_LIT:1> ) : <EOL> self . insert_cell ( col_index , None ) <EOL> def get_cells_biff_data ( self ) : <EOL> cell_items = [ item for item in self . __cells . items ( ) if item [ <NUM_LIT:1> ] is not None ] <EOL> cell_items . sort ( ) <EOL> return _get_cells_biff_data_mul ( self . __idx , cell_items ) <EOL> def get_index ( self ) : <EOL> return self . __idx <EOL> def set_cell_text ( self , colx , value , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , StrCell ( self . __idx , colx , xf_index , self . __parent_wb . add_str ( value ) ) ) <EOL> def set_cell_blank ( self , colx , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , BlankCell ( self . __idx , colx , xf_index ) ) <EOL> def set_cell_mulblanks ( self , first_colx , last_colx , style = Style . default_style ) : <EOL> assert <NUM_LIT:0> <= first_colx <= last_colx <= <NUM_LIT:255> <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( first_colx , last_colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_mulcells ( first_colx , last_colx , MulBlankCell ( self . __idx , first_colx , last_colx , xf_index ) ) <EOL> def set_cell_number ( self , colx , number , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , NumberCell ( self . __idx , colx , xf_index , number ) ) <EOL> def set_cell_date ( self , colx , datetime_obj , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , <EOL> NumberCell ( self . __idx , colx , xf_index , self . __excel_date_dt ( datetime_obj ) ) ) <EOL> def set_cell_formula ( self , colx , formula , style = Style . default_style , calc_flags = <NUM_LIT:0> ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . __parent_wb . add_sheet_reference ( formula ) <EOL> self . insert_cell ( colx , FormulaCell ( self . __idx , colx , xf_index , formula , calc_flags = <NUM_LIT:0> ) ) <EOL> def set_cell_boolean ( self , colx , value , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , BooleanCell ( self . __idx , colx , xf_index , bool ( value ) ) ) <EOL> def set_cell_error ( self , colx , error_string_or_code , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( colx ) <EOL> xf_index = self . __parent_wb . add_style ( style ) <EOL> self . insert_cell ( colx , ErrorCell ( self . __idx , colx , xf_index , error_string_or_code ) ) <EOL> def write ( self , col , label , style = Style . default_style ) : <EOL> self . __adjust_height ( style ) <EOL> self . __adjust_bound_col_idx ( col ) <EOL> style_index = self . __parent_wb . add_style ( style ) <EOL> if isinstance ( label , str ) : <EOL> if len ( label ) > <NUM_LIT:0> : <EOL> self . insert_cell ( col , <EOL> StrCell ( self . __idx , col , style_index , self . __parent_wb . add_str ( label ) ) <EOL> ) <EOL> else : <EOL> self . insert_cell ( col , BlankCell ( self . __idx , col , style_index ) ) <EOL> elif isinstance ( label , bool ) : <EOL> self . insert_cell ( col , BooleanCell ( self . __idx , col , style_index , label ) ) <EOL> elif isinstance ( label , ( float , int , Decimal ) ) : <EOL> self . insert_cell ( col , NumberCell ( self . __idx , col , style_index , label ) ) <EOL> elif isinstance ( label , ( dt . datetime , dt . date , dt . time ) ) : <EOL> date_number = self . __excel_date_dt ( label ) <EOL> self . insert_cell ( col , NumberCell ( self . __idx , col , style_index , date_number ) ) <EOL> elif label is None : <EOL> self . insert_cell ( col , BlankCell ( self . __idx , col , style_index ) ) <EOL> elif isinstance ( label , ExcelFormula . Formula ) : <EOL> self . __parent_wb . add_sheet_reference ( label ) <EOL> self . insert_cell ( col , FormulaCell ( self . __idx , col , style_index , label ) ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % type ( label ) ) <EOL> write_blanks = set_cell_mulblanks </s>
