@@ -297,13 +297,13 @@ def __init__(self, text, fontsize, top, left, width, height):
297297 self .fontsize = _positive_integer (fontsize )
298298
299299 def dump (self , sheet , data_sheet , row ):
300- data_cells = data_sheet .Cells
300+ data_cells = data_sheet .cells
301301 # add title in data sheet
302- data_cells (row , 1 ).Value = self .text
302+ data_cells (row , 1 ).value = self .text
303303 # generate title banner in destination sheet
304304 msoShapeRectangle = 1
305305 msoThemeColorBackground1 = 14
306- sheet_shapes = sheet .Shapes
306+ sheet_shapes = sheet .shapes . api
307307 shp = sheet_shapes .AddShape (Type = msoShapeRectangle , Left = self .left , Top = self .top ,
308308 Width = self .width , Height = self .height )
309309 fill = shp .Fill
@@ -323,7 +323,6 @@ def dump(self, sheet, data_sheet, row):
323323 # update and return current row position
324324 return row + 2
325325
326- # TODO: fix problem with nans values
327326 class ExcelGraphItem (AbstractExcelItem ):
328327
329328 _default_size = ItemSize (427 , 230 )
@@ -341,23 +340,26 @@ def __init__(self, title, data, template, top, left, width, height):
341340 self .template = template
342341
343342 def dump (self , sheet , data_sheet , row ):
344- data_range = data_sheet .Range
345- data_cells = data_sheet .Cells
343+ data_range = data_sheet .range
344+ data_cells = data_sheet .cells
346345 # write graph title in data sheet
347- data_cells (row , 1 ).Value = self .title
346+ data_cells (row , 1 ).value = self .title
348347 row += 1
349348 # dump data to make the graph in data sheet
350349 data = self .data
351350 nb_series = 1 if data .ndim == 1 else data .shape [0 ]
352351 nb_xticks = data .size if data .ndim == 1 else data .shape [1 ]
353352 last_row , last_col = row + nb_series , nb_xticks + 1
354- data_range (data_cells (row , 1 ), data_cells (last_row , last_col )).Value = data .dump ()
355- data_cells (row , 1 ).Value = ''
353+ data_range (data_cells (row , 1 ), data_cells (last_row , last_col )).value = data .dump ()
354+ data_cells (row , 1 ).value = ''
356355 # generate graph in destination sheet
357- sheet_charts = sheet .ChartObjects ()
356+ source = data_range (data_cells (row , 1 ), data_cells (last_row , last_col ))
357+ # Note: from here on, we use pure win32com objects instead of
358+ # larray.excel or xlwings objects as this is faster
359+ source = source .api
360+ sheet_charts = sheet .api .ChartObjects ()
358361 obj = sheet_charts .Add (self .left , self .top , self .width , self .height )
359362 obj_chart = obj .Chart
360- source = data_range (data_cells (row , 1 ), data_cells (last_row , last_col ))
361363 obj_chart .SetSourceData (source )
362364 obj_chart .ChartType = ChartType .xlLine
363365 obj_chart .HasTitle = True
@@ -466,23 +468,23 @@ def add_graph(self, title, data, template=None, width=None, height=None):
466468
467469 def to_excel (self , filepath , data_sheet_name = '__data__' , overwrite = True ):
468470 with open_excel (filepath , overwrite_file = overwrite ) as wb :
469- # from here on, we use pure win32com objects instead of
470- # larray.excel or xlwings objects as this is faster
471- xl_wb = wb . api
471+ app = wb . app . api
472+ # it's a > x7 speed up difference
473+ app . ScreenUpdating = False
472474
473475 # use first sheet as data sheet
474- data_sheet = xl_wb . Worksheets ( 1 )
475- data_sheet .Name = data_sheet_name
476- data_cells = data_sheet .Cells
476+ data_sheet = wb . sheets [ 0 ]
477+ data_sheet .name = data_sheet_name
478+ data_cells = data_sheet .cells
477479
478480 # dump items
479481 row = 1
480482 for dest_sheet_name , items in self .items .items ():
481483 # add new destination sheet
482- dest_sheet = xl_wb . Worksheets . Add ( After = xl_wb . Sheets ( xl_wb . Sheets . Count ) )
483- dest_sheet .Name = dest_sheet_name
484+ dest_sheet = wb . sheets . add ( dest_sheet_name , after = wb [ - 1 ]. xw_sheet )
485+ dest_sheet .name = dest_sheet_name
484486 # write destination sheet name in data sheet
485- data_cells (row , 1 ).Value = dest_sheet_name
487+ data_cells (row , 1 ).value = dest_sheet_name
486488 row += 2
487489 # dump items of current destination sheet
488490 for item in items :
0 commit comments