LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
pyleeno.py
Vai alla documentazione di questo file.
1 #!/usr/bin/env python3
2 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3 
13 
14 # MsgBox('''Per segnalare questo problema,
15 # contatta il canale Telegram
16 # https://t.me/leeno_computometrico''', 'ERRORE!')
17 
18 # documentazione ufficiale: https://api.libreoffice.org/
19 # import pydevd
20 
21  # funzioni per misurare la velocità delle macro
22  # ~datarif = datetime.now()
23  # ~DLG.chi('eseguita in ' + str((datetime.now() - datarif).total_seconds()) + ' secondi!')
24 
25 
26 from datetime import datetime, date
27 from xml.etree.ElementTree import Element, SubElement, tostring
28 
29 # import distutils.dir_util
30 
31 import codecs
32 import subprocess
33 # import psutil
34 import re
35 import traceback
36 import threading
37 import time
38 
39 import os
40 import shutil
41 import sys
42 import uno
43 
44 import SheetUtils
45 import LeenoUtils
46 import LeenoSheetUtils
47 import LeenoToolbars as Toolbars
48 import LeenoFormat
49 import LeenoComputo
50 import LeenoContab
51 import LeenoAnalysis
52 import LeenoDialogs as DLG
53 import PersistUtils as PU
54 import LeenoEvents
55 import LeenoBasicBridge
56 
57 import LeenoConfig
59 
60 import Dialogs
61 
62 # cos'e' il namespace:
63 # http://www.html.it/articoli/il-misterioso-mondo-dei-namespaces-1/
64 
65 # from com.sun.star.lang import Locale
66 from com.sun.star.beans import PropertyValue
67 # from com.sun.star.table.CellContentType import TEXT, EMPTY, VALUE, FORMULA
68 from com.sun.star.sheet.CellFlags import \
69  VALUE, DATETIME, STRING, ANNOTATION, FORMULA, HARDATTR, OBJECTS, EDITATTR, FORMATTED
70 
71 from com.sun.star.beans.PropertyAttribute import \
72  MAYBEVOID, REMOVEABLE, MAYBEDEFAULT
73 
74 
76 
77 
80 
81 def basic_LeenO(funcname, *args):
82  '''Richiama funzioni definite in Basic'''
83 
84  xCompCont = LeenoUtils.getComponentContext()
85  sm = xCompCont.ServiceManager
86  mspf = sm.createInstance("com.sun.star.script.provider.MasterScriptProviderFactory")
87  scriptPro = mspf.createScriptProvider("")
88  Xscript = scriptPro.getScript(
89  "vnd.sun.star.script:UltimusFree2." +
90  funcname +
91  "?language=Basic&location=application")
92  Result = Xscript.invoke(args, None, None)
93  return Result[0]
94 
95 
96 # leeno.conf
98  '''
99  Visualizza il menù di configurazione
100  '''
101  oDoc = LeenoUtils.getDocument()
102  if not oDoc.getSheets().hasByName('S1'):
103  Toolbars.AllOff()
104  return
106  dp = psm.createInstance("com.sun.star.awt.DialogProvider")
107  oDlg_config = dp.createDialog(
108  "vnd.sun.star.script:UltimusFree2.Dlg_config?language=Basic&location=application"
109  )
110  # oDialog1Model = oDlg_config.Model
111 
112  oSheets = list(oDoc.getSheets().getElementNames())
113  # ~for nome in ('M1', 'S1', 'S2', 'S4', 'S5', 'Elenco Prezzi', 'COMPUTO'):
114  for nome in ('M1', 'S1', 'S2', 'S5', 'Elenco Prezzi', 'COMPUTO'):
115  oSheets.remove(nome)
116  for nome in oSheets:
117  oSheet = oDoc.getSheets().getByName(nome)
118  if not oSheet.IsVisible:
119  oDlg_config.getControl('CheckBox2').State = 0
120  test = 0
121  break
122  oDlg_config.getControl('CheckBox2').State = 1
123  test = 1
124  if oDoc.getSheets().getByName("copyright_LeenO").IsVisible:
125  oDlg_config.getControl('CheckBox2').State = 1
126  if cfg.read('Generale', 'pesca_auto') == '1':
127  oDlg_config.getControl('CheckBox1').State = 1 # pesca codice automatico
128  if cfg.read('Generale', 'toolbar_contestuali') == '1':
129  oDlg_config.getControl('CheckBox6').State = 1
130 
131  oSheet = oDoc.getSheets().getByName('S5')
132  # descrizione_in_una_colonna
133  if not oSheet.getCellRangeByName('C9').IsMerged:
134  oDlg_config.getControl('CheckBox5').State = 1
135  else:
136  oDlg_config.getControl('CheckBox5').State = 0
137 
138  # if conf.read(path_conf, 'Generale', 'descrizione_in_una_colonna') == '1': oDlg_config.getControl('CheckBox5').State = 1
139 
140  sString = oDlg_config.getControl('TextField1')
141  sString.Text = cfg.read('Generale', 'altezza_celle')
142 
143  # sString = oDlg_config.getControl("ComboBox1")
144  # sString.Text = conf.read(path_conf, 'Generale', 'visualizza') #visualizza all'avvio
145 
146  sString = oDlg_config.getControl("ComboBox2") # spostamento ad INVIO
147  if cfg.read('Generale', 'movedirection') == '1':
148  sString.Text = 'A DESTRA'
149  elif cfg.read('Generale', 'movedirection') == '0':
150  sString.Text = 'IN BASSO'
151  oSheet = oDoc.getSheets().getByName('S1')
152 
153  # fullscreen
154  oLayout = oDoc.CurrentController.getFrame().LayoutManager
155  if not oLayout.isElementVisible('private:resource/toolbar/standardbar'):
156  oDlg_config.getControl('CheckBox3').State = 1
157 
158  sString = oDlg_config.getControl('TextField14')
159  sString.Text = oSheet.getCellRangeByName(
160  'S1.H334').String # vedi_voce_breve
161  sString = oDlg_config.getControl('TextField4')
162  sString.Text = oSheet.getCellRangeByName(
163  'S1.H335').String # cont_inizio_voci_abbreviate
164  if oDoc.NamedRanges.hasByName("_Lib_1"):
165  sString.setEnable(False)
166  sString = oDlg_config.getControl('TextField12')
167  sString.Text = oSheet.getCellRangeByName(
168  'S1.H336').String # cont_fine_voci_abbreviate
169  if oDoc.NamedRanges.hasByName("_Lib_1"):
170  sString.setEnable(False)
171 
172  if cfg.read('Generale', 'torna_a_ep') == '1':
173  oDlg_config.getControl('CheckBox8').State = 1
174 
175  sString = oDlg_config.getControl('ComboBox4')
176  sString.Text = cfg.read('Generale', 'copie_backup')
177  if int(cfg.read('Generale', 'copie_backup')) != 0:
178  sString = oDlg_config.getControl('ComboBox5')
179  sString.Text = cfg.read('Generale', 'pausa_backup')
180  # ~else:
181  # ~oDlg_config.getControl('ComboBox5').setEnable(False)
182  # ~oDlg_config.execute()
183  # ~DLG.chi(oDlg_config.getControl('ComboBox5'))
184 
185 
186  # MOSTRA IL DIALOGO
187  oDlg_config.execute()
188 
189  if oDlg_config.getControl('CheckBox2').State != test:
190  if oDlg_config.getControl('CheckBox2').State == 1:
191  show_sheets(True)
192  else:
193  show_sheets(False)
194 
195  if oDlg_config.getControl('CheckBox3').State == 1:
196  Toolbars.Switch(False)
197  else:
198  Toolbars.Switch(True)
199 
200  # conf.write(path_conf, 'Generale', 'visualizza', oDlg_config.getControl('ComboBox1').getText())
201 
203  oGSheetSettings = ctx.ServiceManager.createInstanceWithContext("com.sun.star.sheet.GlobalSheetSettings", ctx)
204  if oDlg_config.getControl('ComboBox2').getText() == 'IN BASSO':
205  cfg.write('Generale', 'movedirection', '0')
206  oGSheetSettings.MoveDirection = 0
207  else:
208  cfg.write('Generale', 'movedirection', '1')
209  oGSheetSettings.MoveDirection = 1
210  cfg.write('Generale', 'altezza_celle', oDlg_config.getControl('TextField1').getText())
211 
212  cfg.write('Generale', 'pesca_auto', str(oDlg_config.getControl('CheckBox1').State))
213  cfg.write('Generale', 'descrizione_in_una_colonna', str(oDlg_config.getControl('CheckBox5').State))
214  cfg.write('Generale', 'toolbar_contestuali', str(oDlg_config.getControl('CheckBox6').State))
215  Toolbars.Vedi()
216  if oDlg_config.getControl('CheckBox5').State == 1:
218  else:
220  # torna su prezzario
221  cfg.write('Generale', 'torna_a_ep', str(oDlg_config.getControl('CheckBox8').State))
222 
223  # il salvataggio anche su leeno.conf serve alla funzione voce_breve()
224 
225  if oDlg_config.getControl('TextField14').getText() != '10000':
226  cfg.write('Generale', 'vedi_voce_breve', oDlg_config.getControl('TextField14').getText())
227  oSheet.getCellRangeByName('S1.H334').Value = float(oDlg_config.getControl('TextField14').getText())
228 
229  if oDlg_config.getControl('TextField4').getText() != '10000':
230  cfg.write('Contabilita', 'cont_inizio_voci_abbreviate', oDlg_config.getControl('TextField4').getText())
231  oSheet.getCellRangeByName('S1.H335').Value = float(oDlg_config.getControl('TextField4').getText())
232 
233  if oDlg_config.getControl('TextField12').getText() != '10000':
234  cfg.write('Contabilita', 'cont_fine_voci_abbreviate', oDlg_config.getControl('TextField12').getText())
235  oSheet.getCellRangeByName('S1.H336').Value = float(oDlg_config.getControl('TextField12').getText())
237 
238  cfg.write('Generale', 'copie_backup', oDlg_config.getControl('ComboBox4').getText())
239  cfg.write('Generale', 'pausa_backup', oDlg_config.getControl('ComboBox5').getText())
240  autorun()
241 
242 
243 
244 
246  '''Restituisce il percorso di installazione di LeenO.oxt'''
248  pir = ctx.getValueByName(
249  '/singletons/com.sun.star.deployment.PackageInformationProvider')
250  expath = pir.getPackageLocation('org.giuseppe-vizziello.leeno')
251  return expath
252 
253 
254 
255 
256 def creaComputo(arg=1):
257  '''arg { integer } : 1 mostra il dialogo di salvataggio file'''
258  desktop = LeenoUtils.getDesktop()
259  opz = PropertyValue()
260  opz.Name = 'AsTemplate'
261  opz.Value = True
262  document = desktop.loadComponentFromURL(
263  LeenO_path() + '/template/leeno/Computo_LeenO.ots', "_blank", 0,
264  (opz, ))
265  autoexec()
266  if arg == 1:
267  Dialogs.Exclamation(Title = 'ATTENZIONE!',
268  Text='''
269 Prima di procedere è meglio dare un nome al file.
270 Lavorando su un file senza nome potresti avere dei malfunzionamenti.
271 ''')
272  # ~DLG.MsgBox(
273  # ~"Prima di procedere è consigliabile salvare il lavoro.\n"
274  # ~"Provvedi subito a dare un nome al file di computo...",
275  # ~"Dai un nome al file...")
276  salva_come()
277  DlgMain()
278  return document
279 
280 
282  desktop = LeenoUtils.getDesktop()
283  opz = PropertyValue()
284  opz.Name = 'AsTemplate'
285  opz.Value = True
286  document = desktop.loadComponentFromURL(
287  LeenO_path() + '/template/offmisc/UsoBollo.ott', "_blank", 0,
288  (opz, ))
289  return document
290 
291 
292 
293 
294 
296  '''Crea un nuovo computo vuoto.'''
297  creaComputo()
298 
299 
300 
301 
302 
304  '''Crea un nuovo documento in formato uso bollo.'''
305  creaUsobollo()
306 
307 
308 
309 
311  '''
312  Invia le voci di Elenco Prezzi verso uno degli altri elaborati.
313  Richiede comunque la scelta del DP
314  '''
316  oDoc = LeenoUtils.getDocument()
317  oSheet = oDoc.CurrentController.ActiveSheet
318 
319  elenco = seleziona()
320  codici = []
321  for el in elenco:
322  cod = oSheet.getCellByPosition(0, el).String
323  codici.append(cod)
324  dest = oSheet.getCellRangeByName('C2').String
325 
326  if dest == 'VARIANTE':
328  elif dest == 'CONTABILITA':
330  # ~ins_voce_contab()
331  elif dest == 'COMPUTO':
332  GotoSheet(dest)
333  else:
334  Dialogs.Exclamation(Title='AVVISO!',
335  Text='''Per procedere devi prima scegliere,
336 dalla cella "C2", l'elaborato a cui
337 inviare le voci di prezzo selezionate.
338 
339 Se l'elaborato è già esistente,
340 assicurati di aver scelto anche
341 la posizione di destinazione.''')
342  _gotoCella(2, 1)
343  return
344  oSheet = oDoc.getSheets().getByName(dest)
345  for el in codici:
346  if oSheet.Name == 'CONTABILITA':
347  GotoSheet(dest)
348  ins_voce_contab(cod=el)
349  else:
351  lrow = SheetUtils.getLastUsedRow(oSheet)
353  return
354 
356  '''
357  Invia le voci di computo, elenco prezzi e analisi, con costi elementari,
358  dal documento corrente al Documento Principale.
359  '''
360  oDoc = LeenoUtils.getDocument()
361  oSheet = oDoc.CurrentController.ActiveSheet
362  stili_computo = LeenoUtils.getGlobalVar('stili_computo')
363  stili_cat = LeenoUtils.getGlobalVar('stili_cat')
364 
365  nSheet = oSheet.Name
366  fpartenza = uno.fileUrlToSystemPath(oDoc.getURL())
367  if fpartenza == LeenoUtils.getGlobalVar('sUltimus'):
368  if nSheet == 'Elenco Prezzi':
370  return
371  else:
372  Dialogs.Exclamation(Title='ATTENZIONE!',
373  Text="Questo file coincide con il Documento Principale (DP).")
374  return
375  elif LeenoUtils.getGlobalVar('sUltimus') == '':
376  Dialogs.Exclamation(Title='ATTENZIONE!',
377  Text="E' necessario impostare il Documento Principale (DP).")
378  return
379  nSheetDCC = getDCCSheet()
380  lrow = LeggiPosizioneCorrente()[1]
381 
382  def getAnalisi(oSheet):
383  try:
384  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
385  except AttributeError:
386  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
387  el_y = list()
388  try:
389  len(oRangeAddress)
390  for el in oRangeAddress:
391  el_y.append((el.StartRow, el.EndRow))
392  except TypeError:
393  el_y.append((oRangeAddress.StartRow, oRangeAddress.EndRow))
394  lista = list()
395  for y in el_y:
396  for el in range(y[0], y[1] + 1):
397  lista.append(el)
398  analisi = list()
399  for y in lista:
400  if oSheet.getCellByPosition(1, y).Type.value == 'FORMULA':
401  analisi.append(oSheet.getCellByPosition(0, y).String)
402  return (analisi, lista)
403 
404  def Circoscrive_Analisi(lrow):
405  # oDoc = LeenoUtils.getDocument()
406  # oSheet = oDoc.CurrentController.ActiveSheet
407  stili_analisi = LeenoUtils.getGlobalVar('stili_analisi')
408  if oSheet.getCellByPosition(0, lrow).CellStyle in stili_analisi:
409  for el in reversed(range(0, lrow)):
410  if oSheet.getCellByPosition(0,
411  el).CellStyle == 'Analisi_Sfondo':
412  SR = el
413  break
414  for el in range(lrow, SheetUtils.getUsedArea(oSheet).EndRow):
415  if oSheet.getCellByPosition(
416  0, el).CellStyle == 'An-sfondo-basso Att End':
417  ER = el
418  break
419  celle = oSheet.getCellRangeByPosition(0, SR, 250, ER)
420  return celle
421 
422  # partenza
423  if oSheet.Name == 'Elenco Prezzi':
424  if oSheet.getCellByPosition(
425  0,
426  LeggiPosizioneCorrente()[1]).CellStyle not in ('EP-Cs', 'EP-aS'):
427  Dialogs.Exclamation(Title = 'ATTENZIONE!',
428  Text='La posizione di PARTENZA non è corretta.')
429  # ~DLG.MsgBox('La posizione di PARTENZA non è corretta.', 'ATTENZIONE!')
430  return
431  analisi = getAnalisi(oSheet)[0]
432  lrow = getAnalisi(oSheet)[1][0]
433  LeenoUtils.setGlobalVar('cod', oSheet.getCellByPosition(0, lrow).String)
434  lista = getAnalisi(oSheet)[1]
435 
436  selezione = list()
437  voci = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
438  for y in lista:
439  rangen = oSheet.getCellRangeByPosition(0, y, 100, y).RangeAddress
440  selezione.append(rangen)
441  voci.addRangeAddresses(selezione, True)
442 
443  coppia = list()
444 
445  if analisi:
446  GotoSheet('Analisi di Prezzo')
447  oSheet = oDoc.getSheets().getByName('Analisi di Prezzo')
448 
449  ranges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
450  selezione_analisi = list()
451  for el in analisi:
452  y = SheetUtils.uFindStringCol(el, 0, oSheet)
453  sStRange = Circoscrive_Analisi(y)
454  SR = sStRange.RangeAddress.StartRow
455  ER = sStRange.RangeAddress.EndRow
456  coppia.append((SR, ER))
457  selezione_analisi.append(sStRange.RangeAddress)
458  costi = list()
459  for el in coppia:
460  for y in range(el[0], el[1]):
461  if oSheet.getCellByPosition(0, y).CellStyle == 'An-lavoraz-Cod-sx' and \
462  oSheet.getCellByPosition(0, y).Type.value != 'EMPTY':
463  costi.append(oSheet.getCellByPosition(0, y).String)
464  if len(costi) > 0:
465  GotoSheet('Elenco Prezzi')
466  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
467  el_y = list()
468  for el in costi:
469  el_y.append(SheetUtils.uFindStringCol(el, 0, oSheet))
470  for y in el_y:
471  rangen = oSheet.getCellRangeByPosition(0, y, 100,
472  y).RangeAddress
473  selezione.append(rangen)
474  voci.addRangeAddresses(selezione, True)
475  oDoc.CurrentController.select(voci)
476  comando('Copy')
477  oDoc.CurrentController.select(
478  oDoc.createInstance(
479  "com.sun.star.sheet.SheetCellRanges")) # unselect
480  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
481  ddcDoc = LeenoUtils.getDocument()
482  dccSheet = ddcDoc.CurrentController.ActiveSheet
483  nome = dccSheet.Name
484 
485  if nome in ('Elenco Prezzi'):
486  ddcDoc.CurrentController.setActiveSheet(dccSheet)
487  _gotoCella(0, 3)
488  paste_clip(insCells=1)
489  # EliminaVociDoppieElencoPrezzi()
490  if nome in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
491  dccSheet = ddcDoc.getSheets().getByName('Elenco Prezzi')
492  dccSheet.IsVisible = True
493  ddcDoc.CurrentController.setActiveSheet(dccSheet)
494  _gotoCella(0, 3)
495  paste_clip(insCells=1)
496  # EliminaVociDoppieElencoPrezzi()
497  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
498  ddcDoc = LeenoUtils.getDocument()
499  GotoSheet(nome)
500  dccSheet = ddcDoc.getSheets().getByName(nome)
501  lrow = LeggiPosizioneCorrente()[1]
502 
503  # ~if dccSheet.getCellByPosition(0, lrow).CellStyle in stili_cat:
504  # ~DLG.chi(dccSheet.getCellByPosition(0, lrow).CellStyle)
505  # ~lrow += 1
506 
507  if dccSheet.getCellByPosition(0, lrow).CellStyle in ('comp Int_colonna'):
508  LeenoComputo.insertVoceComputoGrezza(dccSheet, lrow + 1)
509  # @@ PROVVISORIO !!!
510  _gotoCella(1, lrow + 2)
511  numera_voci(1)
512  lrow = LeggiPosizioneCorrente()[1]
513  if dccSheet.getCellByPosition(
514  0, lrow).CellStyle in (stili_cat + stili_computo + ('comp Int_colonna', )):
515  if codice_voce(lrow) in ('', 'Cod. Art.?'):
517  else:
519  GotoSheet(nome)
521  if LeggiPosizioneCorrente()[1] > 20:
522  ddcDoc.CurrentController.setFirstVisibleColumn(0)
523  ddcDoc.CurrentController.setFirstVisibleRow(LeggiPosizioneCorrente()[1] - 5)
524  else:
525  return
526  # partenza
527  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
529  try:
530  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
531  except AttributeError:
532  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
533  try:
534  SR = oRangeAddress.StartRow
535  SR = LeenoComputo.circoscriveVoceComputo(oSheet, SR).RangeAddress.StartRow
536  except AttributeError:
537  Dialogs.Exclamation(Title = 'ATTENZIONE!',
538  Text='''La selezione delle voci dal COMPUTO
539 di partenza deve essere contigua.''')
540  # ~DLG.MsgBox(
541  # ~'La selezione delle voci dal COMPUTO di partenza\ndeve essere contigua.',
542  # ~'ATTENZIONE!')
543  return
544  ER = oRangeAddress.EndRow
545  ER = LeenoComputo.circoscriveVoceComputo(oSheet, ER).RangeAddress.EndRow
546  oDoc.CurrentController.select(oSheet.getCellRangeByPosition(0, SR, 100, ER))
547 
548  oSheet.getCellRangeByPosition(45, SR, 45, ER).CellBackColor = 15757935
549 
550  lista = list()
551  for el in range(SR, ER + 1):
552  if oSheet.getCellByPosition(0, el).CellStyle in ('Comp Start Attributo'):
553  lista.append(codice_voce(el))
554  # seleziona()
555  if nSheetDCC in ('Analisi di Prezzo'):
556  # ~DLG.MsgBox('Il foglio di destinazione non è corretto.', 'ATTENZIONE!')
557  Dialogs.Exclamation(Title = 'ATTENZIONE!',
558  Text='Il foglio di destinazione non è corretto.')
559  oDoc.CurrentController.select(
560  oDoc.createInstance(
561  "com.sun.star.sheet.SheetCellRanges")) # unselect
562  return
563  if nSheetDCC in ('COMPUTO', 'VARIANTE'):
564  comando('Copy')
565  # arrivo
566  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
567  ddcDoc = LeenoUtils.getDocument()
568  dccSheet = ddcDoc.getSheets().getByName(nSheet)
569  lrow = LeggiPosizioneCorrente()[1]
570  if dccSheet.getCellByPosition(0, lrow).CellStyle in ('comp Int_colonna', ):
571  lrow = LeggiPosizioneCorrente()[1] + 1
572  elif dccSheet.getCellByPosition(0, lrow).CellStyle not in stili_computo + stili_cat:
573  # ~DLG.MsgBox('La posizione di destinazione non è corretta.', 'ATTENZIONE!')
574  Dialogs.Exclamation(Title = 'ATTENZIONE!',
575  Text='La posizione di destinazione non è corretta.')
576  # unselect
577  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges"))
578  return
579  else:
580  lrow = LeenoSheetUtils.prossimaVoce(dccSheet, LeggiPosizioneCorrente()[1], 1)
581  _gotoCella(0, lrow)
582  paste_clip(insCells=1)
583  numera_voci(1)
584  last = lrow + ER - SR + 1
585  while lrow < last:
586  rigenera_voce(lrow)
587  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 1)
588  # torno su partenza per prendere i prezzi
589  _gotoDoc(fpartenza)
590  oDoc = LeenoUtils.getDocument()
591  GotoSheet('Elenco Prezzi')
592  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
593  selezione = list()
594  ranges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
595  for el in lista:
596  y = SheetUtils.uFindStringCol(el, 0, oSheet)
597  rangen = oSheet.getCellRangeByPosition(0, y, 100,
598  y).RangeAddress
599  selezione.append(rangen)
600 
601  ranges.addRangeAddresses(selezione, True)
602  oDoc.CurrentController.select(ranges)
603  comando('Copy')
604  #
605  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
606  ddcDoc = LeenoUtils.getDocument()
607  dccSheet = ddcDoc.getSheets().getByName('Elenco Prezzi')
608  GotoSheet('Elenco Prezzi')
609  _gotoCella(0, 3)
610  paste_clip(insCells=1)
611  # EliminaVociDoppieElencoPrezzi()
612  if nSheetDCC in ('Elenco Prezzi'):
613  # ~DLG.MsgBox("Non è possibile inviare voci da un COMPUTO all'Elenco Prezzi.")
614  Dialogs.Exclamation(Title = 'ATTENZIONE!',
615  Text="Non è possibile inviare voci da un COMPUTO all'Elenco Prezzi.")
616  return
617  oDoc.CurrentController.select(
618  oDoc.createInstance(
619  "com.sun.star.sheet.SheetCellRanges")) # unselect
620 
621  try:
622  len(analisi)
623 
624  selezione = list()
625  lista = list()
626  _gotoDoc(fpartenza)
627  oDoc = LeenoUtils.getDocument()
628  GotoSheet('Analisi di Prezzo')
629  ranges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
630  ranges.addRangeAddresses(selezione_analisi, True)
631  oDoc.CurrentController.select(ranges)
632 
633  comando('Copy')
634 
635  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
636  ddcDoc = LeenoUtils.getDocument()
638  _gotoCella(0, 0)
639  paste_clip(insCells=1)
641  except Exception:
642  pass
643 
644  oDoc.CurrentController.select(
645  oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) # unselect
646  _gotoDoc(fpartenza)
647  GotoSheet(nSheet)
648  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
649  # ~if DLG.DlgSiNo("Ricerco ed elimino le voci di prezzo duplicate?") == 2:
650  # ~EliminaVociDoppieElencoPrezzi()
651  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
652  # ~LeenoSheetUtils.adattaAltezzaRiga(oSheet)
653  GotoSheet(nSheetDCC)
654  if nSheetDCC in ('COMPUTO', 'VARIANTE'):
655  lrow = LeggiPosizioneCorrente()[1]
656  _gotoCella(2, lrow + 1)
657  oSheet = oDoc.getSheets().getByName(nSheetDCC)
659 
660 
661 
662 
663 
664 def codice_voce(lrow, cod=None):
665  '''
666  lrow { int } : id della riga
667  cod { string } : codice del prezzo
668  Se cod è assente, restituisce il codice della voce,
669  altrimenti glielo assegna.
670  '''
671  oDoc = LeenoUtils.getDocument()
672  oSheet = oDoc.CurrentController.ActiveSheet
673  # lrow = LeggiPosizioneCorrente()[1]
674  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
675  sopra = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
676  elif oSheet.Name in ('Analisi di Prezzo'):
677  sopra = Circoscrive_Analisi(lrow).RangeAddress.StartRow + 1
678  if cod is None:
679  return oSheet.getCellByPosition(1, sopra + 1).String
680  else:
681  oSheet.getCellByPosition(1, sopra + 1).String = cod
682 
683 
684 # def getVoce(cod=None):
685 # oDoc = LeenoUtils.getDocument()
686 # oSheet = oDoc.CurrentController.ActiveSheet
687 # lrow = LeggiPosizioneCorrente()[1]
688 # sopra = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
689 # return oSheet.getCellByPosition(1, sopra+1).String
690 # def setVoce(cod):
691 # oDoc = LeenoUtils.getDocument()
692 # oSheet = oDoc.CurrentController.ActiveSheet
693 # lrow = LeggiPosizioneCorrente()[1]
694 # sopra = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
695 # oSheet.getCellByPosition(1, sopra+1).String = cod
696 
697 
698 
699 def _gotoDoc(sUrl):
700  '''
701  sUrl { string } : nome del file
702  porta il focus su di un determinato documento
703  '''
704  sUrl = uno.systemPathToFileUrl(sUrl)
705  if sys.platform == 'linux' or sys.platform == 'darwin':
706  target = LeenoUtils.getDesktop().loadComponentFromURL(
707  sUrl, "_default", 0, list())
708  target.getCurrentController().Frame.ContainerWindow.toFront()
709  target.getCurrentController().Frame.activate()
710  elif sys.platform == 'win32':
711  desktop = LeenoUtils.getDesktop()
712  oFocus = uno.createUnoStruct('com.sun.star.awt.FocusEvent')
713  target = desktop.loadComponentFromURL(sUrl, "_default", 0, list())
714  target.getCurrentController().getFrame().focusGained(oFocus)
715  return target
716 
717 
718 
719 
720 
722  '''
723  sUrl { string } : nome del file
724  porta il focus su di un determinato documento
725  '''
726  oDoc = LeenoUtils.getDocument()
727  fpartenza = uno.fileUrlToSystemPath(oDoc.getURL())
728  _gotoDoc(LeenoUtils.getGlobalVar('sUltimus'))
729  sUltimus_sheet = LeenoUtils.getDocument().CurrentController.ActiveSheet.Name
730  _gotoDoc(fpartenza)
731  LeenoUtils.setGlobalVar('sUltimus_sheet', sUltimus_sheet)
732  return sUltimus_sheet
733 
734 
735 
736 
737 
738 def oggi():
739  '''
740  restituisce la data di oggi
741  '''
742  return '/'.join(reversed(str(datetime.now()).split(' ')[0].split('-')))
743 
744 
745 
746 
747 
749  '''
750  fa una copia della directory del codice nel repository locale ed apre una shell per la commit
751  '''
752  oDoc = LeenoUtils.getDocument()
753 
754  try:
755  if oDoc.getSheets().getByName('S1').getCellByPosition(
756  7, 338).String == '':
757  src_oxt = '_LeenO'
758  else:
759  src_oxt = oDoc.getSheets().getByName('S1').getCellByPosition(
760  7, 338).String
761  except Exception:
762  pass
763 
764  make_pack(bar=1)
765  if sys.platform == 'linux' or sys.platform == 'darwin':
766  dest = '/media/giuserpe/PRIVATO/_dwg/ULTIMUSFREE/_SRC/leeno/src/Ultimus.oxt'
767  if not os.path.exists(dest):
768  try:
769  dest = os.getenv(
770  "HOME") + '/' + src_oxt + '/leeno/src/Ultimus.oxt/'
771  os.makedirs(dest)
772  os.makedirs(os.getenv("HOME") + '/' + src_oxt + '/leeno/bin/')
773  os.makedirs(os.getenv("HOME") + '/' + src_oxt + '/_SRC/OXT')
774  except FileExistsError:
775  pass
776 
777  comandi = 'cd ' + dest + ' && mate-terminal && gitk &'
778  else:
779  comandi = 'cd /media/giuserpe/PRIVATO/_dwg/ULTIMUSFREE/_SRC/leeno/src/Ultimus.oxt && mate-terminal && gitk &'
780  if not processo('wish'):
781  subprocess.Popen(comandi, shell=True, stdout=subprocess.PIPE)
782  elif sys.platform == 'win32':
783  if not os.path.exists('w:/_dwg/ULTIMUSFREE/_SRC/leeno/src/'):
784  try:
785  os.makedirs(
786  os.getenv("HOMEPATH") + '\\' + src_oxt +
787  '\\leeno\\src\\Ultimus.oxt\\')
788  except FileExistsError:
789  pass
790  dest = os.getenv("HOMEDRIVE") + os.getenv(
791  "HOMEPATH") + '\\' + src_oxt + '\\leeno\\src\\Ultimus.oxt\\'
792  else:
793  dest = 'w:\\_dwg\\ULTIMUSFREE\\_SRC\\leeno\\src\\Ultimus.oxt'
794  subprocess.Popen(
795  'w: && cd w:/_dwg/ULTIMUSFREE/_SRC/leeno/src/Ultimus.oxt && "C:/Program Files/Git/git-bash.exe"',
796  shell=True,
797  stdout=subprocess.PIPE)
798  return
799 
800 
801 
802 
803 
805  '''
806  Avvia la modifica di pyleeno.py con geany
807  '''
808  avvia_IDE()
809 
810 
811 def avvia_IDE():
812  '''Avvia la modifica di pyleeno.py con geany o eric6'''
813  basic_LeenO('file_gest.avvia_IDE')
814  oDoc = LeenoUtils.getDocument()
815  Toolbars.On("private:resource/toolbar/addon_ULTIMUS_3.OfficeToolBar_DEV", 1)
816  try:
817  if oDoc.getSheets().getByName('S1').getCellByPosition(
818  7, 338).String == '':
819  src_oxt = '_LeenO'
820  else:
821  src_oxt = oDoc.getSheets().getByName('S1').getCellByPosition(
822  7, 338).String
823  except Exception:
824  pass
825 
826  if sys.platform == 'linux' or sys.platform == 'darwin':
827 
828  dest = '/media/giuserpe/PRIVATO/LeenO/_SRC/leeno/src/Ultimus.oxt/python/pythonpath'
829  if not os.path.exists(dest):
830  try:
831  dest = os.getenv(
832  "HOME") + '/' + src_oxt + '/leeno/src/Ultimus.oxt/'
833  os.makedirs(dest)
834  os.makedirs(os.getenv("HOME") + '/' + src_oxt + '/leeno/bin/')
835  os.makedirs(os.getenv("HOME") + '/' + src_oxt + '/_SRC/OXT')
836  except FileExistsError:
837  pass
838 
839  subprocess.Popen('caja '+
840  # ~dest,
841  uno.fileUrlToSystemPath(LeenO_path()),
842  shell=True,
843  stdout=subprocess.PIPE)
844  subprocess.Popen('geany ' + dest + '/pyleeno.py',
845  # ~ subprocess.Popen('eric ' + dest + '/pyleeno.py',
846  shell=True,
847  stdout=subprocess.PIPE)
848  elif sys.platform == 'win32':
849  if not os.path.exists('w:/_dwg/ULTIMUSFREE/_SRC/leeno/src/'):
850  try:
851  os.makedirs(
852  os.getenv("HOMEPATH") + '\\' + src_oxt +
853  '\\leeno\\src\\Ultimus.oxt\\')
854  except FileExistsError:
855  pass
856  dest = os.getenv("HOMEDRIVE") + os.getenv(
857  "HOMEPATH") + '\\' + src_oxt + '\\leeno\\src\\Ultimus.oxt\\'
858  else:
859  dest = 'w:\\_dwg\\ULTIMUSFREE\\_SRC\\leeno\\src\\Ultimus.oxt'
860  # ~subprocess.Popen('explorer.exe ' +
861  # dest,
862  # ~uno.fileUrlToSystemPath(LeenO_path()),
863  # ~shell=True,
864  # ~stdout=subprocess.PIPE)
865  subprocess.Popen('"C:/Program Files/Geany/bin/geany.exe" ' +
866  dest +
867  '/python/pythonpath/pyleeno.py',
868  shell=True,
869  stdout=subprocess.PIPE)
870  return
871 
872 
873 
874 
875 
877  '''
878  @@ DA DOCUMENTARE
879  '''
881 
882 
884  '''
885  @@ DA DOCUMENTARE
886  '''
887  Ins_Categorie(2)
888 
889 
890 
891 
892 
894  '''
895  n { int } : livello della categoria
896  0 = SuperCategoria
897  1 = Categoria
898  2 = SubCategoria
899  '''
900  oDoc = LeenoUtils.getDocument()
902  oSheet = oDoc.CurrentController.ActiveSheet
903 
904  stili_computo = LeenoUtils.getGlobalVar('stili_computo')
905  stili_contab = LeenoUtils.getGlobalVar('stili_contab')
906  noVoce = LeenoUtils.getGlobalVar('noVoce')
907 
908  row = LeggiPosizioneCorrente()[1]
909  if oSheet.getCellByPosition(0,row).CellStyle in stili_computo + stili_contab:
910  lrow = LeenoSheetUtils.prossimaVoce(oSheet, row, 1)
911  elif oSheet.getCellByPosition(0, row).CellStyle in noVoce:
912  lrow = row + 1
913  else:
914  return
915  sTesto = ''
916  if n == 0:
917  sTesto = 'Inserisci il titolo per la Supercategoria'
918  elif n == 1:
919  sTesto = 'Inserisci il titolo per la Categoria'
920  elif n == 2:
921  sTesto = 'Inserisci il titolo per la Sottocategoria'
922  sString = InputBox('', sTesto)
923  if sString is None or sString == '':
924  return
925 
926  if n == 0:
927  LeenoSheetUtils.inserSuperCapitolo(oSheet, lrow, sString)
928  elif n == 1:
929  LeenoSheetUtils.inserCapitolo(oSheet, lrow, sString)
930  elif n == 2:
931  LeenoSheetUtils.inserSottoCapitolo(oSheet, lrow, sString)
932 
933  _gotoCella(2, lrow)
935  oDoc.enableAutomaticCalculation(True)
936  oDoc.CurrentController.setFirstVisibleColumn(0)
937  oDoc.CurrentController.setFirstVisibleRow(lrow - 5)
939 
940 
941 
942 
943 
945  '''
946  @@ DA DOCUMENTARE
947  '''
949 
950 
952  '''
953  @@ DA DOCUMENTARE
954  '''
955  Ins_Categorie(0)
956 
957 
958 
960  '''
961  @@ DA DOCUMENTARE
962  '''
964 
965 
967  '''
968  @@ DA DOCUMENTARE
969  '''
970  Ins_Categorie(1)
971 
972 
973 
974 
976  oDoc = LeenoUtils.getDocument()
977  oSheet = oDoc.CurrentController.ActiveSheet
979 
980 
982  # sistemo gli idcat voce per voce
983  oDoc = LeenoUtils.getDocument()
984  oDoc.enableAutomaticCalculation(False)
986 
987  # ricalcola i totali di categorie e subcategorie
988  Tutti_Subtotali(oSheet)
989  oDoc.enableAutomaticCalculation(True)
990 
991 
992 def Tutti_Subtotali(oSheet):
993  '''ricalcola i subtotali di categorie e subcategorie'''
994 
995  if oSheet.Name not in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
996  return
997  for n in range(0, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1):
998  if oSheet.getCellByPosition(0, n).CellStyle == 'Livello-0-scritta':
999  SubSum_SuperCap(n)
1000  if oSheet.getCellByPosition(0, n).CellStyle == 'Livello-1-scritta':
1001  SubSum_Cap(n)
1002  if oSheet.getCellByPosition(0, n).CellStyle == 'livello2 valuta':
1003  SubSum_SottoCap(n)
1004 
1005  # TOTALI GENERALI
1006  lrow = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1
1007  oSheet.getCellByPosition(
1008  17, 1).Formula = '=SUBTOTAL(9;R4:R' + str(lrow + 1) + ')'
1009  oSheet.getCellByPosition(
1010  17, lrow).Formula = '=SUBTOTAL(9;R4:R' + str(lrow + 1) + ')'
1011  oSheet.getCellByPosition(
1012  18, 1).Formula = '=SUBTOTAL(9;S4:S' + str(lrow + 1) + ')'
1013  oSheet.getCellByPosition(
1014  18, lrow).Formula = '=SUBTOTAL(9;S4:S' + str(lrow + 1) + ')'
1015 
1016  oSheet.getCellByPosition(
1017  28, lrow).Formula = '=SUBTOTAL(9;AC4:AC' + str(lrow + 1) + ')'
1018  oSheet.getCellByPosition(
1019  28, 1).Formula = '=SUBTOTAL(9;AC4:AC' + str(lrow + 1) + ')'
1020 
1021  oSheet.getCellByPosition(
1022  30, lrow).Formula = '=SUBTOTAL(9;AE4:AE' + str(lrow + 1) + ')'
1023  oSheet.getCellByPosition(
1024  30, 1).Formula = '=SUBTOTAL(9;AE4:AE' + str(lrow + 1) + ')'
1025  oSheet.getCellByPosition(
1026  36, lrow).Formula = '=SUBTOTAL(9;AK4:AK' + str(lrow + 1) + ')'
1027  oSheet.getCellByPosition(
1028  36, 1).Formula = '=SUBTOTAL(9;AK4:AK' + str(lrow + 1) + ')'
1029 
1030 
1031 
1032 
1033 
1035  '''
1036  lrow { double } : id della riga di inserimento
1037  inserisce i dati nella riga di SuperCategoria
1038  '''
1039  oDoc = LeenoUtils.getDocument()
1040  oSheet = oDoc.CurrentController.ActiveSheet
1041  if oSheet.Name not in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
1042  return
1043  # lrow = LeggiPosizioneCorrente()[1]
1044  lrowE = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2
1045  nextCap = lrowE
1046  for n in range(lrow + 1, lrowE):
1047  if oSheet.getCellByPosition(
1048  18,
1049  n).CellStyle in ('Livello-0-scritta mini val', 'Comp TOTALI'):
1050  # MsgBox(oSheet.getCellByPosition(18, n).CellStyle,'')
1051  nextCap = n + 1
1052  break
1053  # oDoc.enableAutomaticCalculation(False)
1054  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
1055  oSheet.getCellByPosition(
1056  18, lrow
1057  ).Formula = '=SUBTOTAL(9;S' + str(lrow + 1) + ':S' + str(nextCap) + ')'
1058  oSheet.getCellByPosition(
1059  24, lrow).Formula = '=S' + str(lrow + 1) + '/S' + str(lrowE)
1060  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1061  lrow + 1) + ':AC' + str(nextCap) + ')'
1062  oSheet.getCellByPosition(
1063  29, lrow).Formula = '=AE' + str(lrow + 1) + '/S' + str(lrow + 1)
1064  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1065  lrow + 1) + ':AE' + str(nextCap) + ')'
1066  oSheet.getCellByPosition(18,
1067  lrow).CellStyle = 'Livello-0-scritta mini val'
1068  oSheet.getCellByPosition(24,
1069  lrow).CellStyle = 'Livello-0-scritta mini %'
1070  oSheet.getCellByPosition(29,
1071  lrow).CellStyle = 'Livello-0-scritta mini %'
1072  oSheet.getCellByPosition(30,
1073  lrow).CellStyle = 'Livello-0-scritta mini val'
1074  if oSheet.Name in ('CONTABILITA'):
1075  oSheet.getCellByPosition(15, lrow).Formula = '=SUBTOTAL(9;P' + str(
1076  lrow + 1) + ':P' + str(nextCap) + ')' # IMPORTO
1077  oSheet.getCellByPosition(
1078  16, lrow).Formula = '=P' + str(lrow + 1) + '/P' + str(
1079  lrowE) # incidenza sul totale
1080  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1081  lrow + 1) + ':AC' + str(nextCap) + ')'
1082  oSheet.getCellByPosition(
1083  29, lrow).Formula = '=AE' + str(lrow + 1) + '/P' + str(lrow + 1)
1084  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1085  lrow + 1) + ':AE' + str(nextCap) + ')'
1086  oSheet.getCellByPosition(15,
1087  lrow).CellStyle = 'Livello-0-scritta mini val'
1088  oSheet.getCellByPosition(16,
1089  lrow).CellStyle = 'Livello-0-scritta mini %'
1090  oSheet.getCellByPosition(29,
1091  lrow).CellStyle = 'Livello-0-scritta mini %'
1092  oSheet.getCellByPosition(28,
1093  lrow).CellStyle = 'Livello-0-scritta mini val'
1094  oSheet.getCellByPosition(30,
1095  lrow).CellStyle = 'Livello-0-scritta mini val'
1096  # oDoc.enableAutomaticCalculation(True)
1097 
1098 
1099 
1100 
1101 
1103  '''
1104  lrow { double } : id della riga di inserimento
1105  inserisce i dati nella riga di subcategoria
1106  '''
1107  oDoc = LeenoUtils.getDocument()
1108  oSheet = oDoc.CurrentController.ActiveSheet
1109  if oSheet.Name not in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
1110  return
1111  # lrow = 0#LeggiPosizioneCorrente()[1]
1112  lrowE = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2
1113  nextCap = lrowE
1114  for n in range(lrow + 1, lrowE):
1115  if oSheet.getCellByPosition(
1116  18,
1117  n).CellStyle in ('livello2 scritta mini',
1118  'Livello-0-scritta mini val',
1119  'Livello-1-scritta mini val', 'Comp TOTALI'):
1120  nextCap = n + 1
1121  break
1122  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
1123  oSheet.getCellByPosition(
1124  18, lrow
1125  ).Formula = '=SUBTOTAL(9;S' + str(lrow + 1) + ':S' + str(nextCap) + ')'
1126  oSheet.getCellByPosition(
1127  24, lrow).Formula = '=S' + str(lrow + 1) + '/S' + str(lrowE)
1128  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1129  lrow + 1) + ':AC' + str(nextCap) + ')'
1130  oSheet.getCellByPosition(
1131  29, lrow).Formula = '=AE' + str(lrow + 1) + '/S' + str(lrow + 1)
1132  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1133  lrow + 1) + ':AE' + str(nextCap) + ')'
1134  oSheet.getCellByPosition(18, lrow).CellStyle = 'livello2 scritta mini'
1135  oSheet.getCellByPosition(24, lrow).CellStyle = 'livello2 valuta mini %'
1136  oSheet.getCellByPosition(28, lrow).CellStyle = 'livello2 scritta mini'
1137  oSheet.getCellByPosition(29, lrow).CellStyle = 'livello2 valuta mini %'
1138  oSheet.getCellByPosition(30, lrow).CellStyle = 'livello2 valuta mini'
1139  if oSheet.Name in ('CONTABILITA'):
1140  oSheet.getCellByPosition(15, lrow).Formula = '=SUBTOTAL(9;P' + str(
1141  lrow + 1) + ':P' + str(nextCap) + ')' # IMPORTO
1142  oSheet.getCellByPosition(
1143  16, lrow).Formula = '=P' + str(lrow + 1) + '/P' + str(
1144  lrowE) # incidenza sul totale
1145  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1146  lrow + 1) + ':AC' + str(nextCap) + ')'
1147  oSheet.getCellByPosition(
1148  29, lrow).Formula = '=AE' + str(lrow + 1) + '/P' + str(lrow + 1)
1149  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1150  lrow + 1) + ':AE' + str(nextCap) + ')'
1151  oSheet.getCellByPosition(15, lrow).CellStyle = 'livello2 scritta mini'
1152  oSheet.getCellByPosition(16, lrow).CellStyle = 'livello2 valuta mini %'
1153  oSheet.getCellByPosition(29, lrow).CellStyle = 'livello2 valuta mini %'
1154  oSheet.getCellByPosition(28, lrow).CellStyle = 'livello2 scritta mini'
1155  oSheet.getCellByPosition(30, lrow).CellStyle = 'livello2 scritta mini'
1156 
1157 
1158 
1159 
1160 
1161 def SubSum_Cap(lrow):
1162  '''
1163  lrow { double } : id della riga di inserimento
1164  inserisce i dati nella riga di categoria
1165  '''
1166  oDoc = LeenoUtils.getDocument()
1167  oSheet = oDoc.CurrentController.ActiveSheet
1168  if oSheet.Name not in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
1169  return
1170  # lrow = LeggiPosizioneCorrente()[1]
1171  lrowE = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2
1172  nextCap = lrowE
1173  for n in range(lrow + 1, lrowE):
1174  if oSheet.getCellByPosition(
1175  18,
1176  n).CellStyle in ('Livello-1-scritta mini val',
1177  'Livello-0-scritta mini val', 'Comp TOTALI'):
1178  # MsgBox(oSheet.getCellByPosition(18, n).CellStyle,'')
1179  nextCap = n + 1
1180  break
1181  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
1182  oSheet.getCellByPosition(18, lrow).Formula = '=SUBTOTAL(9;S' + str(
1183  lrow + 1) + ':S' + str(nextCap) + ')' # IMPORTO
1184  oSheet.getCellByPosition(
1185  24, lrow).Formula = '=S' + str(lrow + 1) + '/S' + str(lrowE)
1186  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1187  lrow + 1) + ':AC' + str(nextCap) + ')'
1188  oSheet.getCellByPosition(
1189  29, lrow).Formula = '=AE' + str(lrow + 1) + '/S' + str(lrow + 1)
1190  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1191  lrow + 1) + ':AE' + str(nextCap) + ')'
1192  oSheet.getCellByPosition(18,
1193  lrow).CellStyle = 'Livello-1-scritta mini val'
1194  oSheet.getCellByPosition(24,
1195  lrow).CellStyle = 'Livello-1-scritta mini %'
1196  oSheet.getCellByPosition(29,
1197  lrow).CellStyle = 'Livello-1-scritta mini %'
1198  oSheet.getCellByPosition(30,
1199  lrow).CellStyle = 'Livello-1-scritta mini val'
1200  if oSheet.Name in ('CONTABILITA'):
1201  oSheet.getCellByPosition(15, lrow).Formula = '=SUBTOTAL(9;P' + str(
1202  lrow + 1) + ':P' + str(nextCap) + ')' # IMPORTO
1203  oSheet.getCellByPosition(
1204  16, lrow).Formula = '=P' + str(lrow + 1) + '/P' + str(
1205  lrowE) # incidenza sul totale
1206  oSheet.getCellByPosition(28, lrow).Formula = '=SUBTOTAL(9;AC' + str(
1207  lrow + 1) + ':AC' + str(nextCap) + ')'
1208  oSheet.getCellByPosition(
1209  29, lrow).Formula = '=AE' + str(lrow + 1) + '/P' + str(lrow + 1)
1210  oSheet.getCellByPosition(30, lrow).Formula = '=SUBTOTAL(9;AE' + str(
1211  lrow + 1) + ':AE' + str(nextCap) + ')'
1212  oSheet.getCellByPosition(15,
1213  lrow).CellStyle = 'Livello-1-scritta mini val'
1214  oSheet.getCellByPosition(16,
1215  lrow).CellStyle = 'Livello-1-scritta mini %'
1216  oSheet.getCellByPosition(29,
1217  lrow).CellStyle = 'Livello-1-scritta mini %'
1218  oSheet.getCellByPosition(28,
1219  lrow).CellStyle = 'Livello-1-scritta mini val'
1220  oSheet.getCellByPosition(30,
1221  lrow).CellStyle = 'Livello-1-scritta mini val'
1222 
1223 
1224 
1225 
1226 
1228  '''
1229  lrow { double } : id della riga di inserimento
1230  sincronizza categoria e sottocategorie
1231  '''
1232  if oSheet.Name not in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
1233  return
1234 # lrow = LeggiPosizioneCorrente()[1]
1235  lastRow = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1
1236 
1237  listasbcat = list()
1238  listacat = list()
1239  listaspcat = list()
1240  for lrow in range(0, lastRow):
1241  # SUB CATEGORIA
1242  if oSheet.getCellByPosition(2, lrow).CellStyle == 'livello2_':
1243  if oSheet.getCellByPosition(2, lrow).String not in listasbcat:
1244  listasbcat.append((oSheet.getCellByPosition(2, lrow).String))
1245  try:
1246  oSheet.getCellByPosition(31, lrow).Value = idspcat
1247  except Exception:
1248  pass
1249  try:
1250  oSheet.getCellByPosition(32, lrow).Value = idcat
1251  except Exception:
1252  pass
1253  idsbcat = listasbcat.index(oSheet.getCellByPosition(2, lrow).String) + 1
1254  oSheet.getCellByPosition(33, lrow).Value = idsbcat
1255  oSheet.getCellByPosition(
1256  1, lrow).Formula = '=AF' + str(lrow + 1) + '&"."&AG' + str(
1257  lrow + 1) + '&"."&AH' + str(lrow + 1)
1258 
1259  # CATEGORIA
1260  elif oSheet.getCellByPosition(2, lrow).CellStyle == 'Livello-1-scritta mini':
1261  if oSheet.getCellByPosition(2, lrow).String not in listacat:
1262  listacat.append((oSheet.getCellByPosition(2, lrow).String))
1263 
1264  idsbcat = None
1265 
1266  try:
1267  oSheet.getCellByPosition(31, lrow).Value = idspcat
1268  except Exception:
1269  pass
1270  idcat = listacat.index(oSheet.getCellByPosition(2,
1271  lrow).String) + 1
1272  oSheet.getCellByPosition(32, lrow).Value = idcat
1273  oSheet.getCellByPosition(
1274  1, lrow).Formula = '=AF' + str(lrow +
1275  1) + '&"."&AG' + str(lrow + 1)
1276 
1277  # SUPER CATEGORIA
1278  elif oSheet.getCellByPosition(
1279  2,
1280  lrow).CellStyle == 'Livello-0-scritta mini':
1281  if oSheet.getCellByPosition(2, lrow).String not in listaspcat:
1282  listaspcat.append((oSheet.getCellByPosition(2, lrow).String))
1283 
1284  idcat = idsbcat = None
1285 
1286  idspcat = listaspcat.index(
1287  oSheet.getCellByPosition(2, lrow).String) + 1
1288  oSheet.getCellByPosition(31, lrow).Value = idspcat
1289  oSheet.getCellByPosition(1, lrow).Formula = '=AF' + str(lrow + 1)
1290 
1291  # CATEGORIA
1292  elif oSheet.getCellByPosition(
1293  33, lrow).CellStyle == 'compTagRiservato':
1294  try:
1295  oSheet.getCellByPosition(33, lrow).Value = idsbcat
1296  except Exception:
1297  oSheet.getCellByPosition(33, lrow).Value = 0
1298  try:
1299  oSheet.getCellByPosition(32, lrow).Value = idcat
1300  except Exception:
1301  oSheet.getCellByPosition(32, lrow).Value = 0
1302  try:
1303  oSheet.getCellByPosition(31, lrow).Value = idspcat
1304  except Exception:
1305  oSheet.getCellByPosition(31, lrow).Value = 0
1306 
1307 
1310 
1311 
1313  '''Mostra tutti i foglio fogli'''
1314  oDoc = LeenoUtils.getDocument()
1315  lista_fogli = oDoc.Sheets.ElementNames
1316  for el in lista_fogli:
1317  oDoc.getSheets().getByName(el).IsVisible = True
1318 
1319 
1320 
1321 
1322 
1324  '''
1325  Mostra tutti i foglio fogli
1326  '''
1328 
1329 
1331  '''Mostra tutti i foglio fogli'''
1332  oDoc = LeenoUtils.getDocument()
1333  lista_fogli = oDoc.Sheets.ElementNames
1334  for el in lista_fogli:
1335  oDoc.getSheets().getByName(el).IsVisible = True
1336  for nome in ('cP_', 'cT_', 'M1', 'S1', 'S2', 'S5', 'QUADRO ECONOMICO',
1337  '_LeenO', 'Scorciatoie'):
1338  if nome in el:
1339  oDoc.getSheets().getByName(el).IsVisible = False
1340 
1341 
1342 
1343 
1344 
1346  '''Mostra tutti i foglio fogli'''
1347  oDoc = LeenoUtils.getDocument()
1348  lista_fogli = oDoc.Sheets.ElementNames
1350  for el in lista_fogli:
1351  oDoc.getSheets().getByName(el).IsVisible = True
1352  for nome in ('cP_', 'M1', 'S1', 'S2', 'S5', 'QUADRO ECONOMICO',
1353  '_LeenO', 'Scorciatoie'):
1354  if nome in el:
1355  oDoc.getSheets().getByName(el).IsVisible = False
1356 
1357 
1358 
1359 
1360 
1362  '''Mostra tutti i foglio fogli'''
1363  oDoc = LeenoUtils.getDocument()
1364  lista_fogli = oDoc.Sheets.ElementNames
1366  for el in lista_fogli:
1367  oDoc.getSheets().getByName(el).IsVisible = True
1368  for nome in ('cT_', 'M1', 'S1', 'S2', 'S5', 'QUADRO ECONOMICO',
1369  '_LeenO', 'Scorciatoie'):
1370  if nome in el:
1371  oDoc.getSheets().getByName(el).IsVisible = False
1372 
1373 
1374 
1375 
1376 
1377 def copia_sheet(nSheet, tag):
1378  '''
1379  nSheet { string } : nome sheet
1380  tag { string } : stringa di tag
1381  duplica copia sheet corrente di fianco a destra
1382  '''
1383  oDoc = LeenoUtils.getDocument()
1384  # nSheet = 'COMPUTO'
1385  oSheet = oDoc.getSheets().getByName(nSheet)
1386  idSheet = oSheet.RangeAddress.Sheet + 1
1387  if oDoc.getSheets().hasByName(nSheet + '_' + tag):
1388  DLG.MsgBox('La tabella di nome ' + nSheet + '_' + tag + 'è già presente.', 'ATTENZIONE! Impossibile procedere.')
1389  return
1390  else:
1391  oDoc.Sheets.copyByName(nSheet, nSheet + '_' + tag, idSheet)
1392  oSheet = oDoc.getSheets().getByName(nSheet + '_' + tag)
1393  oDoc.CurrentController.setActiveSheet(oSheet)
1394  # oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) #'unselect
1395 
1396 
1397 
1398 
1399 
1400 def Filtra_computo(nSheet, nCol, sString):
1401  '''
1402  nSheet { string } : nome Sheet
1403  ncol { integer } : colonna di tag
1404  sString { string } : stringa di tag
1405  crea una nuova sheet contenente le sole voci filtrate
1406  '''
1407  oDoc = LeenoUtils.getDocument()
1408  copia_sheet(nSheet, sString)
1409  oSheet = oDoc.CurrentController.ActiveSheet
1410  for lrow in reversed(range(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))):
1411  try:
1412  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
1413  sopra = sStRange.RangeAddress.StartRow
1414  sotto = sStRange.RangeAddress.EndRow
1415  if nCol == 1:
1416  test = sopra + 1
1417  else:
1418  test = sotto
1419  if sString != oSheet.getCellByPosition(nCol, test).String:
1420  oSheet.getRows().removeByIndex(sopra, sotto - sopra + 1)
1421  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 0)
1422  except Exception:
1423  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 0)
1424  for lrow in range(3, SheetUtils.getUsedArea(oSheet).EndRow):
1425  if(oSheet.getCellByPosition(18, lrow).CellStyle == 'Livello-1-scritta mini val' and
1426  oSheet.getCellByPosition(18, lrow).Value == 0 or
1427  oSheet.getCellByPosition(18, lrow).CellStyle == 'livello2 scritta mini' and
1428  oSheet.getCellByPosition(18, lrow).Value == 0):
1429 
1430  oSheet.getRows().removeByIndex(lrow, 1)
1431  return
1432  # iCellAttr =(oDoc.createInstance("com.sun.star.sheet.CellFlags.OBJECTS"))
1433  flags = OBJECTS
1434  oSheet.getCellRangeByPosition(0, 0, 42, 0).clearContents(
1435  flags) # cancello gli oggetti
1436  oDoc.CurrentController.select(oSheet.getCellByPosition(0, 3))
1437  oDoc.CurrentController.select(
1438  oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) # unselect
1439 
1440 
1441 
1442 
1443 
1444 # ~def Filtra_Computo_Cap():
1445  # ~oDoc = LeenoUtils.getDocument()
1446  # ~oSheet = oDoc.CurrentController.ActiveSheet
1447  # ~nSheet = oSheet.getCellByPosition(7, 8).String
1448  # ~sString = oSheet.getCellByPosition(7, 10).String
1449  # ~Filtra_computo(nSheet, 31, sString)
1450 
1451 
1452 
1453 
1454 
1455 # ~def Filtra_Computo_SottCap():
1456  # ~oDoc = LeenoUtils.getDocument()
1457  # ~oSheet = oDoc.CurrentController.ActiveSheet
1458  # ~nSheet = oSheet.getCellByPosition(7, 8).String
1459  # ~sString = oSheet.getCellByPosition(7, 12).String
1460  # ~Filtra_computo(nSheet, 32, sString)
1461 
1462 
1463 
1464 
1465 
1466 # ~def Filtra_Computo_A():
1467  # ~oDoc = LeenoUtils.getDocument()
1468  # ~oSheet = oDoc.CurrentController.ActiveSheet
1469  # ~nSheet = oSheet.getCellByPosition(7, 8).String
1470  # ~sString = oSheet.getCellByPosition(7, 14).String
1471  # ~Filtra_computo(nSheet, 33, sString)
1472 
1473 
1474 
1475 
1476 
1477 # ~def Filtra_Computo_B():
1478  # ~oDoc = LeenoUtils.getDocument()
1479  # ~oSheet = oDoc.CurrentController.ActiveSheet
1480  # ~nSheet = oSheet.getCellByPosition(7, 8).String
1481  # ~sString = oSheet.getCellByPosition(7, 16).String
1482  # ~Filtra_computo(nSheet, 34, sString)
1483 
1484 
1485 
1486 
1487 
1488 # ~def Filtra_Computo_C(): # filtra in base al codice di prezzo
1489  # ~oDoc = LeenoUtils.getDocument()
1490  # ~oSheet = oDoc.CurrentController.ActiveSheet
1491  # ~nSheet = oSheet.getCellByPosition(7, 8).String
1492  # ~sString = oSheet.getCellByPosition(7, 20).String
1493  # ~Filtra_computo(nSheet, 1, sString)
1494 
1495 
1496 
1497 
1498 
1499 def vai_a_M1():
1500  chiudi_dialoghi()
1501  GotoSheet('M1', 85)
1502  _primaCella(0, 0)
1503 
1504 
1505 
1506 
1507 
1508 def vai_a_S2():
1509  chiudi_dialoghi()
1510  GotoSheet('S2')
1511  _primaCella(0, 0)
1512 
1513 
1514 
1515 
1516 
1517 def vai_a_S1():
1518  chiudi_dialoghi()
1519  GotoSheet('S1')
1520  _primaCella(0, 190)
1521 
1522 
1523 
1524 
1525 
1526 def vai_a_ElencoPrezzi(event=None):
1527  chiudi_dialoghi()
1528  GotoSheet('Elenco Prezzi')
1529 
1530 
1531 
1532 
1533 
1535  chiudi_dialoghi()
1536  GotoSheet('COMPUTO')
1537 
1538 
1539 
1540 
1541 
1543  chiudi_dialoghi()
1544  GotoSheet('S1', 85)
1545  _primaCella(6, 289)
1546 
1547 
1548 
1549 
1550 
1552  chiudi_dialoghi()
1553  GotoSheet('Scorciatoie')
1554  _primaCella(0, 0)
1555 
1556 
1557 
1558 
1559 
1560 def GotoSheet(nSheet, fattore=100):
1561  '''
1562  nSheet { string } : nome Sheet
1563  attiva e seleziona una sheet
1564  '''
1565  oDoc = LeenoUtils.getDocument()
1566  oSheet = oDoc.Sheets.getByName(nSheet)
1567  # oDoc.getCurrentSelection().getCellAddress().Sheet
1568 
1569  oSheet.IsVisible = True
1570  oDoc.CurrentController.setActiveSheet(oSheet)
1571  # oDoc.CurrentController.ZoomValue = fattore
1572  # oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) #'unselect
1573 
1574 
1575 
1576 
1577 
1578 def _primaCella(IDcol=0, IDrow=0):
1579  '''
1580  IDcol { integer } : id colonna
1581  IDrow { integer } : id riga
1582  settaggio prima cella visibile(IDcol, IDrow)
1583  '''
1584  oDoc = LeenoUtils.getDocument()
1585  # oSheet = oDoc.CurrentController.ActiveSheet
1586  oDoc.CurrentController.setFirstVisibleColumn(IDcol)
1587  oDoc.CurrentController.setFirstVisibleRow(IDrow)
1588  return
1589 
1590 
1591 
1592 
1593 
1594 def ordina_col(ncol):
1595  '''
1596  ncol { integer } : id colonna
1597  ordina i dati secondo la colonna con id ncol
1598  '''
1599  # oDoc = LeenoUtils.getDocument()
1600  # oSheet = oDoc.CurrentController.ActiveSheet
1602  desktop = LeenoUtils.getDesktop()
1603  oFrame = desktop.getCurrentFrame()
1604  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
1605  'com.sun.star.frame.DispatchHelper', ctx)
1606  oProp = []
1607  oProp0 = PropertyValue()
1608  oProp0.Name = 'ByRows'
1609  oProp0.Value = True
1610  oProp1 = PropertyValue()
1611  oProp1.Name = 'HasHeader'
1612  oProp1.Value = False
1613  oProp2 = PropertyValue()
1614  oProp2.Name = 'CaseSensitive'
1615  oProp2.Value = False
1616  oProp3 = PropertyValue()
1617  oProp3.Name = 'NaturalSort'
1618  oProp3.Value = False
1619  oProp4 = PropertyValue()
1620  oProp4.Name = 'IncludeAttribs'
1621  oProp4.Value = True
1622  oProp5 = PropertyValue()
1623  oProp5.Name = 'UserDefIndex'
1624  oProp5.Value = 0
1625  oProp6 = PropertyValue()
1626  oProp6.Name = 'Col1'
1627  oProp6.Value = ncol
1628  oProp7 = PropertyValue()
1629  oProp7.Name = 'Ascending1'
1630  oProp7.Value = True
1631  oProp.append(oProp0)
1632  oProp.append(oProp1)
1633  oProp.append(oProp2)
1634  oProp.append(oProp3)
1635  oProp.append(oProp4)
1636  oProp.append(oProp5)
1637  oProp.append(oProp6)
1638  oProp.append(oProp7)
1639  properties = tuple(oProp)
1640  dispatchHelper.executeDispatch(oFrame, '.uno:DataSort', '', 0, properties)
1641 
1642 
1643 
1644 
1646  '''
1647  Sprotegge e riordina tutti fogli del documento.
1648  '''
1650 
1651 
1653  '''
1654  Sprotegge e riordina tutti fogli del documento.
1655  '''
1656  oDoc = LeenoUtils.getDocument()
1657  oSheets = oDoc.Sheets.ElementNames
1658  for nome in oSheets:
1659  oSheet = oDoc.getSheets().getByName(nome)
1660  oSheet.unprotect('')
1661  # riordino le sheet
1662  oDoc.Sheets.moveByName("Elenco Prezzi", 0)
1663  if oDoc.Sheets.hasByName("Analisi di Prezzo"):
1664  oDoc.Sheets.moveByName("Analisi di Prezzo", 1)
1665  oDoc.Sheets.moveByName("COMPUTO", 2)
1666  if oDoc.Sheets.hasByName("VARIANTE"):
1667  oDoc.Sheets.moveByName("VARIANTE", 3)
1668  if oDoc.Sheets.hasByName("CONTABILITA"):
1669  oDoc.Sheets.moveByName("CONTABILITA", 4)
1670  if oDoc.Sheets.hasByName("M1"):
1671  oDoc.Sheets.moveByName("M1", 5)
1672  oDoc.Sheets.moveByName("S1", 6)
1673  oDoc.Sheets.moveByName("S2", 7)
1674  # ~oDoc.Sheets.moveByName("S4", 9)
1675  if oDoc.Sheets.hasByName("S5"):
1676  oDoc.Sheets.moveByName("S5", 10)
1677  if oDoc.Sheets.hasByName("copyright_LeenO"):
1678  oDoc.Sheets.moveByName("copyright_LeenO", oDoc.Sheets.Count)
1679 
1680 
1681 
1682 
1683 
1684 def setPreview(arg=0):
1685  '''
1686  colore { integer } : id colore
1687  attribuisce al foglio corrente un colore a scelta
1688  '''
1689  oDoc = LeenoUtils.getDocument()
1690  oSheet = oDoc.CurrentController.ActiveSheet # se questa dà errore, il preview è già attivo
1691  # ~LeenoSheetUtils.adattaAltezzaRiga(oSheet)
1693  desktop = LeenoUtils.getDesktop()
1694  oFrame = desktop.getCurrentFrame()
1695  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
1696  'com.sun.star.frame.DispatchHelper', ctx)
1697  oProp = PropertyValue()
1698  properties = (oProp, )
1699  dispatchHelper.executeDispatch(oFrame, '.uno:PrintPreview', '', arg, properties)
1700 
1701 
1702 
1703 
1704 
1705 def setTabColor(colore):
1706  '''
1707  colore { integer } : id colore
1708  attribuisce al foglio corrente un colore a scelta
1709  '''
1710  # oDoc = LeenoUtils.getDocument()
1711  # oSheet = oDoc.CurrentController.ActiveSheet
1713  desktop = LeenoUtils.getDesktop()
1714  oFrame = desktop.getCurrentFrame()
1715  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
1716  'com.sun.star.frame.DispatchHelper', ctx)
1717  oProp = PropertyValue()
1718  oProp.Name = 'TabBgColor'
1719  oProp.Value = colore
1720  properties = (oProp, )
1721  dispatchHelper.executeDispatch(oFrame, '.uno:SetTabBgColor', '', 0,
1722  properties)
1723 
1724 
1725 
1726 
1727 
1728 def txt_Format(stile):
1729  '''
1730  Forza la formattazione della cella
1731  '''
1732  # oDoc = LeenoUtils.getDocument()
1733  # oSheet = oDoc.CurrentController.ActiveSheet
1735  desktop = LeenoUtils.getDesktop()
1736  oFrame = desktop.getCurrentFrame()
1737  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
1738  'com.sun.star.frame.DispatchHelper', ctx)
1739  oProp = PropertyValue()
1740  oProp.Name = stile
1741  oProp.Value = True
1742  properties = (oProp, )
1743  dispatchHelper.executeDispatch(oFrame, '.uno:' + stile, '', 0, properties)
1744 
1745 
1746 
1747 
1748 
1749 def show_sheets(x=True):
1750  '''
1751  x { boolean } : True = ON, False = OFF
1752 
1753  Mastra/nasconde tutte le tabelle ad esclusione di COMPUTO ed Elenco Prezzi
1754  '''
1755  oDoc = LeenoUtils.getDocument()
1756  oSheets = list(oDoc.getSheets().getElementNames())
1757  # for nome in ('M1', 'S1', 'S2', 'S5', 'Elenco Prezzi', 'COMPUTO'):
1758  for nome in ('Elenco Prezzi', 'COMPUTO'):
1759  oSheets.remove(nome)
1760  # oSheets.remove('Elenco Prezzi')
1761  # oSheets.remove('COMPUTO')
1762  for nome in oSheets:
1763  oSheet = oDoc.getSheets().getByName(nome)
1764  oSheet.IsVisible = x
1765  for nome in ('COMPUTO', 'VARIANTE', 'Elenco Prezzi', 'CONTABILITA',
1766  'Analisi di Prezzo'):
1767  try:
1768  oSheet = oDoc.getSheets().getByName(nome)
1769  oSheet.IsVisible = True
1770  except Exception:
1771  pass
1772 
1773 
1775  show_sheets(False)
1776 
1777 
1778 
1779 
1780 
1781 def salva_come(nomefile=None):
1782  '''
1783  nomefile { string } : nome del file di destinazione
1784  Se presente l'argomento nomefile, salva il file corrente in nomefile.
1785  '''
1786  # oDoc = LeenoUtils.getDocument()
1787  # oSheet = oDoc.CurrentController.ActiveSheet
1789  desktop = LeenoUtils.getDesktop()
1790  oFrame = desktop.getCurrentFrame()
1791  dispatchHelper = ctx.ServiceManager.createInstanceWithContext('com.sun.star.frame.DispatchHelper', ctx)
1792 
1793  oProp = []
1794  if nomefile is not None:
1795  nomefile = uno.systemPathToFileUrl(nomefile)
1796  oProp0 = PropertyValue()
1797  oProp0.Name = "URL"
1798  oProp0.Value = nomefile
1799  oProp.append(oProp0)
1800 
1801  oProp1 = PropertyValue()
1802  oProp1.Name = "FilterName"
1803  oProp1.Value = "calc8"
1804  oProp.append(oProp1)
1805 
1806  properties = tuple(oProp)
1807 
1808  dispatchHelper.executeDispatch(oFrame, ".uno:SaveAs", "", 0, properties)
1809 
1810 
1811 
1812 
1813 
1814 def _gotoCella(IDcol=0, IDrow=0):
1815  '''
1816  IDcol { integer } : id colonna
1817  IDrow { integer } : id riga
1818 
1819  muove il cursore nelle cella(IDcol, IDrow)
1820  '''
1821  oDoc = LeenoUtils.getDocument()
1822  oSheet = oDoc.CurrentController.ActiveSheet
1823 
1824  oDoc.CurrentController.select(oSheet.getCellByPosition(IDcol, IDrow))
1825  oDoc.CurrentController.select(
1826  oDoc.createInstance("com.sun.star.sheet.SheetCellRanges"))
1827  return
1828 
1829 
1830 
1831 
1832 
1834  '''
1835  Legge il numero di versione di LibreOffice.
1836  '''
1837  # sAccess = LeenoUtils.createUnoService(
1838  # "com.sun.star.configuration.ConfigurationAccess")
1839  aConfigProvider = LeenoUtils.createUnoService(
1840  "com.sun.star.configuration.ConfigurationProvider")
1841  arg = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
1842  arg.Name = "nodepath"
1843  arg.Value = '/org.openoffice.Setup/Product'
1844  return aConfigProvider.createInstanceWithArguments(
1845  "com.sun.star.configuration.ConfigurationAccess",
1846  (arg, )).ooSetupVersionAboutBox
1847 
1848 
1851 
1853  oDoc = LeenoUtils.getDocument()
1854  oSheet = oDoc.CurrentController.ActiveSheet
1856 
1858  '''
1859  Cambia il numero di caratteri visualizzati per la descrizione voce in COMPUTO,
1860  CONTABILITA E VARIANTE.
1861  '''
1862  chiudi_dialoghi()
1863  oDoc = LeenoUtils.getDocument()
1864  oSheet = oDoc.CurrentController.ActiveSheet
1865  # ~oSheet.getCellRangeByPosition(
1866  # ~0, 0,
1867  # ~SheetUtils.getUsedArea(oSheet).EndColumn,
1868  # ~SheetUtils.getUsedArea(oSheet).EndRow).Rows.OptimalHeight = True
1869  if not oDoc.getSheets().hasByName('S1'):
1870  return
1871  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
1872  oSheet = oDoc.getSheets().getByName('S1')
1873  if oSheet.getCellRangeByName('S1.H337').Value < 10000:
1874  cfg.write('Computo', 'inizio_voci_abbreviate', oSheet.getCellRangeByName('S1.H337').String)
1875  oSheet.getCellRangeByName('S1.H337').Value = 10000
1876  else:
1877  oSheet.getCellRangeByName('S1.H337').Value = int(
1878  cfg.read('Computo', 'inizio_voci_abbreviate'))
1879  if oSheet.getCellRangeByName('S1.H338').Value < 10000:
1880  cfg.write('Computo', 'fine_voci_abbreviate', oSheet.getCellRangeByName('S1.H338').String)
1881  oSheet.getCellRangeByName('S1.H338').Value = 10000
1882  else:
1883  oSheet.getCellRangeByName('S1.H338').Value = int(cfg.read('Computo', 'fine_voci_abbreviate'))
1884 
1885  elif oSheet.Name == 'CONTABILITA':
1886  oSheet = oDoc.getSheets().getByName('S1')
1887  if oDoc.NamedRanges.hasByName("_Lib_1"):
1888  Dialogs.Exclamation(Title = 'ATTENZIONE!',
1889  Text='''Risulta già registrato un SAL, quindi
1890  NON E' POSSIBILE PROCEDERE.''')
1891  # ~DLG.MsgBox(
1892  # ~"Risulta già registrato un SAL. NON E' POSSIBILE PROCEDERE.",
1893  # ~'ATTENZIONE!')
1894  return
1895  else:
1896  if oSheet.getCellRangeByName('S1.H335').Value < 10000:
1897  cfg.write('Contabilita', 'cont_inizio_voci_abbreviate', oSheet.getCellRangeByName('S1.H335').String)
1898  oSheet.getCellRangeByName('S1.H335').Value = 10000
1899  else:
1900  oSheet.getCellRangeByName('S1.H335').Value = int(cfg.read('Contabilita', 'cont_inizio_voci_abbreviate'))
1901  if oSheet.getCellRangeByName('S1.H336').Value < 10000:
1902  cfg.write('Contabilita', 'cont_fine_voci_abbreviate', oSheet.getCellRangeByName('S1.H336').String)
1903  oSheet.getCellRangeByName('S1.H336').Value = 10000
1904  else:
1905  oSheet.getCellRangeByName('S1.H336').Value = int(cfg.read('Contabilita', 'cont_fine_voci_abbreviate'))
1907 
1908 
1909 
1910 
1911 
1913  '''
1914  Aggiunge suffisso al Codice Articolo
1915  '''
1916  testo = ''
1917  suffisso = InputBox(
1918  testo, t='Inserisci il suffisso per il Codice Articolo (es: "BAS22/1_").')
1919  if suffisso in (None, '', ' '):
1920  return
1921  oDoc = LeenoUtils.getDocument()
1922  oSheet = oDoc.CurrentController.ActiveSheet
1923  lrow = SheetUtils.getLastUsedRow(oSheet)
1924 
1925  # attiva la progressbar
1926  progress = Dialogs.Progress(Title='Operazione in corso...', Text="Progressione")
1927  n = 0
1928  progress.setLimits(n, lrow)
1929  progress.show()
1930  progress.setValue(0)
1931  for y in range(0, lrow):
1932  if oSheet.getCellByPosition(0, y).CellStyle == "EP-aS" and \
1933  oSheet.getCellByPosition(0, y).String != "000":
1934  oSheet.getCellByPosition(0, y).String = suffisso + oSheet.getCellByPosition(0, y).String
1935  progress.setValue(y)
1936  progress.hide()
1937 
1938 
1939 
1940 
1941 
1943  '''
1944  Cancella le voci di prezzo non utilizzate.
1945  '''
1947  chiudi_dialoghi()
1948 
1949  if Dialogs.YesNoDialog(Title='AVVISO!',
1950  Text='''Questo comando ripulisce l'Elenco Prezzi
1951 dalle voci non utilizzate in nessuno degli altri elaborati.
1952 
1953 LA PROCEDURA POTREBBE RICHIEDERE DEL TEMPO.
1954 
1955 Vuoi procedere comunque?''') == 0:
1956  return
1957  oDoc = LeenoUtils.getDocument()
1958  oDoc.enableAutomaticCalculation(False)
1959  oSheet = oDoc.CurrentController.ActiveSheet
1960 
1961  oRange = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
1962  SR = oRange.StartRow + 1
1963  ER = oRange.EndRow + 1
1964  lista_prezzi = list()
1965  for n in range(SR, ER):
1966  lista_prezzi.append(oSheet.getCellByPosition(0, n).String)
1967  lista = list()
1968  # attiva la progressbar
1969  progress = Dialogs.Progress(Title='Ricerca delle voci da eliminare in corso...', Text="Lettura dati")
1970  n = 0
1971  progress.setLimits(n, len(lista_prezzi))
1972  progress.show()
1973  progress.setValue(1)
1974  for tab in ('COMPUTO', 'Analisi di Prezzo', 'VARIANTE', 'CONTABILITA'):
1975  try:
1976  oSheet = oDoc.getSheets().getByName(tab)
1977  if tab == 'Analisi di Prezzo':
1978  col = 0
1979  else:
1980  col = 1
1981  for el in lista_prezzi:
1982  n += 1
1983  progress.setValue(n)
1984  if SheetUtils.uFindStringCol(el, col, oSheet):
1985  lista.append(el)
1986  except Exception:
1987  pass
1988  progress.setLimits(0, 5)
1989  progress.setValue(2)
1990  da_cancellare = set(lista_prezzi).difference(set(lista))
1991  oSheet = oDoc.CurrentController.ActiveSheet
1992  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
1993  iSheet = oSheet.RangeAddress.Sheet
1994  oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
1995  oCellRangeAddr.Sheet = iSheet
1996  progress.setValue(3)
1997  oDoc.CurrentController.select(oSheet.getCellRangeByPosition(0, SR, 0, ER))
1998  struttura_off()
1999  struttura_off()
2000  struttura_off()
2001  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) #'unselect
2002  progress.setValue(4)
2003 
2004  # ~for el in da_cancellare:
2005  # ~oCellRangeAddr.StartRow = el
2006  # ~oCellRangeAddr.EndRow = el
2007  # ~oSheet.group(oCellRangeAddr, 1)
2008  # ~oSheet.getCellRangeByPosition(0, el, 0,
2009  # ~el).Rows.IsVisible = False
2010 
2011  for n in reversed(range(SR, ER)):
2012  if oSheet.getCellByPosition(0, n).String in da_cancellare:
2013  oSheet.Rows.removeByIndex(n, 1)
2014  if(oSheet.getCellByPosition(0, n).String == '' and
2015  oSheet.getCellByPosition(1, n).String == '' and
2016  oSheet.getCellByPosition(4, n).String == ''):
2017  oSheet.Rows.removeByIndex(n, 1)
2018 
2019  progress.setValue(5)
2020  oDoc.enableAutomaticCalculation(True)
2021  progress.hide()
2022  _gotoCella(0, 3)
2024  Dialogs.Info(Title = 'Ricerca conclusa', Text='Eliminate ' + str(len(da_cancellare)) + " voci dall'elenco prezzi.")
2025 
2026 
2027 
2028 
2029 
2031  '''
2032  Ottimizza l'altezza delle celle di Elenco Prezzi o visualizza solo
2033  tre righe della descrizione.
2034  '''
2035  oDoc = LeenoUtils.getDocument()
2036  oSheet = oDoc.CurrentController.ActiveSheet
2037 
2038  oRange = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2039  SR = oRange.StartRow + 1
2040  ER = oRange.EndRow
2041 
2042  if not oSheet.getCellByPosition(1, 3).Rows.OptimalHeight:
2044  else:
2045  hriga = oSheet.getCellRangeByName(
2046  'B4').CharHeight * 65 * 2 + 100 # visualizza tre righe
2047  oSheet.getCellRangeByPosition(0, SR, 0, ER).Rows.Height = hriga
2048 
2049 
2050 
2051 
2052 
2054  '''
2055  Gestisce i dialoghi del menù viste nelle tabelle di Analisi di Prezzo,
2056  Elenco Prezzi, COMPUTO, VARIANTE, CONTABILITA'
2057  Genera i raffronti tra COMPUTO e VARIANTE e CONTABILITA'
2058  '''
2059  oDoc = LeenoUtils.getDocument()
2061  oSheet = oDoc.CurrentController.ActiveSheet
2062  psm = LeenoUtils.getComponentContext().ServiceManager
2063  dp = psm.createInstance('com.sun.star.awt.DialogProvider')
2064  global oDialog1
2065  if oSheet.Name in ('VARIANTE', 'COMPUTO'):
2066  oDialog1 = dp.createDialog(
2067  'vnd.sun.star.script:UltimusFree2.DialogViste_A?language=Basic&location=application'
2068  )
2069  # oDialog1Model = oDialog1.Model
2070  oDialog1.getControl('Dettaglio').State = cfg.read('Generale', 'dettaglio')
2071  if oSheet.getColumns().getByIndex(5).Columns.IsVisible:
2072  oDialog1.getControl('CBMis').State = 1
2073  if oSheet.getColumns().getByIndex(17).Columns.IsVisible:
2074  oDialog1.getControl('CBSic').State = 1
2075  if oSheet.getColumns().getByIndex(28).Columns.IsVisible:
2076  oDialog1.getControl('CBMat').State = 1
2077  if oSheet.getColumns().getByIndex(29).Columns.IsVisible:
2078  oDialog1.getControl('CBMdo').State = 1
2079  if oSheet.getColumns().getByIndex(31).Columns.IsVisible:
2080  oDialog1.getControl('CBCat').State = 1
2081  if oSheet.getColumns().getByIndex(38).Columns.IsVisible:
2082  oDialog1.getControl('CBFig').State = 1
2083 
2084  sString = oDialog1.getControl('TextField10')
2085  sString.Text = oDoc.getSheets().getByName('S1').getCellRangeByName(
2086  'H337').Value # inizio_voci_abbreviate
2087  sString = oDialog1.getControl('TextField11')
2088  sString.Text = oDoc.getSheets().getByName('S1').getCellRangeByName(
2089  'H338').Value # fine_voci_abbreviate
2090 
2091  oDialog1.execute()
2092 
2093  # il salvataggio anche su leeno.conf serve alla funzione voce_breve()
2094  if oDialog1.getControl('TextField10').getText() != '10000':
2095  cfg.write('Computo', 'inizio_voci_abbreviate', oDialog1.getControl('TextField10').getText())
2096  oDoc.getSheets().getByName('S1').getCellRangeByName('H337').Value = float(oDialog1.getControl('TextField10').getText())
2097 
2098  if oDialog1.getControl('TextField11').getText() != '10000':
2099  cfg.write('Computo', 'fine_voci_abbreviate', oDialog1.getControl('TextField11').getText())
2100  oDoc.getSheets().getByName('S1').getCellRangeByName('H338').Value = float(oDialog1.getControl('TextField11').getText())
2101  # oDialog1.getControl('CBMdo').State = False
2102  # if oSheet.getColumns().getByIndex(29).Columns.IsVisible:
2103  # oDialog1.getControl('CBMdo').State = True
2104 
2105  if oDialog1.getControl('OBTerra').State:
2107  oDialog1.getControl('CBSic').State = 0
2108  oDialog1.getControl('CBMdo').State = 0
2109  oDialog1.getControl('CBMat').State = 0
2110  oDialog1.getControl('CBCat').State = 0
2111  oDialog1.getControl('CBFig').State = 0
2112  oDialog1.getControl('CBMis').State = 1
2113 
2114  if oDialog1.getControl("CBMis").State == 0: # misure
2115  oSheet.getColumns().getByIndex(5).Columns.IsVisible = False
2116  oSheet.getColumns().getByIndex(6).Columns.IsVisible = False
2117  oSheet.getColumns().getByIndex(7).Columns.IsVisible = False
2118  oSheet.getColumns().getByIndex(8).Columns.IsVisible = False
2119  else:
2120  oSheet.getColumns().getByIndex(5).Columns.IsVisible = True
2121  oSheet.getColumns().getByIndex(6).Columns.IsVisible = True
2122  oSheet.getColumns().getByIndex(7).Columns.IsVisible = True
2123  oSheet.getColumns().getByIndex(8).Columns.IsVisible = True
2124 
2125  if oDialog1.getControl('CBMdo').State: # manodopera
2126  oSheet.getColumns().getByIndex(29).Columns.IsVisible = True
2127  oSheet.getColumns().getByIndex(30).Columns.IsVisible = True
2128  oSheet.getColumns().getByIndex(5).Columns.IsVisible = False
2129  oSheet.getColumns().getByIndex(6).Columns.IsVisible = False
2130  oSheet.getColumns().getByIndex(7).Columns.IsVisible = False
2131  oSheet.getColumns().getByIndex(8).Columns.IsVisible = False
2132  # LeenoSheetUtils.adattaAltezzaRiga(oSheet)
2133  oSheet.clearOutline()
2134  struct(3)
2135  else:
2136  oSheet.getColumns().getByIndex(29).Columns.IsVisible = False
2137  oSheet.getColumns().getByIndex(30).Columns.IsVisible = False
2138 
2139  if oDialog1.getControl('CBMat').State == 0: # materiali
2140  oSheet.getColumns().getByIndex(28).Columns.IsVisible = False
2141 
2142  else:
2143  oSheet.getColumns().getByIndex(28).Columns.IsVisible = True
2144 
2145  if oDialog1.getControl('CBCat').State == 0: # categorie
2146  oSheet.getColumns().getByIndex(31).Columns.IsVisible = False
2147  oSheet.getColumns().getByIndex(32).Columns.IsVisible = False
2148  oSheet.getColumns().getByIndex(33).Columns.IsVisible = False
2149  else:
2150  oSheet.getColumns().getByIndex(31).Columns.IsVisible = True
2151  oSheet.getColumns().getByIndex(32).Columns.IsVisible = True
2152  oSheet.getColumns().getByIndex(33).Columns.IsVisible = True
2153 
2154  if oDialog1.getControl("CBSic").State == 0: # sicurezza
2155  oSheet.getColumns().getByIndex(17).Columns.IsVisible = False
2156  else:
2157  oSheet.getColumns().getByIndex(17).Columns.IsVisible = True
2158 
2159  if oDialog1.getControl("CBFig").State == 0: # figure
2160  oSheet.getColumns().getByIndex(38).Columns.IsVisible = False
2161  else:
2162  oSheet.getColumns().getByIndex(38).Columns.IsVisible = True
2163 
2164  if oDialog1.getControl('Dettaglio').State == 0: #
2165  cfg.write('Generale', 'dettaglio', '0')
2166  dettaglio_misure(0)
2167  else:
2168  cfg.write('Generale', 'dettaglio', '1')
2169  dettaglio_misure(0)
2170  dettaglio_misure(1)
2171  elif oSheet.Name in ('Elenco Prezzi'):
2172  oCellRangeAddr = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2173  oDialog1 = dp.createDialog(
2174  "vnd.sun.star.script:UltimusFree2.DialogViste_EP?language=Basic&location=application"
2175  )
2176  # oDialog1Model = oDialog1.Model
2177 
2178  if oSheet.getColumns().getByIndex(3).Columns.IsVisible:
2179  oDialog1.getControl('CBSic').State = 1
2180  if oSheet.getColumns().getByIndex(5).Columns.IsVisible:
2181  oDialog1.getControl('CBMdo').State = 1
2182  if not oSheet.getCellByPosition(1, 3).Rows.OptimalHeight:
2183  oDialog1.getControl('CBDesc').State = 1
2184  if oSheet.getColumns().getByIndex(7).Columns.IsVisible:
2185  oDialog1.getControl('CBOrig').State = 1
2186  if oDialog1.execute() == 1:
2187  if oDialog1.getControl("CBSic").State == 0: # sicurezza
2188  oSheet.getColumns().getByIndex(3).Columns.IsVisible = False
2189  else:
2190  oSheet.getColumns().getByIndex(3).Columns.IsVisible = True
2191 
2192  if oDialog1.getControl("CBMdo").State == 0: # manodopera
2193  oSheet.getColumns().getByIndex(5).Columns.IsVisible = False
2194  oSheet.getColumns().getByIndex(6).Columns.IsVisible = False
2195  else:
2196  oSheet.getColumns().getByIndex(5).Columns.IsVisible = True
2197  oSheet.getColumns().getByIndex(6).Columns.IsVisible = True
2198 
2199  if oDialog1.getControl("CBDesc").State == 1: # descrizione
2200  oSheet.getColumns().getByIndex(3).Columns.IsVisible = False
2201  oSheet.getCellByPosition(1, 3).Rows.OptimalHeight
2202  voce_breve_ep()
2203  # elif oDialog1.getControl("CBDesc").State == 0: LeenoSheetUtils.adattaAltezzaRiga(oSheet)
2204 
2205  if oDialog1.getControl("CBOrig").State == 0: # origine
2206  oSheet.getColumns().getByIndex(7).Columns.IsVisible = False
2207  else:
2208  oSheet.getColumns().getByIndex(7).Columns.IsVisible = True
2209 
2210  if oDialog1.getControl("CBSom").State == 1:
2211  genera_sommario()
2212 
2213  oRangeAddress = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2214  SR = oRangeAddress.StartRow + 1
2215  ER = oRangeAddress.EndRow # -1
2216 
2217  oSheet.getCellRangeByPosition(11, 0, 26,
2218  0).Columns.IsVisible = True
2219  oSheet.getCellRangeByPosition(23, SR, 25,
2220  ER).CellStyle = 'EP statistiche'
2221  oSheet.getCellRangeByPosition(26, SR, 26,
2222  ER).CellStyle = 'EP-mezzo %'
2223  oSheet.getCellRangeByName('AA2').CellStyle = 'EP-mezzo %'
2224  formule = list()
2225  oSheet.getCellByPosition(11, 0).String = 'COMPUTO'
2226  oSheet.getCellByPosition(15, 0).String = 'VARIANTE'
2227  oSheet.getCellByPosition(19, 0).String = "CONTABILITA"
2228  if oDialog1.getControl("ComVar").State: # Computo - Variante
2229  genera_sommario()
2230  oRangeAddress.StartColumn = 19
2231  oRangeAddress.EndColumn = 22
2232 
2233  oSheet.getCellByPosition(23, 0).String = 'COMPUTO - VARIANTE'
2234  for n in range(4, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2):
2235  formule.append([
2236  '=IF(Q' + str(n) + '-M' + str(n) + '=0;"--";Q' +
2237  str(n) + '-M' + str(n) + ')', '=IF(R' + str(n) + '-N' +
2238  str(n) + '>0;R' + str(n) + '-N' + str(n) + ';"")',
2239  '=IF(R' + str(n) + '-N' + str(n) + '<0;N' + str(n) +
2240  '-R' + str(n) + ';"")', '=IFERROR(IFS(AND(N' + str(n) +
2241  '>R' + str(n) + ';R' + str(n) + '=0);-1;AND(N' +
2242  str(n) + '<R' + str(n) + ';N' + str(n) + '=0);1;N' +
2243  str(n) + '=R' + str(n) + ';"--";N' + str(n) + '>R' +
2244  str(n) + ';-(N' + str(n) + '-R' + str(n) + ')/N' +
2245  str(n) + ';N' + str(n) + '<R' + str(n) + ';-(N' +
2246  str(n) + '-R' + str(n) + ')/N' + str(n) + ');"--")'
2247  ])
2248  n += 1
2249  oSheet.getCellByPosition(
2250  26, 1
2251  ).Formula = '=IFERROR(IFS(AND(N2>R2;R2=0);-1;AND(N2<R2;N2=0);1;N2=R2;"--";N2>R2;-(N2-R2)/N2;N2<R2;-(N2-R2)/N2);"--")'
2252  oSheet.getCellByPosition(
2253  26, ER
2254  ).Formula = '=IFERROR(IFS(AND(N' + str(n) + '>R' + str(
2255  n) + ';R' + str(n) + '=0);-1;AND(N' + str(n) + '<R' + str(
2256  n) + ';N' + str(n) + '=0);1;N' + str(n) + '=R' + str(
2257  n) + ';"--";N' + str(n) + '>R' + str(
2258  n) + ';-(N' + str(n) + '-R' + str(
2259  n) + ')/N' + str(n) + ';N' + str(
2260  n) + '<R' + str(n) + ';-(N' + str(
2261  n) + '-R' + str(n) + ')/N' + str(
2262  n) + ');"--")'
2263  oRange = oSheet.getCellRangeByPosition(23, 3, 26,
2265  formule = tuple(formule)
2266  oRange.setFormulaArray(formule)
2267 
2268  if oRangeAddress.StartColumn != 0:
2269  oCellRangeAddr.StartColumn = 18
2270  oCellRangeAddr.EndColumn = 21
2271  oSheet.group(oCellRangeAddr, 0)
2272  oSheet.getCellRangeByPosition(18, 0, 21,
2273  0).Columns.IsVisible = False
2274 
2275  oCellRangeAddr.StartColumn = 15
2276  oCellRangeAddr.EndColumn = 15
2277  oSheet.group(oCellRangeAddr, 0)
2278  oSheet.getCellRangeByPosition(15, 0, 15,
2279  0).Columns.IsVisible = False
2280 
2281 
2282  if oDialog1.getControl("ComCon").State: # Computo - Contabilità
2283  genera_sommario()
2284  oRangeAddress.StartColumn = 15
2285  oRangeAddress.EndColumn = 18
2286 
2287  oSheet.getCellByPosition(23,
2288  0).String = 'COMPUTO - CONTABILITÀ'
2289  for n in range(4, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2):
2290  formule.append([
2291  '=IF(U' + str(n) + '-M' + str(n) + '=0;"--";U' +
2292  str(n) + '-M' + str(n) + ')', '=IF(V' + str(n) + '-N' +
2293  str(n) + '>0;V' + str(n) + '-N' + str(n) + ';"")',
2294  '=IF(V' + str(n) + '-N' + str(n) + '<0;N' + str(n) +
2295  '-V' + str(n) + ';"")', '=IFERROR(IFS(AND(N' + str(n) +
2296  '>V' + str(n) + ';V' + str(n) + '=0);-1;AND(N' +
2297  str(n) + '<V' + str(n) + ';N' + str(n) + '=0);1;N' +
2298  str(n) + '=V' + str(n) + ';"--";N' + str(n) + '>V' +
2299  str(n) + ';-(N' + str(n) + '-V' + str(n) + ')/N' +
2300  str(n) + ';N' + str(n) + '<V' + str(n) + ';-(N' +
2301  str(n) + '-V' + str(n) + ')/N' + str(n) + ');"--")'
2302  ])
2303  n += 1
2304  # for el in(1, ER+1):
2305  oSheet.getCellByPosition(
2306  26, 1
2307  ).Formula = '=IFERROR(IFS(AND(N2>V2;V2=0);-1;AND(N2<V2;N2=0);1;N2=V2;"--";N2>V2;-(N2-V2)/N2;N2<V2;-(N2-V2)/N2);"--")'
2308  oSheet.getCellByPosition(
2309  26, ER
2310  ).Formula = '=IFERROR(IFS(AND(N' + str(n) + '>V' + str(
2311  n) + ';V' + str(n) + '=0);-1;AND(N' + str(n) + '<V' + str(
2312  n) + ';N' + str(n) + '=0);1;N' + str(n) + '=V' + str(
2313  n) + ';"--";N' + str(n) + '>V' + str(
2314  n) + ';-(N' + str(n) + '-V' + str(
2315  n) + ')/N' + str(n) + ';N' + str(
2316  n) + '<V' + str(n) + ';-(N' + str(
2317  n) + '-V' + str(n) + ')/N' + str(
2318  n) + ');"--")'
2319  oRange = oSheet.getCellRangeByPosition(23, 3, 26,
2321  formule = tuple(formule)
2322  oRange.setFormulaArray(formule)
2323 
2324  if oRangeAddress.StartColumn != 0:
2325  # evidenzia le quantità eccedenti il VI/I
2326  for el in range(3, SheetUtils.getUsedArea(oSheet).EndRow):
2327  if oSheet.getCellByPosition(
2328  26,
2329  el).Value >= 0.2 or oSheet.getCellByPosition(
2330  26, el).String == '20,00%':
2331  oSheet.getCellRangeByPosition(
2332  0, el, 25, el).CellBackColor = 16777062
2333  # oCellRangeAddr=oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2334  if DLG.DlgSiNo(
2335  "Nascondo eventuali voci non ancora contabilizzate?"
2336  ) == 2:
2337  struttura_off()
2338  for el in range(3, SheetUtils.getUsedArea(oSheet).EndRow):
2339  if oSheet.getCellByPosition(20, el).Value == 0:
2340  oCellRangeAddr.StartRow = el
2341  oCellRangeAddr.EndRow = el
2342  oSheet.group(oCellRangeAddr, 1)
2343  oSheet.getCellRangeByPosition(
2344  0, el, 1, el).Rows.IsVisible = False
2345 
2346  oCellRangeAddr.StartColumn = 5
2347  oCellRangeAddr.EndColumn = 11
2348  oSheet.group(oCellRangeAddr, 0)
2349  oSheet.getCellRangeByPosition(5, 0, 11,
2350  0).Columns.IsVisible = False
2351  oCellRangeAddr.StartColumn = 15
2352  oCellRangeAddr.EndColumn = 19
2353  oSheet.group(oCellRangeAddr, 0)
2354  oSheet.getCellRangeByPosition(15, 0, 19,
2355  0).Columns.IsVisible = False
2356 
2357 
2358  if oDialog1.getControl(
2359  "VarCon").State: # Variante - Contabilità
2360  genera_sommario()
2361 
2362  oRangeAddress.StartColumn = 11
2363  oRangeAddress.EndColumn = 14
2364 
2365  oSheet.getCellByPosition(23,
2366  0).String = 'VARIANTE - CONTABILITÀ'
2367  for n in range(4, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2):
2368  formule.append([
2369  '=IF(U' + str(n) + '-Q' + str(n) + '=0;"--";U' +
2370  str(n) + '-Q' + str(n) + ')', '=IF(V' + str(n) + '-R' +
2371  str(n) + '>0;V' + str(n) + '-R' + str(n) + ';"")',
2372  '=IF(V' + str(n) + '-R' + str(n) + '<0;R' + str(n) +
2373  '-V' + str(n) + ';"")', '=IFERROR(IFS(AND(R' + str(n) +
2374  '>V' + str(n) + ';V' + str(n) + '=0);-1;AND(R' +
2375  str(n) + '<V' + str(n) + ';R' + str(n) + '=0);1;R' +
2376  str(n) + '=V' + str(n) + ';"--";R' + str(n) + '>V' +
2377  str(n) + ';-(R' + str(n) + '-V' + str(n) + ')/R' +
2378  str(n) + ';R' + str(n) + '<V' + str(n) + ';-(R' +
2379  str(n) + '-V' + str(n) + ')/R' + str(n) + ');"--")'
2380  ])
2381  n += 1
2382  # for el in(1, ER+1):
2383  oSheet.getCellByPosition(
2384  26, 1
2385  ).Formula = '=IFERROR(IFS(AND(R2>V2;V2=0);-1;AND(R2<V2;R2=0);1;R2=V2;"--";R2>V2;-(R2-V2)/R2;R2<V2;-(R2-V2)/R2);"--")'
2386  oSheet.getCellByPosition(
2387  26, ER
2388  ).Formula = '=IFERROR(IFS(AND(R' + str(n) + '>V' + str(
2389  n) + ';V' + str(n) + '=0);-1;AND(R' + str(n) + '<V' + str(
2390  n) + ';R' + str(n) + '=0);1;R' + str(n) + '=V' + str(
2391  n) + ';"--";R' + str(n) + '>V' + str(
2392  n) + ';-(R' + str(n) + '-V' + str(
2393  n) + ')/R' + str(n) + ';R' + str(
2394  n) + '<V' + str(n) + ';-(R' + str(
2395  n) + '-V' + str(n) + ')/R' + str(
2396  n) + ');"--")'
2397  oRange = oSheet.getCellRangeByPosition(23, 3, 26,
2399  formule = tuple(formule)
2400  oRange.setFormulaArray(formule)
2401  # operazioni comuni
2402  for el in (11, 15, 19, 26):
2403  oSheet.getCellRangeByPosition(
2404  el, 3, el, LeenoSheetUtils.cercaUltimaVoce(oSheet)).CellStyle = 'EP-mezzo %'
2405  for el in (12, 16, 20, 23):
2406  oSheet.getCellRangeByPosition(
2407  el, 3, el,
2408  LeenoSheetUtils.cercaUltimaVoce(oSheet)).CellStyle = 'EP statistiche_q'
2409  for el in (13, 17, 21, 24, 25):
2410  oSheet.getCellRangeByPosition(
2411  el, 3, el,
2412  LeenoSheetUtils.cercaUltimaVoce(oSheet)).CellStyle = 'EP statistiche'
2413  oCellRangeAddr.StartColumn = 3
2414  oCellRangeAddr.EndColumn = 3
2415  oSheet.group(oCellRangeAddr, 0)
2416  oSheet.getCellRangeByPosition(3, 0, 3, 0).Columns.IsVisible = False
2417  oCellRangeAddr.StartColumn = 5
2418  oCellRangeAddr.EndColumn = 11
2419  oSheet.group(oCellRangeAddr, 0)
2420  oSheet.getCellRangeByPosition(5, 0, 11,
2421  0).Columns.IsVisible = False
2422 
2423  oDoc.CurrentController.select(oSheet.getCellRangeByName('AA2'))
2424  # oDoc.CurrentController.select(oDoc.getSheets().getByName('S5').getCellRangeByName('B30'))
2425  comando('Copy')
2426  oDoc.CurrentController.select(
2427  oSheet.getCellRangeByPosition(26, 3, 26, ER))
2428  paste_format()
2429 
2430  if(oDialog1.getControl("ComVar").State or
2431  oDialog1.getControl("ComCon").State or
2432  oDialog1.getControl("VarCon").State):
2433  if DLG.DlgSiNo("Nascondo eventuali righe con scostamento nullo?") == 2:
2434  errori = ('#DIV/0!', '--')
2435  hide_error(errori, 26)
2436  oSheet.group(oRangeAddress, 0)
2437  oSheet.getCellRangeByPosition(oRangeAddress.StartColumn, 0,
2438  oRangeAddress.EndColumn,
2439  1).Columns.IsVisible = False
2440  _primaCella()
2441  else:
2442  return
2443  elif oSheet.Name in ('Analisi di Prezzo'):
2444  oDialog1 = dp.createDialog(
2445  "vnd.sun.star.script:UltimusFree2.DialogViste_AN?language=Basic&location=application"
2446  )
2447  # oDialog1Model = oDialog1.Model
2448  if not oSheet.getCellByPosition(1, 2).Rows.OptimalHeight:
2449  oDialog1.getControl("CBDesc").State = 1 # descrizione breve
2450 
2451  oS1 = oDoc.getSheets().getByName('S1')
2452  sString = oDialog1.getControl('TextField5')
2453  sString.Text = oS1.getCellRangeByName(
2454  'S1.H319').Value * 100 # sicurezza
2455  sString = oDialog1.getControl('TextField6')
2456  sString.Text = oS1.getCellRangeByName(
2457  'S1.H320').Value * 100 # spese_generali
2458  sString = oDialog1.getControl('TextField7')
2459  sString.Text = oS1.getCellRangeByName(
2460  'S1.H321').Value * 100 # utile_impresa
2461 
2462  # accorpa_spese_utili
2463  if oS1.getCellRangeByName('S1.H323').Value == 1:
2464  oDialog1.getControl('CheckBox4').State = 1
2465  sString = oDialog1.getControl('TextField8')
2466  sString.Text = oS1.getCellRangeByName('S1.H324').Value * 100 # sconto
2467  sString = oDialog1.getControl('TextField9')
2468  sString.Text = oS1.getCellRangeByName(
2469  'S1.H326').Value * 100 # maggiorazione
2470 
2471  oDialog1.execute() # mostra il dialogo
2472 
2473  if(oSheet.getCellByPosition(1, 2).Rows.OptimalHeight and
2474  oDialog1.getControl("CBDesc").State == 1): # descrizione breve
2475  basic_LeenO('Strutture.Tronca_Altezza_Analisi')
2476  # elif oDialog1.getControl("CBDesc").State == 0: LeenoSheetUtils.adattaAltezzaRiga(oSheet)
2477 
2478  # sString.Text =oSheet.getCellRangeByName('S1.H321').Value * 100 #utile_impresa
2479  oS1.getCellRangeByName('S1.H319').Value = float(
2480  oDialog1.getControl('TextField5').getText().replace(
2481  ',', '.')) / 100 # sicurezza
2482  oS1.getCellRangeByName('S1.H320').Value = float(
2483  oDialog1.getControl('TextField6').getText().replace(
2484  ',', '.')) / 100 # spese generali
2485  oS1.getCellRangeByName('S1.H321').Value = float(
2486  oDialog1.getControl('TextField7').getText().replace(
2487  ',', '.')) / 100 # utile_impresa
2488  oS1.getCellRangeByName('S1.H323').Value = oDialog1.getControl(
2489  'CheckBox4').State
2490  oS1.getCellRangeByName('S1.H324').Value = float(
2491  oDialog1.getControl('TextField8').getText().replace(
2492  ',', '.')) / 100 # sconto
2493  oS1.getCellRangeByName('S1.H326').Value = float(
2494  oDialog1.getControl('TextField9').getText().replace(
2495  ',', '.')) / 100 # maggiorazione
2496 
2497  # accorpa_spese_utili
2498  if oS1.getCellRangeByName('S1.H323').Value == 1:
2499  oDialog1.getControl('CheckBox4').State = 1
2500  sString = oDialog1.getControl('TextField8')
2501  sString.Text = oS1.getCellRangeByName('S1.H324').Value * 100 # sconto
2502  sString = oDialog1.getControl('TextField9')
2503  sString.Text = oS1.getCellRangeByName(
2504  'S1.H326').Value * 100 # maggiorazione
2505 
2506  elif oSheet.Name in ('CONTABILITA', 'Registro', 'SAL'):
2507  oDialog1 = dp.createDialog(
2508  "vnd.sun.star.script:UltimusFree2.Dialogviste_N?language=Basic&location=application"
2509  )
2510  if oSheet.getColumns().getByIndex(19).Columns.IsVisible:
2511  oDialog1.getControl('vista_pre').State = 1
2512  else:
2513  oDialog1.getControl('vista_sem').State = 1
2514  sString = oDialog1.getControl('TextField3')
2515  sString.Text = oDoc.getSheets().getByName('S1').getCellRangeByName(
2516  'H335').Value # cont_inizio_voci_abbreviate
2517  sString = oDialog1.getControl('TextField2')
2518  sString.Text = oDoc.getSheets().getByName('S1').getCellRangeByName(
2519  'H336').Value # cont_fine_voci_abbreviate
2520 
2521  # Contabilità abilita
2522  # ~if oSheet.getCellRangeByName('S1.H328').Value == 1:
2523  # ~oDialog1.getControl('CheckBox7').State = 1
2524  sString = oDialog1.getControl('TextField13')
2525  if cfg.read('Contabilita', 'idxsal') == '&273.Dlg_config.TextField13.Text':
2526  sString.Text = '20'
2527  else:
2528  sString.Text = cfg.read('Contabilita', 'idxsal')
2529  if sString.Text == '':
2530  sString.Text = '20'
2531  sString = oDialog1.getControl('ComboBox3')
2532  sString.Text = cfg.read('Contabilita', 'ricicla_da')
2533 
2534  # oDialog1Model = oDialog1.Model
2535  oDialog1.getControl('Dettaglio').State = cfg.read('Generale', 'dettaglio')
2536  oDialog1.execute()
2537 
2538  if oDialog1.getControl('vista_pre').State:
2540  if oDialog1.getControl('vista_sem').State:
2541  LeenoSheetUtils.setVisibilitaColonne(oSheet, 'TTTFFTTTTTFTFTFTFFFFFFFFFFFFFFFFFFFFF')
2542  # ~vista_terra_terra()
2543 
2544  # il salvataggio anche su leeno.conf serve alla funzione voce_breve()
2545  if oDialog1.getControl('TextField3').getText() != '10000':
2546  cfg.write('Contabilita', 'cont_inizio_voci_abbreviate', oDialog1.getControl('TextField3').getText())
2547  oDoc.getSheets().getByName('S1').getCellRangeByName('H335').Value = float(oDialog1.getControl('TextField3').getText())
2548 
2549  if oDialog1.getControl('TextField2').getText() != '10000':
2550  cfg.write('Contabilita', 'cont_fine_voci_abbreviate', oDialog1.getControl('TextField2').getText())
2551  oDoc.getSheets().getByName('S1').getCellRangeByName('H336').Value = float(oDialog1.getControl('TextField2').getText())
2552 
2553  cfg.write('Contabilita', 'idxsal', oDialog1.getControl('TextField13').getText())
2554  if oDialog1.getControl('ComboBox3').getText() in ('COMPUTO', '&305.Dlg_config.ComboBox3.Text'):
2555  cfg.write('Contabilita', 'ricicla_da', 'COMPUTO')
2556  else:
2557  cfg.write('Contabilita', 'ricicla_da', 'VARIANTE')
2558 
2559  if oDialog1.getControl('Dettaglio').State == 0:
2560  cfg.write('Generale', 'dettaglio', '0')
2561  dettaglio_misure(0)
2562  else:
2563  cfg.write('Generale', 'dettaglio', '1')
2564  dettaglio_misure(0)
2565  dettaglio_misure(1)
2566  # LeenoSheetUtils.adattaAltezzaRiga(oSheet)
2568  # ~oDoc.enableAutomaticCalculation(True)
2569  # MsgBox('Operazione eseguita con successo!','')
2570 
2571 
2572 
2573 
2574 
2576  '''
2577  Genera il foglio di VARIANTE a partire dal COMPUTO
2578  @@@ MODIFICA IN CORSO CON 'LeenoVariante.generaVariante'
2579  '''
2580  chiudi_dialoghi()
2581  oDoc = LeenoUtils.getDocument()
2582  if not oDoc.getSheets().hasByName('VARIANTE'):
2583  if oDoc.NamedRanges.hasByName("AA"):
2584  oDoc.NamedRanges.removeByName("AA")
2585  oDoc.NamedRanges.removeByName("BB")
2586  oDoc.Sheets.copyByName('COMPUTO', 'VARIANTE', 4)
2587  oSheet = oDoc.getSheets().getByName('COMPUTO')
2588  lrow = SheetUtils.getUsedArea(oSheet).EndRow
2589  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$AJ$3:$AJ$' + str(lrow), 'AA')
2590  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$N$3:$N$' + str(lrow), "BB")
2591  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$AK$3:$AK$' + str(lrow), "cEuro")
2592  oSheet = oDoc.getSheets().getByName('VARIANTE')
2593  GotoSheet('VARIANTE')
2594  setTabColor(16777062)
2595  oSheet.getCellByPosition(2, 0).String = "VARIANTE"
2596  oSheet.getCellByPosition(2, 0).CellStyle = "comp Int_colonna"
2597  oSheet.getCellRangeByName("C1").CellBackColor = 16777062
2598  oSheet.getCellRangeByPosition(0, 2, 42, 2).CellBackColor = 16777062
2599  if DLG.DlgSiNo(
2600  """Vuoi svuotare la VARIANTE appena generata?
2601 
2602 Se decidi di continuare, cancellerai tutte le voci di
2603 misurazione già presenti in questo elaborato.
2604 Cancello le voci di misurazione?
2605  """, 'ATTENZIONE!') == 2:
2606  lrow = SheetUtils.uFindStringCol('TOTALI COMPUTO', 2, oSheet) - 3
2607  oSheet.Rows.removeByIndex(3, lrow)
2608  _gotoCella(0, 2)
2610  oSheet = oDoc.getSheets().getByName('VARIANTE')
2612  # else:
2613  GotoSheet('VARIANTE')
2617 
2618 
2619 
2620 
2621 
2623  '''
2624  Genera i sommari in Elenco Prezzi
2625  '''
2626  struttura_off()
2627 
2628  oDoc = LeenoUtils.getDocument()
2629  oDoc.enableAutomaticCalculation(False)
2630  oSheet = oDoc.getSheets().getByName('COMPUTO')
2631  lrow = SheetUtils.getUsedArea(oSheet).EndRow
2632  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$AJ$3:$AJ$' + str(lrow), 'AA')
2633  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$N$3:$N$' + str(lrow), "BB")
2634  SheetUtils.NominaArea(oDoc, 'COMPUTO', '$AK$3:$AK$' + str(lrow), "cEuro")
2635 
2636  if oDoc.getSheets().hasByName('VARIANTE'):
2637  oSheet = oDoc.getSheets().getByName('VARIANTE')
2638  lrow = SheetUtils.getUsedArea(oSheet).EndRow
2639  SheetUtils.NominaArea(oDoc, 'VARIANTE', '$AJ$3:$AJ$' + str(lrow), 'varAA')
2640  SheetUtils.NominaArea(oDoc, 'VARIANTE', '$N$3:$N$' + str(lrow), "varBB")
2641  SheetUtils.NominaArea(oDoc, 'VARIANTE', '$AK$3:$AK$' + str(lrow), "varEuro")
2642 
2643  if oDoc.getSheets().hasByName('CONTABILITA'):
2644  oSheet = oDoc.getSheets().getByName('CONTABILITA')
2645  lrow = SheetUtils.getUsedArea(oSheet).EndRow
2646  lrow = SheetUtils.getUsedArea(
2647  oDoc.getSheets().getByName('CONTABILITA')).EndRow
2648  SheetUtils.NominaArea(oDoc, 'CONTABILITA', '$AJ$3:$AJ$' + str(lrow), 'GG')
2649  SheetUtils.NominaArea(oDoc, 'CONTABILITA', '$S$3:$S$' + str(lrow), "G1G1")
2650  SheetUtils.NominaArea(oDoc, 'CONTABILITA', '$AK$3:$AK$' + str(lrow), "conEuro")
2651 
2652  formule = list()
2653  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
2654 
2655  # attiva la progressbar
2656  progress = Dialogs.Progress(Title='Generazione dei sommari in corso...', Text="Lettura dati")
2657  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2)
2658  progress.setValue(0)
2659  progress.show()
2660 
2661  for n in range(4, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2):
2662  progress.setValue(n)
2663  stringa = ([
2664  '=N' + str(n) + '/$N$2', '=SUMIF(AA;A' + str(n) + ';BB)',
2665  '=SUMIF(AA;A' + str(n) + ';cEuro)', '', '', '', '', '', '', '', ''
2666  ])
2667  if oDoc.getSheets().hasByName('VARIANTE'):
2668  stringa = ([
2669  '=N' + str(n) + '/$N$2', '=SUMIF(AA;A' + str(n) + ';BB)',
2670  '=SUMIF(AA;A' + str(n) + ';cEuro)', '',
2671  '=R' + str(n) + '/$R$2', '=SUMIF(varAA;A' + str(n) + ';varBB)',
2672  '=SUMIF(varAA;A' + str(n) + ';varEuro)', '', '', '', ''
2673  ])
2674  if oDoc.getSheets().hasByName('CONTABILITA'):
2675  stringa = ([
2676  '=N' + str(n) + '/$N$2', '=SUMIF(AA;A' + str(n) + ';BB)',
2677  '=SUMIF(AA;A' + str(n) + ';cEuro)', '',
2678  '=R' + str(n) + '/$R$2',
2679  '=SUMIF(varAA;A' + str(n) + ';varBB)',
2680  '=SUMIF(varAA;A' + str(n) + ';varEuro)', '',
2681  '=V' + str(n) + '/$V$2', '=SUMIF(GG;A' + str(n) + ';G1G1)',
2682  '=SUMIF(GG;A' + str(n) + ';conEuro)'
2683  ])
2684  elif oDoc.getSheets().hasByName('CONTABILITA'):
2685  stringa = ([
2686  '=N' + str(n) + '/$N$2', '=SUMIF(AA;A' + str(n) + ';BB)',
2687  '=SUMIF(AA;A' + str(n) + ';cEuro)', '', '', '', '', '',
2688  '=V' + str(n) + '/$V$2', '=SUMIF(GG;A' + str(n) + ';G1G1)',
2689  '=SUMIF(GG;A' + str(n) + ';conEuro)'
2690  ])
2691  formule.append(stringa)
2692  oRange = oSheet.getCellRangeByPosition(11, 3, 21, LeenoSheetUtils.cercaUltimaVoce(oSheet))
2693  formule = tuple(formule)
2694  oRange.setFormulaArray(formule)
2695 
2696  oDoc.enableAutomaticCalculation(True)
2698  progress.hide()
2699 
2700 
2701 
2702 
2704  '''
2705  Riordina l'Elenco Prezzi secondo l'ordine alfabetico dei codici di prezzo
2706  '''
2707  oDoc = LeenoUtils.getDocument()
2708  oDoc.enableAutomaticCalculation(False)
2709  riordina_ElencoPrezzi(oDoc)
2710  oDoc.enableAutomaticCalculation(True)
2711 
2712 
2714  '''
2715  Riordina l'Elenco Prezzi secondo l'ordine alfabetico dei codici di prezzo
2716  '''
2717  #chiudi_dialoghi()
2718  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
2719  if SheetUtils.uFindStringCol('Fine elenco', 0, oSheet) is None:
2721  test = str(SheetUtils.uFindStringCol('Fine elenco', 0, oSheet) +1)
2722  SheetUtils.NominaArea(oDoc, 'Elenco Prezzi', "$A$3:$AF$" + test, 'elenco_prezzi')
2723  SheetUtils.NominaArea(oDoc, 'Elenco Prezzi', "$A$3:$A$" + test, 'Lista')
2724  oRangeAddress = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2725  SR = oRangeAddress.StartRow + 1
2726  SC = 0 #oRangeAddress.StartColumn
2727  EC = oRangeAddress.EndColumn
2728  SR = oRangeAddress.StartRow + 1
2729  ER = oRangeAddress.EndRow -1
2730  if SR == ER:
2731  return
2732 
2733  oRange = oSheet.getCellRangeByPosition(SC, SR, EC, ER)
2734  SheetUtils.simpleSortColumn(oRange, 0, True)
2735 
2736 
2737 
2738 
2739 
2741  # ~EliminaVociDoppieElencoPrezzi()
2743 
2744 
2746  oDoc = LeenoUtils.getDocument()
2747  '''
2748  Cancella eventuali voci che si ripetono in Elenco Prezzi
2749  '''
2751  if oDoc.getSheets().hasByName('Analisi di Prezzo'):
2752  lista_tariffe_analisi = list()
2753  oSheet = oDoc.getSheets().getByName('Analisi di Prezzo')
2754  for n in range(0, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1):
2755  if oSheet.getCellByPosition(0, n).CellStyle == 'An-1_sigla':
2756  lista_tariffe_analisi.append(
2757  oSheet.getCellByPosition(0, n).String)
2758  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
2759 
2760  SR = 0
2761  ER = SheetUtils.getUsedArea(oSheet).EndRow
2762 
2763  try:
2764  lista_tariffe_analisi
2765  for i in reversed(range(SR, ER)):
2766  if oSheet.getCellByPosition(0, i).String in lista_tariffe_analisi:
2767  oSheet.getRows().removeByIndex(i, 1)
2768  except Exception:
2769  pass
2770  oRangeAddress = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
2771  SR = oRangeAddress.StartRow + 1
2772  ER = oRangeAddress.EndRow - 1
2773  if ER < SR:
2774  return
2775  oRange = oSheet.getCellRangeByPosition(0, SR, 7, ER)
2776  lista_come_array = tuple(set(oRange.getDataArray()))
2777  # ~chi ([len(lista_come_array),(lista_come_array)])
2778  # ~return
2779  oSheet.getRows().removeByIndex(SR, ER - SR + 1)
2780  lista_tar = list()
2781  oSheet.getRows().insertByIndex(SR, len(set(lista_come_array)))
2782  for el in set(lista_come_array):
2783  lista_tar.append(el[0])
2784  colonne_lista = len(lista_come_array[0]
2785  ) # numero di colonne necessarie per ospitare i dati
2786  righe_lista = len(
2787  lista_come_array) # numero di righe necessarie per ospitare i dati
2788  oRange = oSheet.getCellRangeByPosition(
2789  0,
2790  3,
2791  colonne_lista + 0 - 1, # l'indice parte da 0
2792  righe_lista + 3 - 1)
2793  oRange.setDataArray(lista_come_array)
2794  oSheet.getCellRangeByPosition(0, 3, 0,
2795  righe_lista + 3 - 1).CellStyle = "EP-aS"
2796  oSheet.getCellRangeByPosition(1, 3, 1,
2797  righe_lista + 3 - 1).CellStyle = "EP-a"
2798  oSheet.getCellRangeByPosition(2, 3, 7,
2799  righe_lista + 3 - 1).CellStyle = "EP-mezzo"
2800  oSheet.getCellRangeByPosition(5, 3, 5,
2801  righe_lista + 3 - 1).CellStyle = "EP-mezzo %"
2802  oSheet.getCellRangeByPosition(8, 3, 9,
2803  righe_lista + 3 - 1).CellStyle = "EP-sfondo"
2804 
2805  oSheet.getCellRangeByPosition(11, 3, 11,
2806  righe_lista + 3 - 1).CellStyle = 'EP-mezzo %'
2807  oSheet.getCellRangeByPosition(12, 3, 12, righe_lista + 3 -
2808  1).CellStyle = 'EP statistiche_q'
2809  oSheet.getCellRangeByPosition(13, 3, 13, righe_lista + 3 -
2810  1).CellStyle = 'EP statistiche_Contab_q'
2811  # ~oDoc.CurrentController.select(
2812  # ~oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) # unselect
2813  if oDoc.getSheets().hasByName('Analisi di Prezzo'):
2815 
2816  oDoc.enableAutomaticCalculation(True)
2818  riordina_ElencoPrezzi(oDoc)
2820 
2821  if len(set(lista_tar)) != len(set(lista_come_array)):
2822  Dialogs.Exclamation(Title = 'ATTENZIONE!',
2823  Text='''Ci sono ancora 2 o più voci che hanno
2824 lo stesso Codice Articolo pur essendo diverse.''')
2825  # ~DLG.MsgBox(
2826  # ~'Ci sono ancora 2 o più voci che hanno lo stesso Codice Articolo pur essendo diverse.',
2827  # ~'C o n t r o l l a!')
2828 
2829 
2830 
2832 def XPWE_out(elaborato, out_file):
2833  '''
2834  esporta il documento in formato XPWE
2835 
2836  elaborato { string } : nome del foglio da esportare
2837  out_file { string } : nome base del file
2838 
2839  il nome file risulterà out_file-elaborato.xpwe
2840  '''
2842  # attiva la progressbar
2843  progress = Dialogs.Progress(Title='Esportazione di ' + elaborato + ' in corso...', Text="Lettura dati")
2844  progress.setLimits(0, 7)
2845  progress.setValue(0)
2846  progress.show()
2847 
2848  oDoc = LeenoUtils.getDocument()
2849  # ~oDoc.enableAutomaticCalculation(False)
2850  if cfg.read('Generale', 'dettaglio') == '1':
2851  dettaglio_misure(0)
2852  numera_voci(1)
2853  top = Element('PweDocumento')
2854  # intestazioni
2855  CopyRight = SubElement(top, 'CopyRight')
2856  CopyRight.text = 'Copyright ACCA software S.p.A.'
2857  TipoDocumento = SubElement(top, 'TipoDocumento')
2858  TipoDocumento.text = '1'
2859  TipoFormato = SubElement(top, 'TipoFormato')
2860  TipoFormato.text = 'XMLPwe'
2861  Versione = SubElement(top, 'Versione')
2862  Versione.text = ''
2863  SourceVersione = SubElement(top, 'SourceVersione')
2864 
2865  release = (
2866  str(LeenoUtils.getGlobalVar('Lmajor')) + '.' +
2867  str(LeenoUtils.getGlobalVar('Lminor')) + '.' +
2868  LeenoUtils.getGlobalVar('Lsubv')
2869  )
2870 
2871  SourceVersione.text = release
2872  SourceNome = SubElement(top, 'SourceNome')
2873  SourceNome.text = 'LeenO.org'
2874  FileNameDocumento = SubElement(top, 'FileNameDocumento')
2875  # dati generali
2876  PweDatiGenerali = SubElement(top, 'PweDatiGenerali')
2877  PweMisurazioni = SubElement(top, 'PweMisurazioni')
2878  PweDGProgetto = SubElement(PweDatiGenerali, 'PweDGProgetto')
2879  PweDGDatiGenerali = SubElement(PweDGProgetto, 'PweDGDatiGenerali')
2880  PercPrezzi = SubElement(PweDGDatiGenerali, 'PercPrezzi')
2881  PercPrezzi.text = '0'
2882 
2883  Comune = SubElement(PweDGDatiGenerali, 'Comune')
2884  Provincia = SubElement(PweDGDatiGenerali, 'Provincia')
2885  Oggetto = SubElement(PweDGDatiGenerali, 'Oggetto')
2886  Committente = SubElement(PweDGDatiGenerali, 'Committente')
2887  Impresa = SubElement(PweDGDatiGenerali, 'Impresa')
2888  ParteOpera = SubElement(PweDGDatiGenerali, 'ParteOpera')
2889  # leggo i dati generali
2890  oSheet = oDoc.getSheets().getByName('S2')
2891  Comune.text = oSheet.getCellByPosition(2, 3).String
2892  Provincia.text = ''
2893  Oggetto.text = oSheet.getCellByPosition(2, 2).String
2894  Committente.text = oSheet.getCellByPosition(2, 5).String
2895  Impresa.text = oSheet.getCellByPosition(2, 16).String
2896  ParteOpera.text = ''
2897  # Capitoli e Categorie
2898  PweDGCapitoliCategorie = SubElement(PweDatiGenerali,
2899  'PweDGCapitoliCategorie')
2900  # SuperCategorie
2901  oSheet = oDoc.getSheets().getByName(elaborato)
2902  lastRow = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1
2903  # evito di esportare in SuperCategorie perché inutile, almeno per ora
2904  listaspcat = list()
2905  PweDGSuperCategorie = SubElement(PweDGCapitoliCategorie,
2906  'PweDGSuperCategorie')
2907  progress.setValue(1)
2908  for n in range(0, lastRow):
2909  if oSheet.getCellByPosition(1, n).CellStyle == 'Livello-0-scritta':
2910  desc = oSheet.getCellByPosition(2, n).String
2911  if desc not in listaspcat:
2912  listaspcat.append(desc)
2913  idID = str(listaspcat.index(desc) + 1)
2914 
2915  # PweDGSuperCategorie = SubElement(PweDGCapitoliCategorie,'PweDGSuperCategorie')
2916  DGSuperCategorieItem = SubElement(PweDGSuperCategorie,
2917  'DGSuperCategorieItem')
2918  DesSintetica = SubElement(DGSuperCategorieItem, 'DesSintetica')
2919 
2920  DesEstesa = SubElement(DGSuperCategorieItem, 'DesEstesa')
2921  DataInit = SubElement(DGSuperCategorieItem, 'DataInit')
2922  Durata = SubElement(DGSuperCategorieItem, 'Durata')
2923  # CodFase = SubElement(DGSuperCategorieItem, 'CodFase')
2924  Percentuale = SubElement(DGSuperCategorieItem, 'Percentuale')
2925  # Codice = SubElement(DGSuperCategorieItem, 'Codice')
2926 
2927  DGSuperCategorieItem.set('ID', idID)
2928  DesSintetica.text = desc
2929  DataInit.text = oggi()
2930  Durata.text = '0'
2931  Percentuale.text = '0'
2932 
2933 # Categorie
2934  listaCat = list()
2935  PweDGCategorie = SubElement(PweDGCapitoliCategorie, 'PweDGCategorie')
2936  progress.setValue(2)
2937  for n in range(0, lastRow):
2938  if oSheet.getCellByPosition(2,
2939  n).CellStyle == 'Livello-1-scritta mini':
2940  desc = oSheet.getCellByPosition(2, n).String
2941  if desc not in listaCat:
2942  listaCat.append(desc)
2943  idID = str(listaCat.index(desc) + 1)
2944 
2945  # PweDGCategorie = SubElement(PweDGCapitoliCategorie,'PweDGCategorie')
2946  DGCategorieItem = SubElement(PweDGCategorie, 'DGCategorieItem')
2947  DesSintetica = SubElement(DGCategorieItem, 'DesSintetica')
2948 
2949  DesEstesa = SubElement(DGCategorieItem, 'DesEstesa')
2950  DataInit = SubElement(DGCategorieItem, 'DataInit')
2951  Durata = SubElement(DGCategorieItem, 'Durata')
2952  # CodFase = SubElement(DGCategorieItem, 'CodFase')
2953  Percentuale = SubElement(DGCategorieItem, 'Percentuale')
2954  # Codice = SubElement(DGCategorieItem, 'Codice')
2955 
2956  DGCategorieItem.set('ID', idID)
2957  DesSintetica.text = desc
2958  DataInit.text = oggi()
2959  Durata.text = '0'
2960  Percentuale.text = '0'
2961 
2962 # SubCategorie
2963  listasbCat = list()
2964  PweDGSubCategorie = SubElement(PweDGCapitoliCategorie, 'PweDGSubCategorie')
2965  progress.setValue(3)
2966  for n in range(0, lastRow):
2967  if oSheet.getCellByPosition(2, n).CellStyle == 'livello2_':
2968  desc = oSheet.getCellByPosition(2, n).String
2969  if desc not in listasbCat:
2970  listasbCat.append(desc)
2971  idID = str(listasbCat.index(desc) + 1)
2972 
2973  # PweDGSubCategorie = SubElement(PweDGCapitoliCategorie,'PweDGSubCategorie')
2974  DGSubCategorieItem = SubElement(PweDGSubCategorie,
2975  'DGSubCategorieItem')
2976  DesSintetica = SubElement(DGSubCategorieItem, 'DesSintetica')
2977 
2978  DesEstesa = SubElement(DGSubCategorieItem, 'DesEstesa')
2979  DataInit = SubElement(DGSubCategorieItem, 'DataInit')
2980  Durata = SubElement(DGSubCategorieItem, 'Durata')
2981  # CodFase = SubElement(DGSubCategorieItem, 'CodFase')
2982  Percentuale = SubElement(DGSubCategorieItem, 'Percentuale')
2983  # Codice = SubElement(DGSubCategorieItem, 'Codice')
2984 
2985  DGSubCategorieItem.set('ID', idID)
2986  DesSintetica.text = desc
2987  DataInit.text = oggi()
2988  Durata.text = '0'
2989  Percentuale.text = '0'
2990 
2991 # Moduli
2992  PweDGModuli = SubElement(PweDatiGenerali, 'PweDGModuli')
2993  PweDGAnalisi = SubElement(PweDGModuli, 'PweDGAnalisi')
2994  SpeseUtili = SubElement(PweDGAnalisi, 'SpeseUtili')
2995  SpeseGenerali = SubElement(PweDGAnalisi, 'SpeseGenerali')
2996  UtiliImpresa = SubElement(PweDGAnalisi, 'UtiliImpresa')
2997  OneriAccessoriSc = SubElement(PweDGAnalisi, 'OneriAccessoriSc')
2998  # ConfQuantita = SubElement(PweDGAnalisi, 'ConfQuantita')
2999 
3000  oSheet = oDoc.getSheets().getByName('S1')
3001  if oSheet.getCellByPosition(
3002  7, 322).Value == 0: # se 0: Spese e Utili Accorpati
3003  SpeseUtili.text = '1'
3004  else:
3005  SpeseUtili.text = '-1'
3006 
3007  UtiliImpresa.text = oSheet.getCellByPosition(7, 320).String[:-1].replace(
3008  ',', '.')
3009  OneriAccessoriSc.text = oSheet.getCellByPosition(7,
3010  318).String[:-1].replace(
3011  ',', '.')
3012  SpeseGenerali.text = oSheet.getCellByPosition(7, 319).String[:-1].replace(
3013  ',', '.')
3014 
3015  # Configurazioni
3016  PU = str(len(LeenoFormat.getFormatString('comp 1-a PU').split(',')[-1]))
3017  LUN = str(len(LeenoFormat.getFormatString('comp 1-a LUNG').split(',')[-1]))
3018  LAR = str(len(LeenoFormat.getFormatString('comp 1-a LARG').split(',')[-1]))
3019  PES = str(len(LeenoFormat.getFormatString('comp 1-a peso').split(',')[-1]))
3020  QUA = str(len(LeenoFormat.getFormatString('Blu').split(',')[-1]))
3021  PR = str(len(LeenoFormat.getFormatString('comp sotto Unitario').split(',')[-1]))
3022  TOT = str(len(LeenoFormat.getFormatString('An-1v-dx').split(',')[-1]))
3023  PweDGConfigurazione = SubElement(PweDatiGenerali, 'PweDGConfigurazione')
3024  PweDGConfigNumeri = SubElement(PweDGConfigurazione, 'PweDGConfigNumeri')
3025  Divisa = SubElement(PweDGConfigNumeri, 'Divisa')
3026  Divisa.text = 'euro'
3027  ConversioniIN = SubElement(PweDGConfigNumeri, 'ConversioniIN')
3028  ConversioniIN.text = 'lire'
3029  FattoreConversione = SubElement(PweDGConfigNumeri, 'FattoreConversione')
3030  FattoreConversione.text = '1936.27'
3031  Cambio = SubElement(PweDGConfigNumeri, 'Cambio')
3032  Cambio.text = '1'
3033  PartiUguali = SubElement(PweDGConfigNumeri, 'PartiUguali')
3034  PartiUguali.text = '9.' + PU + '|0'
3035  Lunghezza = SubElement(PweDGConfigNumeri, 'Lunghezza')
3036  Lunghezza.text = '9.' + LUN + '|0'
3037  Larghezza = SubElement(PweDGConfigNumeri, 'Larghezza')
3038  Larghezza.text = '9.' + LAR + '|0'
3039  HPeso = SubElement(PweDGConfigNumeri, 'HPeso')
3040  HPeso.text = '9.' + PES + '|0'
3041  Quantita = SubElement(PweDGConfigNumeri, 'Quantita')
3042  Quantita.text = '10.' + QUA + '|1'
3043  Prezzi = SubElement(PweDGConfigNumeri, 'Prezzi')
3044  Prezzi.text = '10.' + PR + '|1'
3045  PrezziTotale = SubElement(PweDGConfigNumeri, 'PrezziTotale')
3046  PrezziTotale.text = '14.' + TOT + '|1'
3047  ConvPrezzi = SubElement(PweDGConfigNumeri, 'ConvPrezzi')
3048  ConvPrezzi.text = '11.0|1'
3049  ConvPrezziTotale = SubElement(PweDGConfigNumeri, 'ConvPrezziTotale')
3050  ConvPrezziTotale.text = '15.0|1'
3051  IncidenzaPercentuale = SubElement(PweDGConfigNumeri,
3052  'IncidenzaPercentuale')
3053  IncidenzaPercentuale.text = '7.3|0'
3054  Aliquote = SubElement(PweDGConfigNumeri, 'Aliquote')
3055  Aliquote.text = '7.3|0'
3056 
3057 # Elenco Prezzi
3058  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
3059  PweElencoPrezzi = SubElement(PweMisurazioni, 'PweElencoPrezzi')
3060  diz_ep = dict()
3061  lista_AP = list()
3062  progress.setValue(4)
3063  listaspcap = list()
3064  listacap = list()
3065  listasbcap = list()
3066  # giallo(16777072,16777120,16777168)
3067  for n in range(3, SheetUtils.getUsedArea(oSheet).EndRow):
3068 
3069  # SuperCapitoli
3070  if oSheet.getCellByPosition(0, n).CellBackColor == 16777072 and \
3071  oSheet.getCellByPosition(0, n).String != '000':
3072  cod = oSheet.getCellByPosition(0, n).String
3073  desc = oSheet.getCellByPosition(1, n).String
3074  if desc not in listaspcap:
3075  listaspcap.append(desc)
3076  IDSpCap = str(listaspcap.index(desc) + 1)
3077 
3078  PweDGSuperCapitoli = SubElement(PweDGCapitoliCategorie,'PweDGSuperCapitoli')
3079  DGSuperCapitoliItem = SubElement(PweDGSuperCapitoli,
3080  'DGSuperCapitoliItem')
3081  DesSintetica = SubElement(DGSuperCapitoliItem, 'DesSintetica')
3082 
3083  DesEstesa = SubElement(DGSuperCapitoliItem, 'DesEstesa')
3084  DataInit = SubElement(DGSuperCapitoliItem, 'DataInit')
3085  Durata = SubElement(DGSuperCapitoliItem, 'Durata')
3086  # CodFase = SubElement(DGSuperCapitoliItem, 'CodFase')
3087  Percentuale = SubElement(DGSuperCapitoliItem, 'Percentuale')
3088  Codice = SubElement(DGSuperCapitoliItem, 'Codice')
3089 
3090  DGSuperCapitoliItem.set('ID', IDSpCap)
3091  DesSintetica.text = desc
3092  Codice.text = cod
3093  DataInit.text = '' #oggi()
3094  Durata.text = '0'
3095  Percentuale.text = '0'
3096 
3097  # Capitoli
3098  if oSheet.getCellByPosition(0, n).CellBackColor == 16777120:
3099  cod = oSheet.getCellByPosition(0, n).String
3100  desc = oSheet.getCellByPosition(1, n).String
3101  if desc not in listacap:
3102  listacap.append(desc)
3103  IDCap = str(listacap.index(desc) + 1)
3104 
3105  PweDGCapitoli = SubElement(PweDGCapitoliCategorie,'PweDGCapitoli')
3106  DGCapitoliItem = SubElement(PweDGCapitoli,
3107  'DGCapitoliItem')
3108  DesSintetica = SubElement(DGCapitoliItem, 'DesSintetica')
3109 
3110  DesEstesa = SubElement(DGCapitoliItem, 'DesEstesa')
3111  DataInit = SubElement(DGCapitoliItem, 'DataInit')
3112  Durata = SubElement(DGCapitoliItem, 'Durata')
3113  # CodFase = SubElement(DGCapitoliItem, 'CodFase')
3114  Percentuale = SubElement(DGCapitoliItem, 'Percentuale')
3115  Codice = SubElement(DGCapitoliItem, 'Codice')
3116 
3117  DGCapitoliItem.set('ID', IDCap)
3118  DesSintetica.text = desc
3119  Codice.text = cod
3120  DataInit.text = '' #oggi()
3121  Durata.text = '0'
3122  Percentuale.text = '0'
3123 
3124  # SubCapitoli
3125  if oSheet.getCellByPosition(0, n).CellBackColor == 16777168:
3126  cod = oSheet.getCellByPosition(0, n).String
3127  desc = oSheet.getCellByPosition(1, n).String
3128  if desc not in listasbcap:
3129  listasbcap.append(desc)
3130  IDSbCap = str(listasbcap.index(desc) + 1)
3131 
3132  PweDGSubCapitoli = SubElement(PweDGCapitoliCategorie,'PweDGSubCapitoli')
3133  DGSubCapitoliItem = SubElement(PweDGSubCapitoli,
3134  'DGSubCapitoliItem')
3135  DesSintetica = SubElement(DGSubCapitoliItem, 'DesSintetica')
3136 
3137  DesEstesa = SubElement(DGSubCapitoliItem, 'DesEstesa')
3138  DataInit = SubElement(DGSubCapitoliItem, 'DataInit')
3139  Durata = SubElement(DGSubCapitoliItem, 'Durata')
3140  # CodFase = SubElement(DGSubCapitoliItem, 'CodFase')
3141  Percentuale = SubElement(DGSubCapitoliItem, 'Percentuale')
3142  Codice = SubElement(DGSubCapitoliItem, 'Codice')
3143 
3144  DGSubCapitoliItem.set('ID', IDSbCap)
3145  DesSintetica.text = desc
3146  Codice.text = cod
3147  DataInit.text = '' #oggi()
3148  Durata.text = '0'
3149  Percentuale.text = '0'
3150 
3151 
3152  #voci di prezzo
3153  if(oSheet.getCellByPosition(1, n).Type.value == 'FORMULA' and
3154  oSheet.getCellByPosition(2, n).Type.value == 'FORMULA'):
3155  lista_AP.append(oSheet.getCellByPosition(0, n).String)
3156  elif(oSheet.getCellByPosition(1, n).Type.value == 'TEXT' and
3157  oSheet.getCellByPosition(2, n).Type.value == 'TEXT'):
3158  EPItem = SubElement(PweElencoPrezzi, 'EPItem')
3159  EPItem.set('ID', str(n))
3160  TipoEP = SubElement(EPItem, 'TipoEP')
3161  TipoEP.text = '0'
3162  Tariffa = SubElement(EPItem, 'Tariffa')
3163  id_tar = str(n)
3164  Tariffa.text = oSheet.getCellByPosition(0, n).String
3165  diz_ep[oSheet.getCellByPosition(0, n).String] = id_tar
3166  Articolo = SubElement(EPItem, 'Articolo')
3167  Articolo.text = ''
3168  DesRidotta = SubElement(EPItem, 'DesRidotta')
3169  DesEstesa = SubElement(EPItem, 'DesEstesa')
3170  DesEstesa.text = oSheet.getCellByPosition(1, n).String
3171  if len(DesEstesa.text) > 120:
3172  DesRidotta.text = DesEstesa.text[:
3173  60] + ' ... ' + DesEstesa.text[
3174  -60:]
3175  else:
3176  DesRidotta.text = DesEstesa.text
3177  DesBreve = SubElement(EPItem, 'DesBreve')
3178  if len(DesEstesa.text) > 60:
3179  DesBreve.text = DesEstesa.text[:30] + ' ... ' + DesEstesa.text[
3180  -30:]
3181  else:
3182  DesBreve.text = DesEstesa.text
3183  UnMisura = SubElement(EPItem, 'UnMisura')
3184  UnMisura.text = oSheet.getCellByPosition(2, n).String
3185  Prezzo1 = SubElement(EPItem, 'Prezzo1')
3186  Prezzo1.text = str(oSheet.getCellByPosition(4, n).Value)
3187  Prezzo2 = SubElement(EPItem, 'Prezzo2')
3188  Prezzo2.text = '0'
3189  Prezzo3 = SubElement(EPItem, 'Prezzo3')
3190  Prezzo3.text = '0'
3191  Prezzo4 = SubElement(EPItem, 'Prezzo4')
3192  Prezzo4.text = '0'
3193  Prezzo5 = SubElement(EPItem, 'Prezzo5')
3194  Prezzo5.text = '0'
3195 
3196  try:
3197  SubElement(EPItem, 'IDSpCap').text = IDSpCap
3198  except:
3199  SubElement(EPItem, 'IDSpCap').text = '0'
3200  try:
3201  SubElement(EPItem, 'IDCap').text = IDCap
3202  except:
3203  SubElement(EPItem, 'IDCap').text = '0'
3204  try:
3205  SubElement(EPItem, 'IDSbCap').text = IDSbCap
3206  except:
3207  SubElement(EPItem, 'IDSbCap').text = '0'
3208 
3209  Flags = SubElement(EPItem, 'Flags')
3210  if oSheet.getCellByPosition(8, n).String == '(AP)':
3211  Flags.text = '131072'
3212  else:
3213  Flags.text = '0'
3214  Data = SubElement(EPItem, 'Data')
3215  Data.text = '30/12/1899'
3216  AdrInternet = SubElement(EPItem, 'AdrInternet')
3217  AdrInternet.text = ''
3218  PweEPAnalisi = SubElement(EPItem, 'PweEPAnalisi')
3219 
3220  IncSIC = SubElement(EPItem, 'IncSIC')
3221  if oSheet.getCellByPosition(3, n).Value == 0.0:
3222  IncSIC.text = ''
3223  else:
3224  IncSIC.text = str(oSheet.getCellByPosition(3, n).Value * 100)
3225 
3226  IncMDO = SubElement(EPItem, 'IncMDO')
3227  if oSheet.getCellByPosition(5, n).Value == 0.0:
3228  IncMDO.text = ''
3229  else:
3230  IncMDO.text = str(oSheet.getCellByPosition(5, n).Value * 100)
3231 
3232  IncMAT = SubElement(EPItem, 'IncMAT')
3233  if oSheet.getCellByPosition(6, n).Value == 0.0:
3234  IncMAT.text = ''
3235  else:
3236  IncMAT.text = str(oSheet.getCellByPosition(6, n).Value * 100)
3237 
3238  IncATTR = SubElement(EPItem, 'IncATTR')
3239  if oSheet.getCellByPosition(7, n).Value == 0.0:
3240  IncATTR.text = ''
3241  else:
3242  IncATTR.text = str(oSheet.getCellByPosition(7, n).Value * 100)
3243 
3244  # Analisi di prezzo
3245  progress.setValue(5)
3246  if len(lista_AP) != 0:
3247  oSheet = oDoc.getSheets().getByName('Analisi di Prezzo')
3248  k = n + 1
3249  for el in lista_AP:
3250  try:
3251  m = SheetUtils.uFindStringCol(el, 0, oSheet)
3252  EPItem = SubElement(PweElencoPrezzi, 'EPItem')
3253  EPItem.set('ID', str(k))
3254  TipoEP = SubElement(EPItem, 'TipoEP')
3255  TipoEP.text = '0'
3256  Tariffa = SubElement(EPItem, 'Tariffa')
3257  id_tar = str(k)
3258  Tariffa.text = oSheet.getCellByPosition(0, m).String
3259  diz_ep[oSheet.getCellByPosition(0, m).String] = id_tar
3260  Articolo = SubElement(EPItem, 'Articolo')
3261  Articolo.text = ''
3262  DesRidotta = SubElement(EPItem, 'DesRidotta')
3263  DesEstesa = SubElement(EPItem, 'DesEstesa')
3264  DesEstesa.text = oSheet.getCellByPosition(1, m).String
3265  if len(DesEstesa.text) > 120:
3266  DesRidotta.text = DesEstesa.text[:
3267  60] + ' ... ' + DesEstesa.text[
3268  -60:]
3269  else:
3270  DesRidotta.text = DesEstesa.text
3271  DesBreve = SubElement(EPItem, 'DesBreve')
3272  if len(DesEstesa.text) > 60:
3273  DesBreve.text = DesEstesa.text[:
3274  30] + ' ... ' + DesEstesa.text[
3275  -30:]
3276  else:
3277  DesBreve.text = DesEstesa.text
3278  UnMisura = SubElement(EPItem, 'UnMisura')
3279  UnMisura.text = oSheet.getCellByPosition(2, m).String
3280  Prezzo1 = SubElement(EPItem, 'Prezzo1')
3281  Prezzo1.text = str(oSheet.getCellByPosition(6, m).Value)
3282  Prezzo2 = SubElement(EPItem, 'Prezzo2')
3283  Prezzo2.text = '0'
3284  Prezzo3 = SubElement(EPItem, 'Prezzo3')
3285  Prezzo3.text = '0'
3286  Prezzo4 = SubElement(EPItem, 'Prezzo4')
3287  Prezzo4.text = '0'
3288  Prezzo5 = SubElement(EPItem, 'Prezzo5')
3289  Prezzo5.text = '0'
3290  IDSpCap = SubElement(EPItem, 'IDSpCap')
3291  IDSpCap.text = '0'
3292  IDCap = SubElement(EPItem, 'IDCap')
3293  IDCap.text = '0'
3294  IDSbCap = SubElement(EPItem, 'IDSbCap')
3295  IDSbCap.text = '0'
3296  Flags = SubElement(EPItem, 'Flags')
3297  Flags.text = '131072'
3298  Data = SubElement(EPItem, 'Data')
3299  Data.text = '30/12/1899'
3300  AdrInternet = SubElement(EPItem, 'AdrInternet')
3301  AdrInternet.text = ''
3302  PweEPAnalisi = SubElement(EPItem, 'PweEPAnalisi')
3303  PweEPAR = SubElement(PweEPAnalisi, 'PweEPAR')
3304  nEPARItem = 2
3305  for x in range(m, m + 100):
3306  if oSheet.getCellByPosition(
3307  0, x).CellStyle == 'An-lavoraz-desc':
3308  EPARItem = SubElement(PweEPAR, 'EPARItem')
3309  EPARItem.set('ID', str(nEPARItem))
3310  nEPARItem += 1
3311  Tipo = SubElement(EPARItem, 'Tipo')
3312  Tipo.text = '0'
3313  IDEP = SubElement(EPARItem, 'IDEP')
3314  IDEP.text = diz_ep.get(
3315  oSheet.getCellByPosition(0, x).String)
3316  if IDEP.text is None:
3317  IDEP.text = '-2'
3318  Descrizione = SubElement(EPARItem, 'Descrizione')
3319  if '=IF(' in oSheet.getCellByPosition(1, x).String:
3320  Descrizione.text = ''
3321  else:
3322  Descrizione.text = oSheet.getCellByPosition(
3323  1, x).String
3324  Misura = SubElement(EPARItem, 'Misura')
3325  Misura.text = ''
3326  Qt = SubElement(EPARItem, 'Qt')
3327  Qt.text = ''
3328  Prezzo = SubElement(EPARItem, 'Prezzo')
3329  Prezzo.text = ''
3330  FieldCTL = SubElement(EPARItem, 'FieldCTL')
3331  FieldCTL.text = '0'
3332  if(oSheet.getCellByPosition(0, x).CellStyle == 'An-lavoraz-Cod-sx' and
3333  oSheet.getCellByPosition(1, x).String != ''):
3334  EPARItem = SubElement(PweEPAR, 'EPARItem')
3335  EPARItem.set('ID', str(nEPARItem))
3336  nEPARItem += 1
3337  Tipo = SubElement(EPARItem, 'Tipo')
3338  Tipo.text = '1'
3339  IDEP = SubElement(EPARItem, 'IDEP')
3340  IDEP.text = diz_ep.get(
3341  oSheet.getCellByPosition(0, x).String)
3342  if IDEP.text is None:
3343  IDEP.text = '-2'
3344  Descrizione = SubElement(EPARItem, 'Descrizione')
3345  if '=IF(' in oSheet.getCellByPosition(1, x).String:
3346  Descrizione.text = ''
3347  else:
3348  Descrizione.text = oSheet.getCellByPosition(
3349  1, x).String
3350  Misura = SubElement(EPARItem, 'Misura')
3351  Misura.text = oSheet.getCellByPosition(2, x).String
3352  Qt = SubElement(EPARItem, 'Qt')
3353  Qt.text = oSheet.getCellByPosition(3,
3354  x).String.replace(
3355  ',', '.')
3356  Prezzo = SubElement(EPARItem, 'Prezzo')
3357  Prezzo.text = str(
3358  oSheet.getCellByPosition(4, x).Value).replace(
3359  ',', '.')
3360  FieldCTL = SubElement(EPARItem, 'FieldCTL')
3361  FieldCTL.text = '0'
3362  elif oSheet.getCellByPosition(
3363  0, x).CellStyle == 'An-sfondo-basso Att End':
3364  break
3365 
3366  IncSIC = SubElement(EPItem, 'IncSIC')
3367  if oSheet.getCellByPosition(10, n).Value == 0.0:
3368  IncSIC.text = ''
3369  else:
3370  IncSIC.text = str(oSheet.getCellByPosition(10, n).Value)
3371 
3372  IncMDO = SubElement(EPItem, 'IncMDO')
3373  if oSheet.getCellByPosition(8, n).Value == 0.0:
3374  IncMDO.text = ''
3375  else:
3376  IncMDO.text = str(
3377  oSheet.getCellByPosition(5, n).Value * 100)
3378  k += 1
3379  except Exception:
3380  pass
3381 
3382  if elaborato == 'Elenco_Prezzi':
3383  pass
3384  else:
3385  # COMPUTO/VARIANTE/CONTABILITA
3386  oSheet = oDoc.getSheets().getByName(elaborato)
3387  PweVociComputo = SubElement(PweMisurazioni, 'PweVociComputo')
3388  oDoc.CurrentController.setActiveSheet(oSheet)
3389  Rinumera_TUTTI_Capitoli2(oSheet)
3390  nVCItem = 2
3391  progress.setValue(6)
3392  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))
3393  for n in range(0, LeenoSheetUtils.cercaUltimaVoce(oSheet)):
3394  progress.setValue(n)
3395  if oSheet.getCellByPosition(0,
3396  n).CellStyle in ('Comp Start Attributo',
3397  'Comp Start Attributo_R'):
3398  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, n)
3399  sStRange.RangeAddress
3400  sopra = sStRange.RangeAddress.StartRow
3401  sotto = sStRange.RangeAddress.EndRow
3402  if elaborato == 'CONTABILITA':
3403  sotto -= 1
3404  VCItem = SubElement(PweVociComputo, 'VCItem')
3405  VCItem.set('ID', str(nVCItem))
3406  nVCItem += 1
3407 
3408  IDEP = SubElement(VCItem, 'IDEP')
3409  IDEP.text = diz_ep.get(
3410  oSheet.getCellByPosition(1, sopra + 1).String)
3411 
3412  Quantita = SubElement(VCItem, 'Quantita')
3413  Quantita.text = oSheet.getCellByPosition(9, sotto).String
3414 
3415  DataMis = SubElement(VCItem, 'DataMis')
3416  if elaborato == 'CONTABILITA':
3417  DataMis.text = oSheet.getCellByPosition(1, sopra + 2).String
3418  else:
3419  DataMis.text = oggi() # 26/12/1952'#'28/09/2013'###
3420  vFlags = SubElement(VCItem, 'Flags')
3421  vFlags.text = '0'
3422 
3423  IDSpCat = SubElement(VCItem, 'IDSpCat')
3424  IDSpCat.text = str(oSheet.getCellByPosition(31, sotto).String)
3425  if elaborato == 'CONTABILITA':
3426  IDSpCat.text = str(oSheet.getCellByPosition(31, sotto + 1).String)
3427  if IDSpCat.text == '':
3428  IDSpCat.text = '0'
3429  # #########################
3430  IDCat = SubElement(VCItem, 'IDCat')
3431  IDCat.text = str(oSheet.getCellByPosition(32, sotto).String)
3432  if elaborato == 'CONTABILITA':
3433  IDCat.text = str(oSheet.getCellByPosition(32, sotto + 1).String)
3434  if IDCat.text == '':
3435  IDCat.text = '0'
3436  # #########################
3437  IDSbCat = SubElement(VCItem, 'IDSbCat')
3438  IDSbCat.text = str(oSheet.getCellByPosition(33, sotto).String)
3439  if elaborato == 'CONTABILITA':
3440  IDSbCat.text = str(oSheet.getCellByPosition(33, sotto + 1).String)
3441  if IDSbCat.text == '':
3442  IDSbCat.text = '0'
3443  # #########################
3444  PweVCMisure = SubElement(VCItem, 'PweVCMisure')
3445  x = 2
3446  for m in range(sopra + 2, sotto):
3447  RGItem = SubElement(PweVCMisure, 'RGItem')
3448  RGItem.set('ID', str(x))
3449  x += 1
3450  # #########################
3451  IDVV = SubElement(RGItem, 'IDVV')
3452  IDVV.text = '-2'
3453 
3454  Descrizione = SubElement(RGItem, 'Descrizione')
3455  Descrizione.text = oSheet.getCellByPosition(2, m).String
3456  # #########################
3457  PartiUguali = SubElement(RGItem, 'PartiUguali')
3458  PartiUguali.text = valuta_cella(oSheet.getCellByPosition(5, m))
3459  # #########################
3460  Lunghezza = SubElement(RGItem, 'Lunghezza')
3461  Lunghezza.text = valuta_cella(oSheet.getCellByPosition(6, m))
3462  # #########################
3463  Larghezza = SubElement(RGItem, 'Larghezza')
3464  Larghezza.text = valuta_cella(oSheet.getCellByPosition(7, m))
3465  # #########################
3466  HPeso = SubElement(RGItem, 'HPeso')
3467  HPeso.text = valuta_cella(oSheet.getCellByPosition(8, m))
3468  # #########################
3469  Quantita = SubElement(RGItem, 'Quantita')
3470  Quantita.text = str(oSheet.getCellByPosition(9, m).Value)
3471  # se negativa in CONTABILITA:
3472  # quando vedi_voce guarda ad un valore negativo
3473  if oSheet.getCellByPosition(4, m).Value < 0:
3474  test = True
3475  if elaborato == 'CONTABILITA':
3476  if oSheet.getCellByPosition(11, m).Value != 0:
3477  Quantita.text = '-' + str(oSheet.getCellByPosition(11, m).Value)
3478  # #########################
3479  Flags = SubElement(RGItem, 'Flags')
3480  if '*** VOCE AZZERATA ***' in Descrizione.text:
3481  PartiUguali.text = str(
3482  abs(float(valuta_cella(oSheet.getCellByPosition(5,
3483  m)))))
3484  Flags.text = '1'
3485  elif '-' in Quantita.text or oSheet.getCellByPosition(
3486  11, m).Value != 0:
3487  Flags.text = '1'
3488  elif "Parziale [" in oSheet.getCellByPosition(8, m).String:
3489  Flags.text = '2'
3490  HPeso.text = ''
3491  elif 'PARTITA IN CONTO PROVVISORIO' in Descrizione.text:
3492  Flags.text = '16'
3493  else:
3494  Flags.text = '0'
3495  # #########################
3496  if 'DETRAE LA PARTITA IN CONTO PROVVISORIO' in Descrizione.text:
3497  Flags.text = '32'
3498  if '- vedi voce n.' in Descrizione.text:
3499  IDVV.text = str(
3500  int(
3501  Descrizione.text.split('- vedi voce n.')[1].split(
3502  ' ')[0]) + 1)
3503  Flags.text = '32768'
3504  Descrizione.text = ''
3505  # PartiUguali.text =''
3506  if oSheet.getCellByPosition(4, m).Value < 0 and \
3507  oSheet.getCellByPosition(11, m).Value != 0:
3508  Flags.text = '32768'
3509  if oSheet.getCellByPosition(4, m).Value > 0 and \
3510  oSheet.getCellByPosition(11, m).Value != 0:
3511  Flags.text = '32769'
3512  if oSheet.getCellByPosition(4, m).Value > 0 and \
3513  oSheet.getCellByPosition(10, m).Value != 0:
3514  Flags.text = '32768'
3515  n = sotto + 1
3516  # #########################
3517  # ~out_file = Dialogs.FileSelect('Salva con nome...', '*.xpwe', 1)
3518  # ~out_file = uno.fileUrlToSystemPath(oDoc.getURL())
3519  # ~DLG.mri (uno.fileUrlToSystemPath(oDoc.getURL()))
3520  # ~chi(out_file)
3521  if cfg.read('Generale', 'dettaglio') == '1':
3522  dettaglio_misure(1)
3523  try:
3524  if out_file.split('.')[-1].upper() != 'XPWE':
3525  out_file = out_file + '-' + elaborato + '.xpwe'
3526  FileNameDocumento.text = out_file
3527  except AttributeError:
3528  return
3529  riga = str(tostring(top, encoding="unicode"))
3530  # if len(lista_AP) != 0:
3531  # riga = riga.replace('<PweDatiGenerali>','<Fgs>131072</Fgs><PweDatiGenerali>')
3532  progress.hide()
3533  try:
3534  of = codecs.open(out_file, 'w', 'utf-8')
3535  of.write(riga)
3536  of.close()
3537  # ~MsgBox('Esportazione in formato XPWE eseguita con successo\nsul file ' + out_file + '!','Avviso.')
3538  except Exception:
3539  Dialogs.Exclamation(Title = 'E R R O R E !',
3540  Text=''' Esportazione non eseguita!
3541 Verifica che il file di destinazione non sia già in uso!''')
3542  # ~DLG.MsgBox(
3543  # ~'Esportazione non eseguita!\n\nVerifica che il file di destinazione non sia già in uso!',
3544  # ~'E R R O R E !')
3545 
3547 
3548 
3549 
3550 def MENU_firme_in_calce(lrowF=None):
3551  '''
3552  Inserisce(in COMPUTO o VARIANTE) un riepilogo delle categorie
3553  ed i dati necessari alle firme
3554  '''
3556  oDoc = LeenoUtils.getDocument()
3557  oSheet = oDoc.CurrentController.ActiveSheet
3558  oSheet_S2 = oDoc.getSheets().getByName('S2')
3559 
3560  datafirme = oSheet_S2.getCellRangeByName('$S2.C4').String
3561 
3562  if datafirme == "":
3563  datafirme="Data,"
3564  else:
3565  datafirme = datafirme + ", "
3566  if oSheet.Name == "CONTABILITA":
3567  if lrowF == None:
3568  lrowF = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2
3569  oSheet.getRows().insertByIndex(lrowF, 11)
3570  riga_corrente = lrowF + 1
3571 
3572  # INSERISCI LA DATA E IL PROGETTISTA
3573  # ~DLG.chi(datafirme)
3574  oSheet.getCellByPosition(2 , riga_corrente).Formula = (
3575  '=CONCATENATE("' + datafirme + '";TEXT(NOW();"GG/mm/aaaa"))')
3576  oSheet.getCellByPosition(2 , riga_corrente + 2).Formula = (
3577  "L'Impresa esecutrice\n(" + oSheet_S2.getCellByPosition(
3578  2, 16).String + ")")
3579  oSheet.getCellByPosition(2 , riga_corrente + 6).Formula = (
3580  "Il Direttore dei Lavori\n(" + oSheet_S2.getCellByPosition(
3581  2, 15).String + ")")
3582  comando('CalculateHard')
3583 # ~rem CONSOLIDA LA DATA
3584  oRange = oSheet.getCellRangeByPosition (2, riga_corrente, 40, riga_corrente)
3585  aSaveData = oRange.getDataArray()
3586  oRange.setDataArray(aSaveData)
3587  if oSheet.Name in ("Registro", "SAL"):
3588  if lrowF == None:
3589  lrowF = SheetUtils.getLastUsedRow(oSheet)
3590 
3591  oSheet.getRows().insertByIndex(lrowF, 13)
3592  riga_corrente = lrowF + 1
3593  oSheet.getCellByPosition(1 , riga_corrente).Formula = '=CONCATENATE("' + datafirme + '";TEXT(NOW();"GG/mm/aaaa"))'
3594  comando('CalculateHard')
3595  oRange = oSheet.getCellRangeByPosition (1, riga_corrente, 40, riga_corrente)
3596  aSaveData = oRange.getDataArray()
3597  oRange.setDataArray(aSaveData)
3598 
3599  oSheet.getCellByPosition(1, riga_corrente + 2).Formula = (
3600  "L'Impresa esecutrice\n(" + oSheet_S2.getCellRangeByName(
3601  '$S2.C17').String + ")")
3602 
3603  oSheet.getCellByPosition(1, riga_corrente + 6).Formula = (
3604  "Il Direttore dei Lavori\n(" + oSheet_S2.getCellRangeByName(
3605  '$S2.C16').String + ")")
3606  oSheet.getCellRangeByPosition (0, riga_corrente + 2, 5,riga_corrente + 6).Rows.OptimalHeight = True
3607  if oSheet.Name == "SAL":
3608  return
3609  nSal = 1
3610  for i in reversed(range(2, 50)):
3611  if oDoc.NamedRanges.hasByName("_Lib_" + str(i)):
3612  nSal = i
3613  break
3614  oSheet.getCellByPosition(1, riga_corrente + 10).Formula = (
3615  '=CONCATENATE("In data ";TEXT(NOW();"DD/MM/YYYY");" è stato emesso il CERTIFICATO DI PAGAMENTO n.' + str(nSal) + ' per un importo di €")')
3616  comando('CalculateHard')
3617 
3618  oRange = oSheet.getCellRangeByPosition (1, riga_corrente + 10, 40, riga_corrente + 10)
3619 
3620  aSaveData = oRange.getDataArray()
3621  oRange.setDataArray(aSaveData)
3622 
3623  oSheet.getCellByPosition(1 , riga_corrente + 12).Formula = (
3624  "Il Direttore dei Lavori\n(" + oSheet_S2.getCellRangeByName(
3625  '$S2.C16').String + ")")
3626  if oSheet.Name in ('Analisi di Prezzo', 'Elenco Prezzi'):
3627  if lrowF == None:
3628  lrowF = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1
3629  oDoc.CurrentController.setFirstVisibleRow(lrowF - 1)
3630  lrowE = SheetUtils.getUsedArea(oSheet).EndRow
3631  for i in range(lrowF, SheetUtils.getUsedArea(oSheet).EndRow + 1):
3632  if oSheet.getCellByPosition(0, i).CellStyle == "Riga_rossa_Chiudi":
3633  lrowE = i
3634  break
3635  if lrowE > lrowF + 1:
3636  oSheet.getRows().removeByIndex(lrowF, lrowE - lrowF)
3637  riga_corrente = lrowF + 1
3638  oSheet.getRows().insertByIndex(lrowF, 15)
3639  oSheet.getCellRangeByPosition(0, lrowF, 100, lrowF + 15 -
3640  1).CellStyle = "Ultimus_centro"
3641  oSheet.getCellRangeByPosition(0, lrowF + 15 - 1, 100, lrowF + 15 -
3642  1).CellStyle = "Comp-Bianche in mezzo Descr_R"
3643  # raggruppo i righi di mirura
3644  iSheet = oSheet.RangeAddress.Sheet
3645  oCellRangeAddr = uno.createUnoStruct(
3646  'com.sun.star.table.CellRangeAddress')
3647  oCellRangeAddr.Sheet = iSheet
3648  oCellRangeAddr.StartColumn = 0
3649  oCellRangeAddr.EndColumn = 0
3650  oCellRangeAddr.StartRow = lrowF
3651  oCellRangeAddr.EndRow = lrowF + 15 - 1
3652  oSheet.group(oCellRangeAddr, 1)
3653 
3654  # INSERISCI LA DATA E IL PROGETTISTA
3655  oSheet.getCellByPosition(
3656  1, riga_corrente +
3657  3).Formula = '=CONCATENATE("Data, ";TEXT(NOW();"GG/MM/AAAA"))'
3658  comando('CalculateHard')
3659  # consolido il risultato
3660  oRange = oSheet.getCellByPosition(1, riga_corrente + 3)
3661  # flags = (oDoc.createInstance('com.sun.star.sheet.CellFlags.FORMULA'))
3662  aSaveData = oRange.getDataArray()
3663  oRange.setDataArray(aSaveData)
3664  oSheet.getCellRangeByPosition(1, riga_corrente + 3, 1,
3665  riga_corrente + 3).CellStyle = 'ULTIMUS'
3666  oSheet.getCellByPosition(1,
3667  riga_corrente + 5).Formula = 'Il Progettista'
3668  oSheet.getCellByPosition(
3669  1, riga_corrente + 6
3670  ).Formula = '=CONCATENATE($S2.$C$13)' # senza concatenate, se la cella di origine è vuota il risultato è '0,00'
3671 
3672  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'CompuM_NoP'):
3673  if lrowF == None:
3674  lrowF = LeenoSheetUtils.cercaUltimaVoce(oSheet) + 2
3675  oDoc.CurrentController.setFirstVisibleRow(lrowF - 2)
3676  lrowE = SheetUtils.getUsedArea(oSheet).EndRow
3677  for i in range(lrowF, SheetUtils.getUsedArea(oSheet).EndRow + 1):
3678  if oSheet.getCellByPosition(0, i).CellStyle == "Riga_rossa_Chiudi":
3679  lrowE = i
3680  break
3681  if lrowE > lrowF + 1:
3682  oSheet.getRows().removeByIndex(lrowF, lrowE - lrowF)
3683  riga_corrente = lrowF + 2
3684  if oDoc.getSheets().hasByName('S2'):
3685  ii = 11
3686  vv = 18
3687  ac = 28
3688  ad = 29
3689  ae = 30
3690  ss = 41
3691  col = 'S'
3692 
3693  else:
3694  ii = 8
3695  vv = 9
3696  ss = 9
3697  col = 'J'
3698  oSheet.getRows().insertByIndex(lrowF, 17)
3699  oSheet.getCellRangeByPosition(0, lrowF, ss,
3700  lrowF + 17 - 1).CellStyle = 'ULTIMUS'
3701  # raggruppo i righi di mirura
3702  iSheet = oSheet.RangeAddress.Sheet
3703  oCellRangeAddr = uno.createUnoStruct(
3704  'com.sun.star.table.CellRangeAddress')
3705  oCellRangeAddr.Sheet = iSheet
3706  oCellRangeAddr.StartColumn = 0
3707  oCellRangeAddr.EndColumn = 0
3708  oCellRangeAddr.StartRow = lrowF
3709  oCellRangeAddr.EndRow = lrowF + 17 - 1
3710  oSheet.group(oCellRangeAddr, 1)
3711 
3712  # INSERIMENTO TITOLO
3713  oSheet.getCellByPosition(
3714  2, riga_corrente).String = 'Riepilogo strutturale delle Categorie'
3715  oSheet.getCellByPosition(ii, riga_corrente).String = 'Incidenze %'
3716  oSheet.getCellByPosition(vv, riga_corrente).String = 'Importi €'
3717  oSheet.getCellByPosition(ac,
3718  riga_corrente).String = 'Materiali\ne Noli €'
3719  oSheet.getCellByPosition(ad, riga_corrente).String = 'Incidenza\nMDO %'
3720  oSheet.getCellByPosition(ae, riga_corrente).String = 'Importo\nMDO €'
3721  inizio_gruppo = riga_corrente
3722  riga_corrente += 1
3723 
3724  # attiva la progressbar
3725  progress = Dialogs.Progress(Title='Esecuzione in corso...', Text="Composizione del riepilogo strutturale.")
3726  i = 0
3727  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))
3728  progress.setValue(i)
3729  progress.show()
3730  for i in range(0, lrowF):
3731  progress.setValue(i)
3732 
3733  if oSheet.getCellByPosition(1, i).CellStyle == 'Livello-0-scritta':
3734  oSheet.getRows().insertByIndex(riga_corrente, 1)
3735  oSheet.getCellRangeByPosition(
3736  0, riga_corrente, 30,
3737  riga_corrente).CellStyle = 'ULTIMUS_1'
3738  oSheet.getCellByPosition(
3739  1, riga_corrente).Formula = '=B' + str(i + 1)
3740  oSheet.getCellByPosition(
3741  1, riga_corrente).CellStyle = 'Ultimus_destra_1'
3742  oSheet.getCellByPosition(
3743  2, riga_corrente).Formula = '=C' + str(i + 1)
3744  oSheet.getCellByPosition(
3745  ii, riga_corrente).Formula = '=' + col + str(
3746  riga_corrente + 1) + '/' + col + str(lrowF) + '*100'
3747  oSheet.getCellByPosition(
3748  ii, riga_corrente).CellStyle = 'Ultimus %_1'
3749  oSheet.getCellByPosition(
3750  vv, riga_corrente).Formula = '=' + col + str(i + 1)
3751  oSheet.getCellRangeByPosition(
3752  vv, riga_corrente, ae,
3753  riga_corrente).CellStyle = 'Ultimus_totali_1'
3754  oSheet.getCellByPosition(
3755  ac, riga_corrente).Formula = '=AC' + str(i + 1)
3756  oSheet.getCellByPosition(
3757  ad, riga_corrente).Formula = '=AD' + str(i + 1) + '*100'
3758  oSheet.getCellByPosition(
3759  ad, riga_corrente).CellStyle = 'Ultimus %_1'
3760  oSheet.getCellByPosition(
3761  ae, riga_corrente).Formula = '=AE' + str(i + 1)
3762  riga_corrente += 1
3763  elif oSheet.getCellByPosition(1,
3764  i).CellStyle == 'Livello-1-scritta':
3765  oSheet.getRows().insertByIndex(riga_corrente, 1)
3766  oSheet.getCellRangeByPosition(
3767  0, riga_corrente, 30,
3768  riga_corrente).CellStyle = 'ULTIMUS_2'
3769  oSheet.getCellByPosition(
3770  1, riga_corrente).Formula = '=B' + str(i + 1)
3771  oSheet.getCellByPosition(
3772  1, riga_corrente).CellStyle = 'Ultimus_destra'
3773  oSheet.getCellByPosition(
3774  2, riga_corrente).Formula = '=C' + str(i + 1)
3775  oSheet.getCellByPosition(
3776  ii, riga_corrente).Formula = '=' + col + str(
3777  riga_corrente + 1) + '/' + col + str(lrowF) + '*100'
3778  oSheet.getCellByPosition(ii,
3779  riga_corrente).CellStyle = 'Ultimus %'
3780  oSheet.getCellByPosition(
3781  vv, riga_corrente).Formula = '=' + col + str(i + 1)
3782  oSheet.getCellByPosition(
3783  vv, riga_corrente).CellStyle = 'Ultimus_bordo'
3784  oSheet.getCellByPosition(
3785  ac, riga_corrente).Formula = '=AC' + str(i + 1)
3786  oSheet.getCellByPosition(
3787  ad, riga_corrente).Formula = '=AD' + str(i + 1) + '*100'
3788  oSheet.getCellByPosition(ad,
3789  riga_corrente).CellStyle = 'Ultimus %'
3790  oSheet.getCellByPosition(
3791  ae, riga_corrente).Formula = '=AE' + str(i + 1)
3792  riga_corrente += 1
3793  elif oSheet.getCellByPosition(1, i).CellStyle == 'livello2 valuta':
3794  oSheet.getRows().insertByIndex(riga_corrente, 1)
3795  oSheet.getCellRangeByPosition(
3796  0, riga_corrente, 30,
3797  riga_corrente).CellStyle = 'ULTIMUS_3'
3798  oSheet.getCellByPosition(
3799  1, riga_corrente).Formula = '=B' + str(i + 1)
3800  oSheet.getCellByPosition(
3801  1, riga_corrente).CellStyle = 'Ultimus_destra_3'
3802  oSheet.getCellByPosition(
3803  2, riga_corrente).Formula = '=C' + str(i + 1)
3804  oSheet.getCellByPosition(
3805  ii, riga_corrente).Formula = '=' + col + str(
3806  riga_corrente + 1) + '/' + col + str(lrowF) + '*100'
3807  oSheet.getCellByPosition(
3808  ii, riga_corrente).CellStyle = 'Ultimus %_3'
3809  oSheet.getCellByPosition(
3810  vv, riga_corrente).Formula = '=' + col + str(i + 1)
3811  oSheet.getCellByPosition(vv,
3812  riga_corrente).CellStyle = 'ULTIMUS_3'
3813  oSheet.getCellByPosition(
3814  ac, riga_corrente).Formula = '=AC' + str(i + 1)
3815  oSheet.getCellByPosition(
3816  ad, riga_corrente).Formula = '=AD' + str(i + 1) + '*100'
3817  oSheet.getCellByPosition(
3818  ad, riga_corrente).CellStyle = 'Ultimus %_3'
3819  oSheet.getCellByPosition(
3820  ae, riga_corrente).Formula = '=AE' + str(i + 1)
3821  riga_corrente += 1
3822  progress.hide()
3823  oSheet.getCellRangeByPosition(
3824  2, inizio_gruppo, ae, inizio_gruppo).CellStyle = "Ultimus_centro"
3825  oSheet.getCellByPosition(ii, riga_corrente).Value = 100
3826  oSheet.getCellByPosition(2, riga_corrente).CellStyle = 'Ultimus_destra'
3827  oSheet.getCellByPosition(ii, riga_corrente).CellStyle = 'Ultimus %_1'
3828  oSheet.getCellByPosition(
3829  vv, riga_corrente).Formula = '=' + col + str(lrowF)
3830  oSheet.getCellByPosition(
3831  vv, riga_corrente).CellStyle = 'Ultimus_Bordo_sotto'
3832  oSheet.getCellByPosition(ac,
3833  riga_corrente).Formula = '=AC' + str(lrowF)
3834  oSheet.getCellByPosition(
3835  ac, riga_corrente).CellStyle = 'Ultimus_Bordo_sotto'
3836  oSheet.getCellByPosition(ae,
3837  riga_corrente).Formula = '=AE' + str(lrowF)
3838  oSheet.getCellByPosition(
3839  ae, riga_corrente).CellStyle = 'Ultimus_Bordo_sotto'
3840  oSheet.getCellByPosition(
3841  ad, riga_corrente).Formula = '=AD' + str(lrowF) + '*100'
3842  oSheet.getCellByPosition(
3843  2, riga_corrente).String = ' T O T A L E €'
3844  oSheet.getCellByPosition(2, riga_corrente).CellStyle = 'ULTIMUS_1'
3845  # fine_gruppo = riga_corrente
3846  # DATA
3847  oSheet.getCellByPosition(
3848  2, riga_corrente +
3849  3).Formula = '=CONCATENATE("Data, ";TEXT(NOW();"GG/MM/AAAA"))'
3850  # consolido il risultato
3851  oRange = oSheet.getCellByPosition(2, riga_corrente + 3)
3852  # flags = (oDoc.createInstance('com.sun.star.sheet.CellFlags.FORMULA'))
3853  comando('CalculateHard')
3854  aSaveData = oRange.getDataArray()
3855  oRange.setDataArray(aSaveData)
3856 
3857  oSheet.getCellByPosition(2,
3858  riga_corrente + 5).Formula = 'Il Progettista'
3859  oSheet.getCellByPosition(
3860  2, riga_corrente + 6
3861  ).Formula = '=CONCATENATE($S2.$C$13)' # senza concatenate, se la cella di origine è vuota il risultato è '0,00'
3862  oSheet.getCellRangeByPosition(2, riga_corrente + 5, 2, riga_corrente +
3863  6).CellStyle = 'Ultimus_centro'
3864 
3865  # inserisco il salto pagina in cima al riepilogo
3866  oDoc.CurrentController.select(oSheet.getCellByPosition(0, lrowF))
3868  desktop = LeenoUtils.getDesktop()
3869  oFrame = desktop.getCurrentFrame()
3870  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
3871  'com.sun.star.frame.DispatchHelper', ctx)
3872  dispatchHelper.executeDispatch(oFrame, ".uno:InsertRowBreak", "", 0, list())
3873  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges"))
3874 
3875  # oSheet.getCellByPosition(lrowF,0).Rows.IsManualPageBreak = True
3877 
3878 
3879 
3880 
3882  '''
3883  cancella le voci in Elenco Prezzi che derivano da analisi
3884  '''
3885  oDoc = LeenoUtils.getDocument()
3886  oSheet = oDoc.CurrentController.ActiveSheet
3887  oSheet = oDoc.Sheets.getByName('Analisi di Prezzo')
3888  lista_an = list()
3889  for i in range(0, SheetUtils.getUsedArea(oSheet).EndRow):
3890  if oSheet.getCellByPosition(0, i).CellStyle == 'An-1_sigla':
3891  # codice = oSheet.getCellByPosition(0, i).String
3892  lista_an.append(oSheet.getCellByPosition(0, i).String)
3893  oSheet = oDoc.Sheets.getByName('Elenco Prezzi')
3894  for i in reversed(range(0, SheetUtils.getUsedArea(oSheet).EndRow)):
3895  if oSheet.getCellByPosition(0, i).String in lista_an:
3896  oSheet.getRows().removeByIndex(i, 1)
3897 
3898 
3900  '''
3901  @@ DA DOCUMENTARE
3902  '''
3903  oDoc = LeenoUtils.getDocument()
3904  try:
3905  oSheet = oDoc.CurrentController.ActiveSheet
3906  if oSheet.Name != 'Analisi di Prezzo':
3907  return
3908  oDoc.enableAutomaticCalculation(False) # blocco il calcolo automatico
3910  riga = sStRange.RangeAddress.StartRow + 2
3911 
3912  codice = oSheet.getCellByPosition(0, riga).String
3913 
3914  oSheet = oDoc.Sheets.getByName('Elenco Prezzi')
3915  oDoc.CurrentController.setActiveSheet(oSheet)
3916 
3917  oSheet.getRows().insertByIndex(3, 1)
3918 
3919  oSheet.getCellByPosition(0, 3).CellStyle = 'EP-aS'
3920  oSheet.getCellByPosition(1, 3).CellStyle = 'EP-a'
3921  oSheet.getCellRangeByPosition(2, 3, 8, 3).CellStyle = 'EP-mezzo'
3922  oSheet.getCellByPosition(5, 3).CellStyle = 'EP-mezzo %'
3923  oSheet.getCellByPosition(9, 3).CellStyle = 'EP-sfondo'
3924  oSheet.getCellByPosition(10, 3).CellStyle = 'Default'
3925  oSheet.getCellByPosition(11, 3).CellStyle = 'EP-mezzo %'
3926  oSheet.getCellByPosition(12, 3).CellStyle = 'EP statistiche_q'
3927  oSheet.getCellByPosition(13, 3).CellStyle = 'EP statistiche_Contab_q'
3928 
3929  oSheet.getCellByPosition(0, 3).String = codice
3930 
3931  oSheet.getCellByPosition(
3932  1, 3).Formula = "=$'Analisi di Prezzo'.B" + str(riga + 1)
3933  oSheet.getCellByPosition(
3934  2, 3).Formula = "=$'Analisi di Prezzo'.C" + str(riga + 1)
3935  oSheet.getCellByPosition(
3936  3, 3).Formula = "=$'Analisi di Prezzo'.K" + str(riga + 1)
3937  oSheet.getCellByPosition(
3938  4, 3).Formula = "=$'Analisi di Prezzo'.G" + str(riga + 1)
3939  oSheet.getCellByPosition(
3940  5, 3).Formula = "=$'Analisi di Prezzo'.I" + str(riga + 1)
3941  oSheet.getCellByPosition(
3942  6, 3).Formula = "=$'Analisi di Prezzo'.J" + str(riga + 1)
3943  oSheet.getCellByPosition(
3944  7, 3).Formula = "=$'Analisi di Prezzo'.A" + str(riga + 1)
3945  oSheet.getCellByPosition(8, 3).String = "(AP)"
3946  oSheet.getCellByPosition(11, 3).Formula = "=N4/$N$2"
3947  oSheet.getCellByPosition(12, 3).Formula = "=SUMIF(AA;A4;BB)"
3948  oSheet.getCellByPosition(13, 3).Formula = "=SUMIF(AA;A4;cEuro)"
3949  oDoc.enableAutomaticCalculation(True) # sblocco il calcolo automatico
3950  _gotoCella(1, 3)
3951  except Exception:
3952  pass
3953  oDoc.enableAutomaticCalculation(True)
3954 
3955 
3956 
3958  '''
3959  Invia le analisi all'Elenco Prezzi.
3960  '''
3961  chiudi_dialoghi()
3962 
3963  oDoc = LeenoUtils.getDocument()
3964  # ~oDoc.enableAutomaticCalculation(False)
3965  lista_analisi = list()
3966  oSheet = oDoc.getSheets().getByName('Analisi di prezzo')
3967  SheetUtils.NominaArea(oDoc, 'Analisi di Prezzo',
3968  '$A$3:$K$' + str(SheetUtils.getUsedArea(oSheet).EndRow), 'analisi')
3969  voce = list()
3970  idx = 4
3971  for n in range(0, LeenoSheetUtils.cercaUltimaVoce(oSheet) + 1):
3972  if oSheet.getCellByPosition(
3973  0, n
3974  ).CellStyle == 'An-1_sigla' and oSheet.getCellByPosition(
3975  1, n
3976  ).String != '<<<Scrivi la descrizione della nuova voce da analizzare ':
3977  voce = (
3978  oSheet.getCellByPosition(0, n).String,
3979  "=$'Analisi di Prezzo'.B" + str(n + 1),
3980  "=$'Analisi di Prezzo'.C" + str(n + 1),
3981  "=$'Analisi di Prezzo'.K" + str(n + 1),
3982  "=$'Analisi di Prezzo'.G" + str(n + 1),
3983  "=$'Analisi di Prezzo'.I" + str(n + 1),
3984  # ~"=$'Analisi di Prezzo'.J" + str(n + 1),
3985  "",
3986  "=$'Analisi di Prezzo'.A" + str(n + 1),
3987  "(AP)",
3988  '',
3989  '',
3990  "=N" + str(idx) + "/$N$2",
3991  "=SUMIF(AA;A" + str(idx) + ";BB)",
3992  "=SUMIF(AA;A" + str(idx) + ";cEuro)",
3993  )
3994  lista_analisi.append(voce)
3995  idx += 1
3996  oSheet = oDoc.getSheets().getByName('Elenco Prezzi')
3997  if len(lista_analisi) != 0:
3998  oSheet.getRows().insertByIndex(3, len(lista_analisi))
3999  else:
4000  return
4001  oRange = oSheet.getCellRangeByPosition(0, 3, 13,
4002  3 + len(lista_analisi) - 1)
4003  lista_come_array = tuple(lista_analisi)
4004  oRange.setDataArray(
4005  lista_come_array
4006  ) # setFormulaArray() sarebbe meglio, ma mi fa storie sul codice articolo
4007  for y in range(3, 3 + len(lista_analisi)):
4008  for x in range(
4009  1, len(lista_analisi[0])
4010  ): # evito il codice articolo, altrimenti me lo converte in numero
4011  oSheet.getCellByPosition(x, y).Formula = oSheet.getCellByPosition(
4012  x, y).String
4013  oSheet.getCellRangeByPosition(0, 3, 0, 3 + len(lista_analisi) -
4014  1).CellStyle = 'EP-aS'
4015  oSheet.getCellRangeByPosition(1, 3, 1, 3 + len(lista_analisi) -
4016  1).CellStyle = 'EP-a'
4017  oSheet.getCellRangeByPosition(2, 3, 8, 3 + len(lista_analisi) -
4018  1).CellStyle = 'EP-mezzo'
4019  oSheet.getCellRangeByPosition(5, 3, 5, 3 + len(lista_analisi) -
4020  1).CellStyle = 'EP-mezzo %'
4021  oSheet.getCellRangeByPosition(9, 3, 9, 3 + len(lista_analisi) -
4022  1).CellStyle = 'EP-sfondo'
4023  oSheet.getCellRangeByPosition(10, 3, 10, 3 + len(lista_analisi) -
4024  1).CellStyle = 'Default'
4025  oSheet.getCellRangeByPosition(11, 3, 11, 3 + len(lista_analisi) -
4026  1).CellStyle = 'EP-mezzo %'
4027  oSheet.getCellRangeByPosition(12, 3, 12, 3 + len(lista_analisi) -
4028  1).CellStyle = 'EP statistiche_q'
4029  oSheet.getCellRangeByPosition(13, 3, 13, 3 + len(lista_analisi) -
4030  1).CellStyle = 'EP statistiche_Contab_q'
4031 
4032  # ~oDoc.enableAutomaticCalculation(True)
4033  GotoSheet('Elenco Prezzi')
4034  # MsgBox('Trasferite ' + str(len(lista_analisi)) + ' analisi di prezzo in Elenco Prezzi.', 'Avviso')
4035 
4036 
4037 
4039  '''
4040  @@@ MODIFICA IN CORSO CON 'LeenoAnalysis.circoscriveAnalisi'
4041  lrow { int } : riga di riferimento per
4042  la selezione dell'intera voce
4043  Circoscrive una voce di analisi
4044  partendo dalla posizione corrente del cursore
4045  '''
4046  oDoc = LeenoUtils.getDocument()
4047  oSheet = oDoc.CurrentController.ActiveSheet
4048  stili_analisi = LeenoUtils.getGlobalVar('stili_analisi')
4049  if oSheet.getCellByPosition(0, lrow).CellStyle in stili_analisi:
4050  for el in reversed(range(0, lrow)):
4051  # chi(oSheet.getCellByPosition(0, el).CellStyle)
4052  if oSheet.getCellByPosition(0, el).CellStyle == 'Analisi_Sfondo':
4053  SR = el
4054  break
4055  for el in range(lrow, SheetUtils.getUsedArea(oSheet).EndRow):
4056  if oSheet.getCellByPosition(
4057  0, el).CellStyle == 'An-sfondo-basso Att End':
4058  ER = el
4059  break
4060  celle = oSheet.getCellRangeByPosition(0, SR, 250, ER)
4061  return celle
4062 
4063 
4064 
4065 
4066 def ColumnNumberToName(oSheet, cColumnNumb):
4067  '''Trasforma IDcolonna in Nome'''
4068  # oDoc = LeenoUtils.getDocument()
4069  # oSheet = oDoc.CurrentController.ActiveSheet
4070  oColumns = oSheet.getColumns()
4071  oColumn = oColumns.getByIndex(cColumnNumb).Name
4072  return oColumn
4073 
4074 
4075 
4076 def ColumnNameToNumber(oSheet, cColumnName):
4077  '''Trasforma il nome colonna in IDcolonna'''
4078  # oDoc = LeenoUtils.getDocument()
4079  # oSheet = oDoc.CurrentController.ActiveSheet
4080  oColumns = oSheet.getColumns()
4081  oColumn = oColumns.getByName(cColumnName)
4082  oRangeAddress = oColumn.getRangeAddress()
4083  nColumn = oRangeAddress.StartColumn
4084  return nColumn
4085 
4086 
4087 
4089  '''
4090  Azzera la quantità di una voce e ne raggruppa le relative righe
4091  '''
4092  oDoc = LeenoUtils.getDocument()
4094 
4095  try:
4096  oSheet = oDoc.CurrentController.ActiveSheet
4097  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
4098  try:
4099  sRow = oDoc.getCurrentSelection().getRangeAddresses(
4100  )[0].StartRow
4101  eRow = oDoc.getCurrentSelection().getRangeAddresses()[0].EndRow
4102 
4103  except Exception:
4104  sRow = oDoc.getCurrentSelection().getRangeAddress().StartRow
4105  eRow = oDoc.getCurrentSelection().getRangeAddress().EndRow
4106  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, sRow)
4107  sStRange.RangeAddress
4108  sRow = sStRange.RangeAddress.StartRow
4109  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, eRow)
4110  try:
4111  sStRange.RangeAddress
4112  except Exception:
4113  return
4114  inizio = sStRange.RangeAddress.StartRow
4115  eRow = sStRange.RangeAddress.EndRow + 1
4116 
4117  lrow = sRow
4118  fini = list()
4119  for x in range(sRow, eRow):
4120  if oSheet.getCellByPosition(
4121  0, x).CellStyle == 'Comp End Attributo':
4122  fini.append(x)
4123  elif oSheet.getCellByPosition(
4124  0, x).CellStyle == 'Comp End Attributo_R':
4125  fini.append(x - 2)
4126  idx = 0
4127  for lrow in reversed(fini):
4128  lrow += idx
4129  try:
4130  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4131  sStRange.RangeAddress
4132  inizio = sStRange.RangeAddress.StartRow
4133  fine = sStRange.RangeAddress.EndRow
4134  if oSheet.Name == 'CONTABILITA':
4135  fine -= 1
4136  _gotoCella(2, fine - 1)
4137  if '*** VOCE AZZERATA ***' in oSheet.getCellByPosition(2, fine - 1).String:
4138  # elimino il colore di sfondo
4139  if oSheet.Name == 'CONTABILITA':
4140  oSheet.getCellRangeByPosition(
4141  0, inizio, 250, fine + 1).clearContents(HARDATTR)
4142  else:
4143  oSheet.getCellRangeByPosition(
4144  0, inizio, 250, fine).clearContents(HARDATTR)
4145  raggruppa_righe_voce(lrow, 0)
4146  oSheet.getRows().removeByIndex(fine - 1, 1)
4147  fine -= 1
4148  _gotoCella(2, fine - 1)
4149  idx -= 1
4150  else:
4151  Copia_riga_Ent()
4152  oSheet.getCellByPosition(2, fine).String = '*** VOCE AZZERATA ***'
4153  if oSheet.Name == 'CONTABILITA':
4154  oSheet.getCellByPosition(
4155  5, fine).Formula = '=SUBTOTAL(9;J' + str(
4156  inizio + 1) + ':J' + str(
4157  fine) + ')-SUBTOTAL(9;L' + str(
4158  inizio + 1) + ':L' + str(fine) + ')'
4159  else:
4160  oSheet.getCellByPosition(
4161  5, fine).Formula = '=SUBTOTAL(9;J' + str(
4162  inizio + 1) + ':J' + str(fine) + ')'
4163  inverti_segno()
4164  # cambio il colore di sfondo
4165  oDoc.CurrentController.select(sStRange)
4166  raggruppa_righe_voce(lrow, 1)
4168  desktop = LeenoUtils.getDesktop()
4169  oFrame = desktop.getCurrentFrame()
4170  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
4171  'com.sun.star.frame.DispatchHelper', ctx)
4172  oProp = PropertyValue()
4173  oProp.Name = 'BackgroundColor'
4174  oProp.Value = 15066597
4175  properties = (oProp, )
4176  dispatchHelper.executeDispatch(oFrame, '.uno:BackgroundColor', '', 0, properties)
4177  _gotoCella(2, fine)
4178 
4179  lrow = LeggiPosizioneCorrente()[1]
4180  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 1)
4181  except Exception:
4182  pass
4183  # ~numera_voci(1)
4184  except Exception:
4185  pass
4186  _gotoCella(0, fine)
4188 
4189 
4190 
4192  '''
4193  Elimina le voci in cui compare la dicitura '*** VOCE AZZERATA ***'
4194  in COMPUTO o in VARIANTE, senza chiedere conferma
4195  '''
4196  oDoc = LeenoUtils.getDocument()
4197  oSheet = oDoc.CurrentController.ActiveSheet
4198  try:
4199  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
4200  ER = SheetUtils.getUsedArea(oSheet).EndRow
4201  # attiva la progressbar
4202  progress = Dialogs.Progress(Title='Esecuzione in corso...', Text="Cancellazione voci azzerate")
4203  n = 0
4204  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))
4205  progress.setValue(n)
4206  progress.show()
4207  for lrow in reversed(range(0, ER)):
4208  n += 1
4209  progress.setValue(n)
4210  # ~if oSheet.getCellByPosition(
4211  # ~2, lrow).String == '*** VOCE AZZERATA ***':
4212  if '*** VOCE AZZERATA ***' in oSheet.getCellByPosition(2, lrow).String:
4213  # ~elimina_voce(lrow=lrow, msg=0)
4214  LeenoSheetUtils.eliminaVoce(oSheet, lrow)
4215 
4216  numera_voci(1)
4217  progress.hide()
4218  except Exception:
4219  return
4220 
4221 
4222 
4223 def raggruppa_righe_voce(lrow, flag=1):
4224  '''
4225  Raggruppa le righe che compongono una singola voce.
4226  '''
4227  oDoc = LeenoUtils.getDocument()
4228  oSheet = oDoc.CurrentController.ActiveSheet
4229  # lrow = LeggiPosizioneCorrente()[1]
4230  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4231  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4232  sStRange.RangeAddress
4233 
4234  iSheet = oSheet.RangeAddress.Sheet
4235  oCellRangeAddr = uno.createUnoStruct(
4236  'com.sun.star.table.CellRangeAddress')
4237  oCellRangeAddr.Sheet = iSheet
4238  oCellRangeAddr.StartColumn = sStRange.RangeAddress.StartColumn
4239  oCellRangeAddr.EndColumn = sStRange.RangeAddress.EndColumn
4240  oCellRangeAddr.StartRow = sStRange.RangeAddress.StartRow
4241  oCellRangeAddr.EndRow = sStRange.RangeAddress.EndRow
4242  if flag == 1:
4243  oSheet.group(oCellRangeAddr, 1)
4244  else:
4245  oSheet.ungroup(oCellRangeAddr, 1)
4246 
4247 
4248 
4250  '''
4251  Nasconde le voci in cui compare la dicitura '*** VOCE AZZERATA ***'
4252  in COMPUTO o in VARIANTE.
4253  '''
4254  oDoc = LeenoUtils.getDocument()
4255  oSheet = oDoc.CurrentController.ActiveSheet
4256  try:
4257  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4258  ER = SheetUtils.getUsedArea(oSheet).EndRow
4259  for lrow in reversed(range(0, ER)):
4260  if '*** VOCE AZZERATA ***' in oSheet.getCellByPosition(2, lrow).String:
4261  raggruppa_righe_voce(lrow, 1)
4262  except Exception:
4263  return
4264 
4265 
4266 
4267 def seleziona(lrow=None):
4268  '''
4269  Seleziona voci intere
4270  '''
4271  oDoc = LeenoUtils.getDocument()
4272  oSheet = oDoc.CurrentController.ActiveSheet
4273 
4274  if lrow == None:
4275  lrow = LeggiPosizioneCorrente()[1]
4276 
4277  try:
4278  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
4279  except AttributeError:
4280  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
4281  if oSheet.Name in ('Elenco Prezzi'):
4282 
4283  el_y = []
4284  lista_y = []
4285  try:
4286  len(oRangeAddress)
4287  for el in oRangeAddress:
4288  el_y.append((el.StartRow, el.EndRow))
4289  except TypeError:
4290  el_y.append((oRangeAddress.StartRow, oRangeAddress.EndRow))
4291  for y in el_y:
4292  for el in range(y[0], y[1] + 1):
4293  lista_y.append(el)
4294 
4295 
4296  if oSheet.Name in ('COMPUTO', 'VARIANTE', 'Analisi di Prezzo'):
4297  try:
4298  if lrow is not None:
4299  SR = oRangeAddress.StartRow
4300  SR = LeenoComputo.circoscriveVoceComputo(oSheet, SR).RangeAddress.StartRow
4301  else:
4302  SR = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
4303  except AttributeError:
4304  # ~DLG.MsgBox('La selezione deve essere contigua.', 'ATTENZIONE!')
4305  Dialogs.Exclamation(Title = 'ATTENZIONE!',
4306  Text='''La selezione deve essere contigua.''')
4307  return 0
4308  if lrow is not None:
4309  ER = oRangeAddress.EndRow
4310  ER = LeenoComputo.circoscriveVoceComputo(oSheet, ER).RangeAddress.EndRow
4311  else:
4312  ER = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.EndRow
4313  lista_y = [SR, ER]
4314  # ~if oSheet.Name == 'Analisi di Prezzo':
4315  # ~try:
4316  # ~oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
4317  # ~except AttributeError:
4318  # ~oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
4319  # ~try:
4320  # ~if lrow is not None:
4321  # ~SR = oRangeAddress.StartRow
4322  # ~SR = LeenoComputo.circoscriveVoceComputo(oSheet, SR).RangeAddress.StartRow
4323  # ~else:
4324  # ~SR = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
4325  # ~except AttributeError:
4326  # ~DLG.MsgBox('La selezione deve essere contigua.', 'ATTENZIONE!')
4327  # ~return 0
4328  # ~if lrow is not None:
4329  # ~ER = oRangeAddress.EndRow
4330  # ~ER = LeenoComputo.circoscriveVoceComputo(oSheet, ER).RangeAddress.EndRow
4331  # ~else:
4332  # ~ER = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.EndRow
4333  if oSheet.Name == 'CONTABILITA':
4334  partenza = cerca_partenza()
4335  if partenza[2] == '#reg':
4336  sblocca_cont()
4337  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
4338  return
4339  pass
4340  else:
4341  pass
4342  try:
4343  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
4344  except AttributeError:
4345  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
4346  try:
4347  if lrow is not None:
4348  SR = oRangeAddress.StartRow
4349  SR = LeenoComputo.circoscriveVoceComputo(oSheet, SR).RangeAddress.StartRow
4350  else:
4351  SR = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
4352  except AttributeError:
4353  # ~DLG.MsgBox('La selezione deve essere contigua.', 'ATTENZIONE!')
4354  Dialogs.Exclamation(Title = 'ATTENZIONE!',
4355  Text='''La selezione deve essere contigua.''')
4356  return 0
4357  if lrow is not None:
4358  ER = oRangeAddress.EndRow
4359  ER = LeenoComputo.circoscriveVoceComputo(oSheet, ER).RangeAddress.EndRow
4360  else:
4361  ER = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.EndRow
4362  lista_y = [SR, ER]
4363  return lista_y
4364 
4365 
4366 
4367 def seleziona_voce(lrow=None):
4368  '''
4369  @@@ MODIFICA IN CORSO CON 'LeenoSheetUtils.selezionaVoce'
4370  Restituisce inizio e fine riga di una voce in COMPUTO, VARIANTE,
4371  CONTABILITA o Analisi di Prezzo
4372  lrow { long } : numero riga
4373  '''
4374  oDoc = LeenoUtils.getDocument()
4375  oSheet = oDoc.CurrentController.ActiveSheet
4376  if lrow is None or lrow == 0:
4377  lrow = LeggiPosizioneCorrente()[1]
4378  if oSheet.Name in ('Elenco Prezzi'):
4379  return
4380  try:
4381  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4382  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4383  elif oSheet.Name == 'Analisi di Prezzo':
4384  sStRange = Circoscrive_Analisi(lrow)
4385 
4386  if oSheet.Name == 'CONTABILITA':
4387  partenza = cerca_partenza()
4388  if partenza[2] == '#reg':
4389  sblocca_cont()
4390  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
4391  return
4392  pass
4393  else:
4394  pass
4395  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4396 
4397  except Exception:
4398  return
4399  try:
4400  sStRange.RangeAddress
4401  SR = sStRange.RangeAddress.StartRow
4402  ER = sStRange.RangeAddress.EndRow
4403  except:
4404  return
4405  return (SR, ER)
4406 
4407 
4408 
4409 
4410 
4415 
4416 
4417 
4418 
4419 
4421  '''
4422  Elimina le righe selezionate anche se non contigue.
4423  '''
4424  oDoc = LeenoUtils.getDocument()
4425  oDoc.enableAutomaticCalculation(False)
4426  oSheet = oDoc.CurrentController.ActiveSheet
4427 
4428  if oSheet.Name == 'Elenco Prezzi':
4429  Dialogs.Info(Title = 'Info', Text="""Per eliminare una o più voci dall'Elenco Prezzi
4430 devi selezionarle ed utilizzare il comando 'Elimina righe' di Calc.""")
4431  return
4432 
4433  if oSheet.Name not in ('COMPUTO', 'CONTABILITA', 'VARIANTE', 'Analisi di Prezzo'):
4434  return
4435 
4436  try:
4437  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
4438  except AttributeError:
4439  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
4440  el_y = list()
4441  lista_y = list()
4442  try:
4443  len(oRangeAddress)
4444  for el in oRangeAddress:
4445  el_y.append((el.StartRow, el.EndRow))
4446  except TypeError:
4447  el_y.append((oRangeAddress.StartRow, oRangeAddress.EndRow))
4448  for y in el_y:
4449  for el in range(y[0], y[1] + 1):
4450  lista_y.append(el)
4451  oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
4452  rigen = False
4453  for y in reversed(lista_y):
4454  if oSheet.getCellByPosition(2, y).CellStyle not in ('An-lavoraz-generica',
4455  'An-lavoraz-Cod-sx',
4456  'comp 1-a',
4457  'comp 1-a ROSSO',
4458  'comp sotto centro',
4459  'EP-mezzo',
4460  'Livello-0-scritta mini',
4461  'Livello-1-scritta mini',
4462  'livello2_') or \
4463  'Somma positivi e negativi [' in oSheet.getCellByPosition(8, y).String or \
4464  'SOMMANO' in oSheet.getCellByPosition(8, y).String:
4465  pass
4466  else:
4467  if oSheet.getCellByPosition(2, y).CellStyle in ('comp sotto centro'):
4468  rigen = True
4469  if oSheet.getCellByPosition(1, y).CellStyle == 'Data_bianca':
4470  oCellAddress = oSheet.getCellByPosition(1, y+1).getCellAddress()
4471  oCellRangeAddr.Sheet = oSheet.RangeAddress.Sheet
4472  oCellRangeAddr.StartColumn = 1
4473  oCellRangeAddr.StartRow = y
4474  oCellRangeAddr.EndColumn = 1
4475  oCellRangeAddr.EndRow = y
4476  oSheet.copyRange(oCellAddress, oCellRangeAddr)
4477  stile = oSheet.getCellByPosition(2, y).CellStyle
4478  oSheet.getRows().removeByIndex(y, 1)
4479  if stile in ('Livello-0-scritta mini', 'Livello-1-scritta mini', 'livello2_'):
4480  Rinumera_TUTTI_Capitoli2(oSheet)
4481  if rigen == True:
4482  rigenera_parziali(False)
4483  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges"))
4484  oDoc.enableAutomaticCalculation(True)
4485 
4486 
4488  '''
4489  Inserisce una nuova riga di misurazione nel computo
4490  '''
4491  oDoc = LeenoUtils.getDocument()
4492  oSheet = oDoc.CurrentController.ActiveSheet
4493  # ~lrow = LeggiPosizioneCorrente()[1]
4494  stile = oSheet.getCellByPosition(1, lrow).CellStyle
4495  if stile in (
4496  'comp Art-EP', 'comp Art-EP_R', 'Comp-Bianche in mezzo'
4497  ): # Comp-Bianche in mezzo Descr', 'comp 1-a', 'comp sotto centro'):# <stili computo
4498  lrow = lrow + 1 # PER INSERIMENTO SOTTO RIGA CORRENTE
4499  oSheet.getRows().insertByIndex(lrow, 1)
4500  # imposto gli stili
4501  oSheet.getCellRangeByPosition(
4502  5,
4503  lrow,
4504  7,
4505  lrow,
4506  ).CellStyle = 'comp 1-a'
4507  oSheet.getCellByPosition(0, lrow).CellStyle = 'comp 10 s'
4508  oSheet.getCellByPosition(1, lrow).CellStyle = 'Comp-Bianche in mezzo'
4509  oSheet.getCellByPosition(2, lrow).CellStyle = 'comp 1-a'
4510  oSheet.getCellRangeByPosition(
4511  3, lrow, 4, lrow).CellStyle = 'Comp-Bianche in mezzo bordate_R'
4512  oSheet.getCellByPosition(5, lrow).CellStyle = 'comp 1-a PU'
4513  oSheet.getCellByPosition(6, lrow).CellStyle = 'comp 1-a LUNG'
4514  oSheet.getCellByPosition(7, lrow).CellStyle = 'comp 1-a LARG'
4515  oSheet.getCellByPosition(8, lrow).CellStyle = 'comp 1-a peso'
4516  oSheet.getCellByPosition(9, lrow).CellStyle = 'Blu'
4517  # ci metto le formule
4518  oSheet.getCellByPosition(
4519  9, lrow).Formula = '=IF(PRODUCT(E' + str(lrow + 1) + ':I' + str(
4520  lrow + 1) + ')=0;"";PRODUCT(E' + str(lrow +
4521  1) + ':I' + str(lrow +
4522  1) + '))'
4523  _gotoCella(2, lrow)
4524  # ~oDoc.CurrentController.select(oSheet.getCellByPosition(2, lrow))
4525  # ~oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges"))
4526 
4527 
4529  '''
4530  Inserisce una nuova riga di misurazione in contabilità
4531  '''
4532  oDoc = LeenoUtils.getDocument()
4533  # vado alla vecchia maniera ## copio il range di righe computo da S5 ##
4534  oSheet = oDoc.CurrentController.ActiveSheet
4535  oSheetto = oDoc.getSheets().getByName('S5')
4536  oRangeAddress = oSheetto.getCellRangeByPosition(0, 24, 42, 24).getRangeAddress()
4537  # lrow = LeggiPosizioneCorrente()[1]
4538  stile = oSheet.getCellByPosition(1, lrow).CellStyle
4539  if oSheet.getCellByPosition(1,
4540  lrow + 1).CellStyle == 'comp sotto Bianche_R':
4541  return
4542  if stile in ('comp Art-EP_R', 'Data_bianca', 'Comp-Bianche in mezzo_R'):
4543 
4544  lrow = lrow + 1 # PER INSERIMENTO SOTTO RIGA CORRENTE
4545 
4546  oCellAddress = oSheet.getCellByPosition(0, lrow).getCellAddress()
4547  oSheet.getRows().insertByIndex(lrow, 1)
4548  oSheet.copyRange(oCellAddress, oRangeAddress)
4549  if stile in ('comp Art-EP_R'):
4550  oRangeAddress = oSheet.getCellByPosition(1, lrow +
4551  1).getRangeAddress()
4552  oCellAddress = oSheet.getCellByPosition(1, lrow).getCellAddress()
4553  oSheet.copyRange(oCellAddress, oRangeAddress)
4554  oSheet.getCellByPosition(1, lrow + 1).String = ""
4555  oSheet.getCellByPosition(1, lrow + 1
4556  ).CellStyle = 'Comp-Bianche in mezzo_R'
4557  else:
4558  oSheet.getCellByPosition(1, lrow).CellStyle = 'Comp-Bianche in mezzo_R'
4559  _gotoCella(2, lrow)
4560  return
4561 
4562 
4564  '''
4565  @@@ MODIFICA IN CORSO CON 'LeenoAnalysis.copiaRigaAnalisi'
4566  Inserisce una nuova riga di misurazione in analisi di prezzo
4567  '''
4568  oDoc = LeenoUtils.getDocument()
4569  oSheet = oDoc.CurrentController.ActiveSheet
4570  stile = oSheet.getCellByPosition(0, lrow).CellStyle
4571  if stile in ('An-lavoraz-desc', 'An-lavoraz-Cod-sx'):
4572  lrow = lrow + 1
4573  oSheet.getRows().insertByIndex(lrow, 1)
4574  # imposto gli stili
4575  oSheet.getCellByPosition(0, lrow).CellStyle = 'An-lavoraz-Cod-sx'
4576  oSheet.getCellRangeByPosition(1, lrow, 5,
4577  lrow).CellStyle = 'An-lavoraz-generica'
4578  oSheet.getCellByPosition(3, lrow).CellStyle = 'An-lavoraz-input'
4579  oSheet.getCellByPosition(6, lrow).CellStyle = 'An-senza'
4580  oSheet.getCellByPosition(7, lrow).CellStyle = 'An-senza-DX'
4581  # ci metto le formule
4582  # oDoc.enableAutomaticCalculation(False)
4583  oSheet.getCellByPosition(1, lrow).Formula = '=IF(A' + str(
4584  lrow + 1) + '="";"";CONCATENATE(" ";VLOOKUP(A' + str(
4585  lrow + 1) + ';elenco_prezzi;2;FALSE());' '))'
4586  oSheet.getCellByPosition(
4587  2,
4588  lrow).Formula = '=IF(A' + str(lrow + 1) + '="";"";VLOOKUP(A' + str(
4589  lrow + 1) + ';elenco_prezzi;3;FALSE()))'
4590  oSheet.getCellByPosition(3, lrow).Value = 0
4591  oSheet.getCellByPosition(
4592  4,
4593  lrow).Formula = '=IF(A' + str(lrow + 1) + '="";0;VLOOKUP(A' + str(
4594  lrow + 1) + ';elenco_prezzi;5;FALSE()))'
4595  oSheet.getCellByPosition(
4596  5, lrow).Formula = '=D' + str(lrow + 1) + '*E' + str(lrow + 1)
4597  oSheet.getCellByPosition(
4598  8, lrow
4599  ).Formula = '=IF(A' + str(lrow + 1) + '="";"";IF(VLOOKUP(A' + str(
4600  lrow + 1) + ';elenco_prezzi;6;FALSE())="";"";(VLOOKUP(A' + str(
4601  lrow + 1) + ';elenco_prezzi;6;FALSE()))))'
4602  oSheet.getCellByPosition(9, lrow).Formula = '=IF(I' + str(
4603  lrow + 1) + '="";"";I' + str(lrow + 1) + '*F' + str(lrow + 1) + ')'
4604  # oDoc.enableAutomaticCalculation(True)
4605  # preserva il Pesca
4606  if oSheet.getCellByPosition(
4607  1, lrow - 1).CellStyle == 'An-lavoraz-dx-senza-bordi':
4608  oRangeAddress = oSheet.getCellByPosition(0, lrow +
4609  1).getRangeAddress()
4610  oCellAddress = oSheet.getCellByPosition(0, lrow).getCellAddress()
4611  oSheet.copyRange(oCellAddress, oRangeAddress)
4612  oSheet.getCellByPosition(0, lrow).String = 'Cod. Art.?'
4613  _gotoCella(1, lrow)
4614 
4615 
4616 
4617 
4619  '''
4620  @@ DA DOCUMENTARE
4621  '''
4622  Copia_riga_Ent()
4623 
4624 
4625 def Copia_riga_Ent(arg=None):
4626  '''
4627  Aggiunge riga di misurazione
4628  '''
4630  oDoc = LeenoUtils.getDocument()
4631  oSheet = oDoc.CurrentController.ActiveSheet
4632  lrow = LeggiPosizioneCorrente()[1]
4633  nome_sheet = oSheet.Name
4634  if nome_sheet in ('COMPUTO', 'VARIANTE'):
4635  if cfg.read('Generale', 'dettaglio') == '1':
4637  copia_riga_computo(lrow)
4638  elif nome_sheet == 'CONTABILITA':
4639  if cfg.read('Generale', 'dettaglio') == '1':
4641  copia_riga_contab(lrow)
4642  elif nome_sheet == 'Analisi di Prezzo':
4643  copia_riga_analisi(lrow)
4645 
4646 
4647 
4649  '''
4650  Conserva, nella variabile globale 'partenza', il nome del foglio [0] e l'id
4651  della riga di codice prezzo componente [1], il flag '#reg' solo per la contabilità.
4652  partenza = (nome_foglio, id_rcodice, flag_contabilità)
4653  '''
4654  oDoc = LeenoUtils.getDocument()
4655  oSheet = oDoc.CurrentController.ActiveSheet
4656  lrow = LeggiPosizioneCorrente()[1]
4657 
4658  partenza = LeenoSheetUtils.cercaPartenza(oSheet, lrow)
4659  LeenoUtils.setGlobalVar('partenza', partenza)
4660  return partenza
4661 
4662 
4664  '''
4665  @@@ MODIFICA IN CORSO CON 'LeenoContab.sbloccaContabilita'
4666  Controlla che non ci siano atti contabili registrati e dà il consenso a procedere.
4667  '''
4668  partenza = LeenoUtils.getGlobalVar('partenza')
4669  oDoc = LeenoUtils.getDocument()
4670  oSheet = oDoc.CurrentController.ActiveSheet
4671  if oSheet.Name in ('CONTABILITA'):
4672  partenza = cerca_partenza()
4673  # ~DLG.chi(partenza[2])
4674  # ~DLG.chi(LeenoUtils.getGlobalVar('sblocca_computo'))
4675  if LeenoUtils.getGlobalVar('sblocca_computo') == 1:
4676  pass
4677  else:
4678  if partenza[2] == '':
4679  pass
4680  if partenza[2] == '#reg':
4681  if Dialogs.YesNoDialog(Title='Avviso: Voce già registrata!',
4682 
4683  Text= """Lavorando in questo punto del foglio,
4684 comprometterai la validità degli atti contabili già emessi.
4685 
4686 Vuoi procedere?
4687 
4688 SCEGLIENDO SI' SARAI COSTRETTO A RIGENERARLI!""") == 0:
4689  pass
4690  else:
4691  LeenoUtils.setGlobalVar('sblocca_computo', 1)
4692  # ~DLG.chi(LeenoUtils.getGlobalVar('sblocca_computo'))
4693 
4694 
4695 
4696 
4697 
4699  '''
4700  Evidenzia il codice di elenco prezzi della voce corrente.
4701  '''
4702  cerca_in_elenco()
4703 
4704 
4706  '''
4707  Evidenzia il codice di elenco prezzi della voce corrente.
4708  '''
4709  oDoc = LeenoUtils.getDocument()
4710  oSheet = oDoc.CurrentController.ActiveSheet
4711  lrow = LeggiPosizioneCorrente()[1]
4712  if oSheet.Name in ('COMPUTO', 'CONTABILITA', 'VARIANTE', 'Registro',
4713  'Analisi di Prezzo', 'SAL'):
4714  if oSheet.Name == 'Analisi di Prezzo':
4715  if oSheet.getCellByPosition(
4716  0, lrow).CellStyle in ('An-lavoraz-Cod-sx', 'An-1_sigla'):
4717  codice_da_cercare = oSheet.getCellByPosition(0, lrow).String
4718  else:
4719  return
4720  elif oSheet.Name in ('Registro','SAL'):
4721  codice_da_cercare =oSheet.getCellByPosition(0, lrow).String.split('\n')[1]
4722  else:
4723  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4724  sopra = sStRange.RangeAddress.StartRow
4725  codice_da_cercare = oSheet.getCellByPosition(1, sopra + 1).String
4726  oSheet = oDoc.getSheets().getByName("Elenco Prezzi")
4727  oSheet.IsVisible = True
4728  GotoSheet('Elenco Prezzi')
4729  elif oSheet.Name in ('Elenco Prezzi'):
4730  if oSheet.getCellByPosition(1, lrow).Type.value == 'FORMULA':
4731  codice_da_cercare = oSheet.getCellByPosition(0, lrow).String
4732  else:
4733  return
4734  oSheet = oDoc.getSheets().getByName("Analisi di Prezzo")
4735  oSheet.IsVisible = True
4736  GotoSheet('Analisi di Prezzo')
4737 
4738  if codice_da_cercare == "Cod. Art.?":
4739  return
4740  if codice_da_cercare != '':
4741  oCell = SheetUtils.uFindString(codice_da_cercare, oSheet)
4742  try:
4743  oDoc.CurrentController.select(
4744  oSheet.getCellRangeByPosition(oCell[0], oCell[1], 30, oCell[1]))
4745  except:
4746  _gotoCella(1, 2)
4747  return
4748 
4749 
4750 
4751 
4753  '''
4754  @@ DA DOCUMENTARE
4755  '''
4756  pesca_cod()
4757 
4758 
4760  '''
4761  Permette di scegliere il codice per la voce di COMPUTO o VARIANTE o CONTABILITA dall'Elenco Prezzi.
4762  Capisce quando la voce nel libretto delle misure è già registrata o nel documento ci sono già atti contabili emessi.
4763  '''
4764  partenza = LeenoUtils.getGlobalVar('partenza')
4765  oDoc = LeenoUtils.getDocument()
4766  oSheet = oDoc.CurrentController.ActiveSheet
4767  lrow = LeggiPosizioneCorrente()[1]
4768 
4769  stili_computo = LeenoUtils.getGlobalVar('stili_computo')
4770  stili_contab = LeenoUtils.getGlobalVar('stili_contab')
4771  stili_analisi = LeenoUtils.getGlobalVar('stili_analisi')
4772  stili_elenco = LeenoUtils.getGlobalVar('stili_elenco')
4773 
4774  if oSheet.getCellByPosition(0, lrow).CellStyle not in stili_computo + stili_contab + stili_analisi + stili_elenco:
4775  return
4776  if oSheet.Name in ('Analisi di Prezzo'):
4777  partenza = cerca_partenza()
4778  cerca_in_elenco()
4779  GotoSheet('Elenco Prezzi')
4780 
4781 
4782  if oSheet.Name in ('CONTABILITA'):
4783  # controllo che non ci siano atti registrati
4784  partenza = cerca_partenza()
4785  if partenza[2] == '#reg':
4786  sblocca_cont()
4787  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
4788  return
4789  pass
4790  else:
4791  pass
4792 
4794  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4795  if oDoc.NamedRanges.hasByName("_Lib_1"):
4796  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
4797  if DLG.DlgSiNo(
4798  "Risulta già registrato un SAL. VUOI PROCEDERE COMUQUE?",
4799  'ATTENZIONE!') == 3:
4800  return
4801  if Dialogs.YesNoDialog(Title='ATTENZIONE!',
4802  Text="Risulta già registrato un SAL."
4803  "Vuoi procedere comunque?") == 0:
4804  return
4805  else:
4806  LeenoUtils.setGlobalVar('sblocca_computo', 1)
4807  partenza = cerca_partenza()
4808  if oSheet.getCellByPosition(1, partenza[1]).String != 'Cod. Art.?':
4809  cerca_in_elenco()
4810  GotoSheet('Elenco Prezzi')
4811 
4812  if oSheet.Name in ('Elenco Prezzi'):
4813  try:
4815  codice = oSheet.getCellByPosition(0, lrow).String
4816  GotoSheet(partenza[0])
4817  oSheet = oDoc.CurrentController.ActiveSheet
4818  if partenza[0] == 'Analisi di Prezzo':
4819  oSheet.getCellByPosition(0, partenza[1]).String = codice
4820  _gotoCella(3, partenza[1])
4821  else:
4822  oSheet.getCellByPosition(1, partenza[1]).String = codice
4823  _gotoCella(2, partenza[1] + 1)
4824  except NameError:
4825  return
4826 
4827 
4828 
4830  '''
4831  In CONTABILITA consente l'inserimento di nuove voci di misurazione
4832  partendo da voci già inserite in COMPUTO o VARIANTE.
4833  '''
4835  oDoc = LeenoUtils.getDocument()
4836  # ~oDoc.enableAutomaticCalculation(False)
4837  oSheet = oDoc.CurrentController.ActiveSheet
4838  if oSheet.Name == 'CONTABILITA':
4839  try:
4840  # controllo che non ci siano atti registrati
4841  partenza = cerca_partenza()
4842  if partenza[2] == '#reg':
4843  sblocca_cont()
4844  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
4845  return
4846  pass
4847  else:
4848  pass
4849 
4850  except Exception:
4851  pass
4852  lrow = LeggiPosizioneCorrente()[1]
4853 
4854  stili_contab = LeenoUtils.getGlobalVar('stili_contab')
4855 
4856  if oSheet.getCellByPosition(0, lrow).CellStyle not in stili_contab + (
4857  'comp Int_colonna_R_prima', ):
4858  return
4859  ins_voce_contab(arg=0)
4860  partenza = cerca_partenza()
4861  try:
4862  GotoSheet(cfg.read('Contabilita', 'ricicla_da'))
4863  except:
4864  Dialogs.Exclamation(Title = 'ATTENZIONE!',
4865  Text=' Stai cercando di riciclare le misure dal foglio ' + \
4866  cfg.read('Contabilita', 'ricicla_da'))
4868  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4869  lrow = LeggiPosizioneCorrente()[1]
4870  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
4871  sopra = sStRange.RangeAddress.StartRow + 2
4872  sotto = sStRange.RangeAddress.EndRow - 1
4873 
4874  oSrc = oSheet.getCellRangeByPosition(2, sopra, 8,
4875  sotto).getRangeAddress()
4876  oSheet.getCellByPosition(2, sopra - 1).CellBackColor = 13500076
4877  partenza = LeenoUtils.getGlobalVar('partenza')
4878  if partenza is None:
4879  return
4880  oDest = oDoc.getSheets().getByName('CONTABILITA')
4881  oCellAddress = oDest.getCellByPosition(2, partenza[1] + 1).getCellAddress()
4882  GotoSheet('CONTABILITA')
4883 
4884  if sotto != sopra:
4885  oDest.getRows().insertByIndex(partenza[1] + 2, sotto - sopra)
4886  oDest.getCellRangeByPosition(1, partenza[1] + 2, 1, partenza[1] +
4887  sotto - sopra +1).CellStyle = 'Comp-Bianche in mezzo_R'
4888 
4889  oDest.copyRange(oCellAddress, oSrc)
4890  oDest.getCellByPosition(1, partenza[1]).String = oSheet.getCellByPosition(1, sopra - 1).String
4891  oDest.getCellByPosition(2, partenza[1]).CellBackColor = 13500076
4892  rigenera_voce(partenza[1])
4893  # ~rigenera_parziali(False)
4894  _gotoCella(2, partenza[1] + 1)
4895  # ~oDoc.enableAutomaticCalculation(True)
4897 
4898 
4900  inverti_segno()
4901 
4903  '''
4904  Inverte il segno delle formule di quantità nei righi di misurazione selezionati.
4905  '''
4906  oDoc = LeenoUtils.getDocument()
4907  oSheet = oDoc.CurrentController.ActiveSheet
4908 
4909  # estrae il range o i ranges selezionati
4910  # (possono essere più di uno)
4911  try:
4912  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
4913  except AttributeError:
4914  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
4915 
4916  # inserisce in una lista le righe di inizio e fine
4917  # di ogni range come touples ((inizio, fine), (inizio, fine)...)
4918  el_y = list()
4919  try:
4920  len(oRangeAddress)
4921  for el in oRangeAddress:
4922  el_y.append((el.StartRow, el.EndRow))
4923  except TypeError:
4924  el_y.append((oRangeAddress.StartRow, oRangeAddress.EndRow))
4925 
4926  # estrate tutte le righe incluse nel o nei range(s)
4927  # e le inserisce in una lista di righe
4928  lista = list()
4929  for y in el_y:
4930  for el in range(y[0], y[1] + 1):
4931  lista.append(el)
4932 
4933  # va ad eseguire il lavoro su ogni riga della lista
4934  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
4935  for lrow in lista:
4936  if 'comp 1-a' in oSheet.getCellByPosition(2, lrow).CellStyle:
4937  if 'ROSSO' in oSheet.getCellByPosition(2, lrow).CellStyle:
4938  # se VediVoce
4939  oSheet.getCellByPosition(9, lrow).Formula = (
4940  '=IF(PRODUCT(E' + str(lrow + 1) + ':I' +
4941  str(lrow + 1) + ')=0;"";PRODUCT(E' +
4942  str(lrow + 1) + ':I' +
4943  str(lrow + 1) + '))')
4944 
4945  for x in range(2, 10):
4946  oSheet.getCellByPosition(x, lrow).CellStyle = (
4947  oSheet.getCellByPosition(x, lrow).CellStyle.split(' ROSSO')[0])
4948  else:
4949  # se VediVoce
4950  oSheet.getCellByPosition(9, lrow).Formula = (
4951  '=IF(PRODUCT(E' + str(lrow + 1) + ':I' +
4952  str(lrow + 1) + ')=0;"";-PRODUCT(E' +
4953  str(lrow + 1) + ':I' + str(lrow + 1) + '))')
4954 
4955  for x in range(2, 10):
4956  oSheet.getCellByPosition(x, lrow).CellStyle = (
4957  oSheet.getCellByPosition(x, lrow).CellStyle + ' ROSSO')
4958 
4959  elif oSheet.Name in ('CONTABILITA'):
4960  for lrow in lista:
4961  if 'comp 1-a' in oSheet.getCellByPosition(2, lrow).CellStyle:
4962  formula1 = oSheet.getCellByPosition(9, lrow).Formula
4963  formula2 = oSheet.getCellByPosition(11, lrow).Formula
4964  oSheet.getCellByPosition(11, lrow).Formula = formula1
4965  oSheet.getCellByPosition(9, lrow).Formula = formula2
4966  if oSheet.getCellByPosition(11, lrow).Value > 0:
4967  for x in range(2, 12):
4968  oSheet.getCellByPosition(x, lrow).CellStyle = (
4969  oSheet.getCellByPosition(x, lrow).CellStyle + ' ROSSO')
4970  else:
4971  for x in range(2, 12):
4972  oSheet.getCellByPosition(
4973  x, lrow).CellStyle = (
4974  oSheet.getCellByPosition(x, lrow).CellStyle.split(' ROSSO')[0])
4975 
4976 
4977 
4978 def valuta_cella(oCell):
4979  '''
4980  Estrae qualsiasi valore da una cella, restituendo una stringa, indipendentemente dal tipo originario.
4981  oCell { object } : cella da validare
4982  '''
4983  if oCell.Type.value == 'FORMULA':
4984  if re.search('[a-zA-Z]', oCell.Formula):
4985  valore = str(oCell.Value)
4986  else:
4987  valore = oCell.Formula.split('=')[-1]
4988  elif oCell.Type.value == 'VALUE':
4989  valore = str(oCell.Value)
4990  elif oCell.Type.value == 'TEXT':
4991  valore = str(oCell.String)
4992  elif oCell.Type.value == 'EMPTY':
4993  valore = ''
4994  if valore == ' ':
4995  valore = ''
4996  return valore
4997 
4998 
4999 
5001  '''
5002  Indica il dettaglio delle misure nel rigo di descrizione quando
5003  incontra delle formule nei valori immessi.
5004  bit { integer } : 1 inserisce i dettagli
5005  0 cancella i dettagli
5006  '''
5007  oDoc = LeenoUtils.getDocument()
5009  oSheet = oDoc.CurrentController.ActiveSheet
5010  lrow = LeggiPosizioneCorrente()[1]
5011  if ' ►' in oSheet.getCellByPosition(2, lrow).String:
5012  oSheet.getCellByPosition(2, lrow).String = oSheet.getCellByPosition(
5013  2, lrow).String.split(' ►')[0]
5014  if oSheet.getCellByPosition(2, lrow).CellStyle in (
5015  'comp 1-a'
5016  ) and "*** VOCE AZZERATA ***" not in oSheet.getCellByPosition(2,
5017  lrow).String:
5018  for el in range(5, 9):
5019  if oSheet.getCellByPosition(el, lrow).Type.value == 'FORMULA':
5020  stringa = ''
5021  break
5022  else:
5023  stringa = None
5024 
5025  if stringa == '':
5026  for el in range(5, 9):
5027  if oSheet.getCellByPosition(el, lrow).Type.value == 'FORMULA':
5028  if '$' not in oSheet.getCellByPosition(el, lrow).Formula:
5029  try:
5030  eval(
5031  oSheet.getCellByPosition(
5032  el, lrow).Formula.split('=')[1].replace(
5033  '^', '**'))
5034  # ~eval(oSheet.getCellByPosition(el, lrow).Formula.split('=')[1])
5035  stringa = stringa + '(' + oSheet.getCellByPosition(
5036  el, lrow).Formula.split('=')[-1] + ')*'
5037  except Exception:
5038  stringa = stringa + '(' + oSheet.getCellByPosition(
5039  el, lrow).String.split('=')[-1] + ')*'
5040  pass
5041  else:
5042  stringa = stringa + '*' + str(
5043  oSheet.getCellByPosition(el, lrow).String) + '*'
5044  while '**' in stringa:
5045  stringa = stringa.replace('**', '*')
5046  if stringa[0] == '*':
5047  stringa = stringa[1:-1]
5048  else:
5049  stringa = stringa[0:-1]
5050  stringa = ' ►' + stringa # + ')'
5051  if oSheet.getCellByPosition(2, lrow).Type.value != 'FORMULA':
5052  oSheet.getCellByPosition(
5053  2, lrow).String = oSheet.getCellByPosition(
5054  2, lrow).String + stringa.replace('.', ',')
5056 
5057 
5058 
5060  '''
5061  Indica il dettaglio delle misure nel rigo di descrizione quando
5062  incontra delle formule nei valori immessi.
5063  bit { integer } : 1 inserisce i dettagli
5064  0 cancella i dettagli
5065  '''
5067  oDoc = LeenoUtils.getDocument()
5068  try:
5069  oSheet = oDoc.CurrentController.ActiveSheet
5070  except Exception:
5071  return
5072  ER = SheetUtils.getUsedArea(oSheet).EndRow
5073 
5074  progress = Dialogs.Progress(Title='Rigenerazione in corso...', Text="Lettura dati")
5075  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))
5076  progress.setValue(0)
5077  progress.show()
5078 
5079  if bit == 1:
5080  for lrow in range(0, ER):
5081  progress.setValue(lrow)
5082  if oSheet.getCellByPosition(2, lrow).CellStyle in (
5083  'comp 1-a'
5084  ) and "*** VOCE AZZERATA ***" not in oSheet.getCellByPosition(
5085  2, lrow).String:
5086  for el in range(5, 9):
5087  if oSheet.getCellByPosition(el, lrow).Type.value == 'FORMULA':
5088  stringa = ''
5089  break
5090  else:
5091  stringa = None
5092  if stringa == '':
5093  for el in range(5, 9):
5094  if oSheet.getCellByPosition(
5095  el, lrow).Type.value == 'FORMULA':
5096  if '$' not in oSheet.getCellByPosition(
5097  el, lrow).Formula:
5098  try:
5099  eval(
5100  oSheet.getCellByPosition(
5101  el, lrow).Formula.split('=')
5102  [1].replace('^', '**'))
5103  # ~eval(oSheet.getCellByPosition(el, lrow).Formula.split('=')[1])
5104  stringa = stringa + '(' + oSheet.getCellByPosition(
5105  el, lrow).Formula.split('=')[-1] + ')*'
5106  except Exception:
5107  stringa = stringa + '(' + oSheet.getCellByPosition(
5108  el, lrow).String.split('=')[-1] + ')*'
5109  pass
5110  else:
5111  stringa = stringa + '*' + str(
5112  oSheet.getCellByPosition(el,
5113  lrow).String) + '*'
5114  while '**' in stringa:
5115  stringa = stringa.replace('**', '*')
5116  if stringa[0] == '*':
5117  stringa = stringa[1:-1]
5118  else:
5119  stringa = stringa[0:-1]
5120  stringa = ' ►' + stringa #+ ')'
5121  if oSheet.getCellByPosition(2,
5122  lrow).Type.value != 'FORMULA':
5123  oSheet.getCellByPosition(
5124  2, lrow).String = oSheet.getCellByPosition(
5125  2, lrow).String + stringa.replace('.', ',')
5126  else:
5127  for lrow in range(0, ER):
5128  progress.hide()
5129  # ~progress.setValue(lrow)
5130  if ' ►' in oSheet.getCellByPosition(2, lrow).String:
5131  oSheet.getCellByPosition(
5132  2, lrow).String = oSheet.getCellByPosition(
5133  2, lrow).String.split(' ►')[0]
5134 
5135  progress.hide()
5137  return
5138 
5139 
5140 
5142  oDoc = LeenoUtils.getDocument()
5143  oSheet = oDoc.CurrentController.ActiveSheet
5144  # DLG.mri(oDoc.CurrentSelection.Validation)
5145 
5146  oSheet.getCellRangeByName('L1').String = 'Ricicla da:'
5147  oSheet.getCellRangeByName('L1').CellStyle = 'Reg_prog'
5148  oCell = oSheet.getCellRangeByName('N1')
5149  if oCell.String not in ("COMPUTO", "VARIANTE", 'Scegli origine'):
5150  oCell.CellStyle = 'Menu_sfondo _input_grasBig'
5151  valida_cella(oCell,
5152  '"COMPUTO";"VARIANTE"',
5153  titoloInput='Scegli...',
5154  msgInput='COMPUTO o VARIANTE',
5155  err=True)
5156  oCell.String = 'Scegli...'
5157 
5158 
5159 def valida_cella(oCell, lista_val, titoloInput='', msgInput='', err=False):
5160  '''
5161  Validità lista valori
5162  Imposta un elenco di valori a cascata, da cui scegliere.
5163  oCell { object } : cella da validare
5164  lista_val { string } : lista dei valori in questa forma: '"UNO";"DUE";"TRE"'
5165  titoloInput { string } : titolo del suggerimento che compare passando il cursore sulla cella
5166  msgInput { string } : suggerimento che compare passando il cursore sulla cella
5167  err { boolean } : permette di abilitare il messaggio di errore per input non validi
5168  '''
5169  # oDoc = LeenoUtils.getDocument()
5170  # oSheet = oDoc.CurrentController.ActiveSheet
5171 
5172  oTabVal = oCell.getPropertyValue("Validation")
5173  oTabVal.setPropertyValue('ConditionOperator', 1)
5174 
5175  oTabVal.setPropertyValue("ShowInputMessage", True)
5176  oTabVal.setPropertyValue("InputTitle", titoloInput)
5177  oTabVal.setPropertyValue("InputMessage", msgInput)
5178  oTabVal.setPropertyValue("ErrorMessage",
5179  "ERRORE: Questo valore non è consentito.")
5180  oTabVal.setPropertyValue("ShowErrorMessage", err)
5181  oTabVal.ErrorAlertStyle = uno.Enum(
5182  "com.sun.star.sheet.ValidationAlertStyle", "STOP")
5183  oTabVal.Type = uno.Enum("com.sun.star.sheet.ValidationType", "LIST")
5184  oTabVal.Operator = uno.Enum("com.sun.star.sheet.ConditionOperator",
5185  "EQUAL")
5186  oTabVal.setFormula1(lista_val)
5187  oCell.setPropertyValue("Validation", oTabVal)
5188 
5189 
5191  oDoc = LeenoUtils.getDocument()
5192  oCell = oDoc.CurrentSelection
5193  oSheet = oDoc.CurrentController.ActiveSheet
5194 
5195  i = oCell.RangeAddress.StartRow
5196  n = oCell.Rows.Count
5197  oSheet.getRows().removeByIndex(i, n)
5198 
5199 
5200 
5201 def comando(cmd):
5202  '''
5203  Esegue un comando di menù.
5204  cmd { string } : nome del comando di menù
5205 
5206  Elenco comandi:
5207  'DeletePrintArea' = Cancella l'area di stampa
5208  'ShowDependents' = Mostra le celle dipendenti
5209  'ClearArrowDependents' = elimina frecce celle dipendenti
5210  'Undo' = Annulla ultimo comando
5211  'CalculateHard' = Ricalcolo incondizionato
5212  '''
5214  desktop = LeenoUtils.getDesktop()
5215  oFrame = desktop.getCurrentFrame()
5216  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
5217  'com.sun.star.frame.DispatchHelper', ctx)
5218  dispatchHelper.executeDispatch(oFrame, ".uno:" + cmd, "", 0,
5219  list())
5220 
5221 
5222 
5225 
5226 
5227 def delete(arg):
5228  '''
5229  Elimina righe o colonne.
5230  arg { string } : 'R' per righe
5231  'C' per colonne
5232  '''
5233  # oDoc = LeenoUtils.getDocument()
5234  # oSheet = oDoc.CurrentController.ActiveSheet
5236  desktop = LeenoUtils.getDesktop()
5237  oFrame = desktop.getCurrentFrame()
5238  oProp = PropertyValue()
5239  oProp.Name = 'Flags'
5240  oProp.Value = arg
5241  properties = (oProp, )
5242 
5243  dispatchHelper = ctx.ServiceManager.createInstanceWithContext(
5244  'com.sun.star.frame.DispatchHelper', ctx)
5245  dispatchHelper.executeDispatch(oFrame, ".uno:DeleteCell", "", 0, properties)
5246 
5247 
5248 
5249 def paste_clip(arg=None, insCells=0):
5250  oDoc = LeenoUtils.getDocument()
5251  # oSheet = oDoc.CurrentController.ActiveSheet
5253  desktop = LeenoUtils.getDesktop()
5254  oFrame = desktop.getCurrentFrame()
5255  oProp = []
5256  oProp0 = PropertyValue()
5257  oProp0.Name = 'Flags'
5258  oProp0.Value = 'A'
5259  oProp1 = PropertyValue()
5260  oProp1.Name = 'FormulaCommand'
5261  oProp1.Value = 0
5262  oProp2 = PropertyValue()
5263  oProp2.Name = 'SkipEmptyCells'
5264  oProp2.Value = False
5265  oProp3 = PropertyValue()
5266  oProp3.Name = 'Transpose'
5267  oProp3.Value = False
5268  oProp4 = PropertyValue()
5269  oProp4.Name = 'AsLink'
5270  oProp4.Value = False
5271  oProp.append(oProp0)
5272  oProp.append(oProp1)
5273  oProp.append(oProp2)
5274  oProp.append(oProp3)
5275  oProp.append(oProp4)
5276  # insert mode ON
5277  if insCells == 1:
5278  oProp5 = PropertyValue()
5279  oProp5.Name = 'MoveMode'
5280  oProp5.Value = 0
5281  oProp.append(oProp5)
5282  properties = tuple(oProp)
5283 
5284  dispatchHelper = ctx.ServiceManager.createInstanceWithContext('com.sun.star.frame.DispatchHelper', ctx)
5285  dispatchHelper.executeDispatch(oFrame, '.uno:InsertContents', '', 0, properties)
5286  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) # unselect
5287 
5288 
5289 
5291  '''
5292  Incolla solo il formato cella
5293  '''
5294  oDoc = LeenoUtils.getDocument()
5296  desktop = LeenoUtils.getDesktop()
5297  oFrame = desktop.getCurrentFrame()
5298  oProp = []
5299  oProp0 = PropertyValue()
5300  oProp0.Name = 'Flags'
5301  oProp0.Value = 'T'
5302  oProp1 = PropertyValue()
5303  oProp1.Name = 'FormulaCommand'
5304  oProp1.Value = 0
5305  oProp2 = PropertyValue()
5306  oProp2.Name = 'SkipEmptyCells'
5307  oProp2.Value = False
5308  oProp3 = PropertyValue()
5309  oProp3.Name = 'Transpose'
5310  oProp3.Value = False
5311  oProp4 = PropertyValue()
5312  oProp4.Name = 'AsLink'
5313  oProp4.Value = False
5314  oProp.append(oProp0)
5315  oProp.append(oProp1)
5316  oProp.append(oProp2)
5317  oProp.append(oProp3)
5318  oProp.append(oProp4)
5319  properties = tuple(oProp)
5320  dispatchHelper = ctx.ServiceManager.createInstanceWithContext('com.sun.star.frame.DispatchHelper', ctx)
5321  dispatchHelper.executeDispatch(oFrame, '.uno:InsertContents', '', 0, properties)
5322  oDoc.CurrentController.select(oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")) # unselect
5323 
5324 
5325 
5327  '''
5328  A partire dalla selezione di un range di celle in cui alcune righe e/o
5329  colonne sono nascoste, mette in clipboard solo il contenuto delle celle
5330  visibili.
5331  Liberamente ispirato a "Copy only visible cells" http://bit.ly/2j3bfq2
5332  '''
5333  oDoc = LeenoUtils.getDocument()
5334  oSheet = oDoc.CurrentController.ActiveSheet
5335  try:
5336  oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
5337  except AttributeError:
5338  oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
5339  # IS = oRangeAddress.Sheet
5340  SC = oRangeAddress.StartColumn
5341  EC = oRangeAddress.EndColumn
5342  SR = oRangeAddress.StartRow
5343  ER = oRangeAddress.EndRow
5344  if EC == 1023:
5345  EC = SheetUtils.getUsedArea(oSheet).EndColumn
5346  if ER == 1048575:
5347  ER = SheetUtils.getUsedArea(oSheet).EndRow
5348  righe = list()
5349  colonne = list()
5350  i = 0
5351  for nRow in range(SR, ER + 1):
5352  if not oSheet.getCellByPosition(SR, nRow).Rows.IsVisible:
5353  righe.append(i)
5354  i += 1
5355  i = 0
5356  for nCol in range(SC, EC + 1):
5357  if not oSheet.getCellByPosition(nCol, nRow).Columns.IsVisible:
5358  colonne.append(i)
5359  i += 1
5360 
5361  if not oDoc.getSheets().hasByName('tmp_clip'):
5362  sheet = oDoc.createInstance("com.sun.star.sheet.Spreadsheet")
5363  tmp = oDoc.Sheets.insertByName('tmp_clip', sheet)
5364  tmp = oDoc.getSheets().getByName('tmp_clip')
5365 
5366  oCellAddress = tmp.getCellByPosition(0, 0).getCellAddress()
5367  tmp.copyRange(oCellAddress, oRangeAddress)
5368 
5369  for i in reversed(righe):
5370  tmp.getRows().removeByIndex(i, 1)
5371  for i in reversed(colonne):
5372  tmp.getColumns().removeByIndex(i, 1)
5373 
5374  oRange = tmp.getCellRangeByPosition(0, 0, EC - SC - len(colonne),
5375  ER - SR - len(righe))
5376  oDoc.CurrentController.select(oRange)
5377 
5379  desktop = LeenoUtils.getDesktop()
5380  oFrame = desktop.getCurrentFrame()
5381  dispatchHelper = ctx.ServiceManager.createInstanceWithContext('com.sun.star.frame.DispatchHelper', ctx)
5382  dispatchHelper.executeDispatch(oFrame, ".uno:Copy", "", 0, list())
5383  oDoc.Sheets.removeByName('tmp_clip')
5384  oDoc.CurrentController.setActiveSheet(oSheet)
5385  oDoc.CurrentController.select(oSheet.getCellRangeByPosition(SC, SR, EC, ER))
5386 
5387 
5388 # LeggiPosizioneCorrente ###########################################################
5390  '''
5391  Restituisce la tupla (IDcolonna, IDriga, NameSheet) della posizione corrente
5392  '''
5393  oDoc = LeenoUtils.getDocument()
5394  oSheet = oDoc.CurrentController.ActiveSheet
5395  try:
5396  if oDoc.getCurrentSelection().getRangeAddresses()[0]:
5397  nRow = oDoc.getCurrentSelection().getRangeAddresses()[0].StartRow
5398  nCol = oDoc.getCurrentSelection().getRangeAddresses(
5399  )[0].StartColumn
5400  except AttributeError:
5401  nRow = oDoc.getCurrentSelection().getRangeAddress().StartRow
5402  nCol = oDoc.getCurrentSelection().getRangeAddress().StartColumn
5403  return (nCol, nRow, oSheet.Name)
5404 
5405 
5407 
5408 
5410  '''
5411  Comando di menu per numera_voci()
5412  '''
5413  numera_voci(1)
5414 
5415 
5416 def numera_voci(bit=1): #
5417  '''
5418  @@@ MODIFICA IN CORSO CON 'LeenoSheetUtils.numeraVoci'
5419  bit { integer } : 1 rinumera tutto
5420  0 rinumera dalla voce corrente in giù
5421  '''
5422  oDoc = LeenoUtils.getDocument()
5423  oSheet = oDoc.CurrentController.ActiveSheet
5424  lastRow = SheetUtils.getUsedArea(oSheet).EndRow + 1
5425  lrow = LeggiPosizioneCorrente()[1]
5426  n = 1
5427 
5428  if bit == 0:
5429  for x in reversed(range(0, lrow)):
5430  if(
5431  oSheet.getCellByPosition(1, x).CellStyle in ('comp Art-EP', 'comp Art-EP_R') and
5432  oSheet.getCellByPosition(1, x).CellBackColor != 15066597):
5433  n = oSheet.getCellByPosition(0, x).Value + 1
5434  break
5435  for row in range(lrow, lastRow):
5436  if oSheet.getCellByPosition(1, row).CellBackColor == 15066597:
5437  oSheet.getCellByPosition(0, row).String = ''
5438  elif oSheet.getCellByPosition(1,row).CellStyle in ('comp Art-EP', 'comp Art-EP_R'):
5439  oSheet.getCellByPosition(0, row).Value = n
5440  n += 1
5441  if bit == 1:
5442  for row in range(0, lastRow):
5443  # ~if oSheet.getCellByPosition(1,row).CellBackColor == 15066597:
5444  # ~oSheet.getCellByPosition(0,row).String = ''
5445  # ~elif oSheet.getCellByPosition(1,row).CellStyle in('comp Art-EP', 'comp Art-EP_R'):
5446  # ~oSheet.getCellByPosition(0,row).Value = n
5447  # ~n = n+1
5448  if oSheet.getCellByPosition(1, row).CellStyle in ('comp Art-EP','comp Art-EP_R'):
5449  oSheet.getCellByPosition(0, row).Value = n
5450  n = n + 1
5451  # ~oSheet.getCellByPosition(0,row).Value = n
5452  # ~n = n+1
5453 
5454 
5455 
5456 
5457 
5459  '''Crea la Lista Lavorazioni e Forniture dall'Elenco Prezzi,
5460 per la formulazione dell'offerta'''
5461  chiudi_dialoghi()
5462  oDoc = LeenoUtils.getDocument()
5463  GotoSheet('Elenco Prezzi')
5464  genera_sommario()
5465  oSheet = oDoc.CurrentController.ActiveSheet
5466  try:
5467  oDoc.Sheets.copyByName(oSheet.Name, 'Elenco Prezzi', 5)
5468  except Exception:
5469  pass
5470  nSheet = oDoc.getSheets().getByIndex(5).Name
5471  GotoSheet(nSheet)
5472  oSheet = oDoc.CurrentController.ActiveSheet
5473  oSheet.Name = 'Richiesta offerta'
5474  setTabColor(10079487)
5475  oSheet = oDoc.CurrentController.ActiveSheet
5476  fine = SheetUtils.getUsedArea(oSheet).EndRow + 1
5477  oRange = oSheet.getCellRangeByPosition(12, 3, 12, fine)
5478  aSaveData = oRange.getDataArray()
5479  oRange = oSheet.getCellRangeByPosition(3, 3, 3, fine)
5480  oRange.CellStyle = 'EP statistiche_q'
5481  oRange.setDataArray(aSaveData)
5482  oSheet.getCellByPosition(3, 2).String = 'Quantità\na Computo'
5483  oSheet.getCellByPosition(5, 2).String = 'Prezzo Unitario\nin lettere'
5484  oSheet.getCellByPosition(6, 2).String = 'Importo'
5485  oSheet.Columns.removeByIndex(7, 100)
5486  oSheet.getColumns().getByName("D").IsVisible = True
5487  oSheet.getColumns().getByName("F").IsVisible = True
5488  oSheet.getColumns().getByName("G").IsVisible = True
5489  oSheet.getColumns().getByName("A").Columns.Width = 1600
5490  oSheet.getColumns().getByName("B").Columns.Width = 8000
5491  oSheet.getColumns().getByName("C").Columns.Width = 1200
5492  oSheet.getColumns().getByName("D").Columns.Width = 1600
5493  oSheet.getColumns().getByName("E").Columns.Width = 1500
5494  oSheet.getColumns().getByName("F").Columns.Width = 4000
5495  oSheet.getColumns().getByName("G").Columns.Width = 1800
5496  oDoc.CurrentController.freezeAtPosition(0, 1)
5497 
5498  formule = list()
5499  for x in range(3, SheetUtils.getUsedArea(oSheet).EndRow - 1):
5500  formule.append([
5501  '=IF(E' + str(x + 1) + '<>"";D' + str(x + 1) + '*E' + str(x + 1) +
5502  ';""'
5503  ])
5504  oSheet.getCellRangeByPosition(6, 3, 6,
5505  len(formule) + 2).CellBackColor = 15757935
5506  oRange = oSheet.getCellRangeByPosition(6, 3, 6, len(formule) + 2)
5507  formule = tuple(formule)
5508  oRange.setFormulaArray(formule)
5509 
5510  oSheet.getCellRangeByPosition(
5511  5, 3, 5,
5512  fine).clearContents(VALUE + DATETIME + STRING + ANNOTATION + FORMULA +
5513  HARDATTR + OBJECTS + EDITATTR + FORMATTED)
5514 
5515  oSheet.getCellRangeByPosition(4, 3, 4, fine + 1).clearContents(
5516  VALUE + FORMULA + STRING) # cancella prezzi unitari
5517  oSheet.getCellRangeByPosition(0, fine - 1, 100, fine +
5518  1).clearContents(VALUE + FORMULA + STRING)
5519  oSheet.Columns.insertByIndex(0, 1)
5520 
5521  oSrc = oSheet.getCellRangeByPosition(1, 0, 1, fine).RangeAddress
5522  oDest = oSheet.getCellByPosition(0, 0).CellAddress
5523  oSheet.copyRange(oDest, oSrc)
5524  oSheet.getCellByPosition(0, 2).String = "N."
5525  for x in range(3, fine - 1):
5526  oSheet.getCellByPosition(0, x).Value = x - 2
5527  oSheet.getCellRangeByPosition(0, 1, 0, fine).CellStyle = "EP-aS"
5528  for y in (2, 3):
5529  for x in range(3, fine - 1):
5530  if oSheet.getCellByPosition(y, x).Type.value == 'FORMULA':
5531  oSheet.getCellByPosition(y,
5532  x).String = oSheet.getCellByPosition(
5533  y, x).String
5534  for x in range(3, fine - 1):
5535  if oSheet.getCellByPosition(5, x).Type.value == 'FORMULA':
5536  oSheet.getCellByPosition(5, x).Value = oSheet.getCellByPosition(
5537  5, x).Value
5538  oSheet.getColumns().getByName("A").Columns.Width = 650
5539 
5540  oSheet.getCellByPosition(
5541  7, fine).Formula = "=SUBTOTAL(9;H2:H" + str(fine + 1) + ")"
5542  oSheet.getCellByPosition(2, fine).String = "TOTALE COMPUTO"
5543  oSheet.getCellRangeByPosition(0, fine, 7, fine).CellStyle = "Comp TOTALI"
5544  oSheet.Rows.removeByIndex(fine - 1, 1)
5545  oSheet.Rows.removeByIndex(0, 2)
5546  oSheet.getCellByPosition(2,
5547  fine + 3).String = "(diconsi euro - in lettere)"
5548  oSheet.getCellRangeByPosition(2, fine + 3, 6,
5549  fine + 3).CellStyle = "List-intest_med_c"
5550  oSheet.getCellByPosition(2, fine +
5551  5).String = "Pari a Ribasso del ___________%"
5552  oSheet.getCellByPosition(2, fine + 8).String = "(ribasso in lettere)"
5553  oSheet.getCellRangeByPosition(2, fine + 8, 6,
5554  fine + 8).CellStyle = "List-intest_med_c"
5555  # INSERISCI LA DATA E L'OFFERENTE
5556  oSheet.getCellByPosition(
5557  2,
5558  fine + 10).Formula = '=CONCATENATE("Data, ";TEXT(NOW();"GG/MM/AAAA"))'
5559  oSheet.getCellRangeByPosition(2, fine + 10, 2,
5560  fine + 10).CellStyle = "Ultimus"
5561  oSheet.getCellByPosition(2, fine + 12).String = "L'OFFERENTE"
5562  oSheet.getCellByPosition(2, fine + 12).CellStyle = 'centro_grassetto'
5563  oSheet.getCellByPosition(2, fine + 13).String = '(timbro e firma)'
5564  oSheet.getCellByPosition(2, fine + 13).CellStyle = 'centro_corsivo'
5565 
5566  # CONSOLIDA LA DATA
5567  oRange = oSheet.getCellRangeByPosition(2, fine + 10, 2, fine + 10)
5568  # Flags = com.sun.star.sheet.CellFlags.FORMULA
5569  aSaveData = oRange.getDataArray()
5570  oRange.setDataArray(aSaveData)
5571  oSheet.getCellRangeByPosition(
5572  0, 0,
5573  SheetUtils.getUsedArea(oSheet).EndColumn,
5574  SheetUtils.getUsedArea(oSheet).EndRow).CellBackColor = -1
5575  # imposta stile pagina ed intestazioni
5576  oSheet.PageStyle = 'PageStyle_COMPUTO_A4'
5577  pagestyle = oDoc.StyleFamilies.getByName('PageStyles').getByName(
5578  'PageStyle_COMPUTO_A4')
5579  pagestyle.HeaderIsOn = True
5580  # left = pagestyle.RightPageHeaderContent.LeftText.Text
5581 
5582  pagestyle.HeaderIsOn = True
5583  oHContent = pagestyle.RightPageHeaderContent
5584  filename = '' # uno.fileUrlToSystemPath(oDoc.getURL())
5585  if len(filename) > 50:
5586  filename = filename[:20] + ' ... ' + filename[-20:]
5587  oHContent.LeftText.String = filename
5588  oHContent.CenterText.String = ''
5589  oHContent.RightText.String = ''.join(''.join(''.join(
5590  str(datetime.now()).split('.')[0].split(' ')).split('-')).split(':'))
5592  pagestyle.RightPageHeaderContent = oHContent
5593  _gotoCella(0, 1)
5594  return
5595 
5596 
5597 
5599  '''
5600  Inserisce una nuova riga voce in Elenco Prezzi
5601  '''
5602  oDoc = LeenoUtils.getDocument()
5603  oDoc.enableAutomaticCalculation(False)
5604 
5605  oSheet = oDoc.CurrentController.ActiveSheet
5606  _gotoCella(0, 3)
5607  oSheet.getRows().insertByIndex(3, 1)
5608 
5609  oSheet.getCellByPosition(0, 3).CellStyle = "EP-aS"
5610  oSheet.getCellByPosition(1, 3).CellStyle = "EP-a"
5611  oSheet.getCellRangeByPosition(2, 3, 7, 3).CellStyle = "EP-mezzo"
5612  oSheet.getCellRangeByPosition(8, 3, 9, 3).CellStyle = "EP-sfondo"
5613  for el in (5, 11, 15, 19, 26):
5614  oSheet.getCellByPosition(el, 3).CellStyle = "EP-mezzo %"
5615 
5616  for el in (12, 16, 20, 21): # (12, 16, 20):
5617  oSheet.getCellByPosition(el, 3).CellStyle = 'EP statistiche_q'
5618 
5619  for el in (13, 17, 23, 24, 25): # (12, 16, 20):
5620  oSheet.getCellByPosition(el, 3).CellStyle = 'EP statistiche'
5621 
5622  oSheet.getCellRangeByPosition(0, 3, 26, 3).clearContents(HARDATTR)
5623  oSheet.getCellByPosition(11,
5624  3).Formula = '=IF(ISERROR(N4/$N$2);"--";N4/$N$2)'
5625  # oSheet.getCellByPosition(11, 3).Formula = '=N4/$N$2'
5626  oSheet.getCellByPosition(12, 3).Formula = '=SUMIF(AA;A4;BB)'
5627  oSheet.getCellByPosition(13, 3).Formula = '=SUMIF(AA;A4;cEuro)'
5628 
5629  # copio le formule dalla riga sotto
5630  oRangeAddress = oSheet.getCellRangeByPosition(15, 4, 26,
5631  4).getRangeAddress()
5632  oCellAddress = oSheet.getCellByPosition(15, 3).getCellAddress()
5633  oSheet.copyRange(oCellAddress, oRangeAddress)
5634  oCell = oSheet.getCellByPosition(2, 3)
5635  valida_cella(
5636  oCell,
5637  '"cad";"corpo";"dm";"dm²";"dm³";"kg";"lt";"m";"m²";"m³";"q";"t";""',
5638  titoloInput='Scegli...',
5639  msgInput='Unità di misura')
5640  oDoc.enableAutomaticCalculation(True)
5641 
5642 
5643 
5644 def rigenera_voce(lrow=None):
5645  '''
5646  Ripristina/ricalcola le formule di descrizione e somma di una voce.
5647  in COMPUTO, VARIANTE e CONTABILITA
5648  '''
5649  oDoc = LeenoUtils.getDocument()
5650  oSheet = oDoc.CurrentController.ActiveSheet
5651  try:
5652  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
5653  except Exception:
5654  return
5655  sopra = sStRange.RangeAddress.StartRow
5656  sotto = sStRange.RangeAddress.EndRow
5657  # attiva la progressbar
5658 # progress = Dialogs.Progress(Title='Rigenerazione in corso...', Text="Formule")
5659 # progress.setLimits(0, sotto - sopra)
5660 # k = 0
5661 # progress.setValue(k)
5662 # progress.show()
5663 
5664  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
5665 # progress.setValue(10)
5666  oSheet.getCellByPosition(
5667  1, sopra + 1
5668  ).CellStyle = 'comp Art-EP_R'
5669  oSheet.getCellByPosition(
5670  2, sopra + 1
5671  ).Formula = '=IF(LEN(VLOOKUP(B' + str(
5672  sopra + 2
5673  ) + ';elenco_prezzi;2;FALSE()))<($S1.$H$337+$S1.$H$338);VLOOKUP(B' + str(
5674  sopra + 2
5675  ) + ';elenco_prezzi;2;FALSE());CONCATENATE(LEFT(VLOOKUP(B' + str(
5676  sopra + 2
5677  ) + ';elenco_prezzi;2;FALSE());$S1.$H$337);" [...] ";RIGHT(VLOOKUP(B' + str(
5678  sopra + 2) + ';elenco_prezzi;2;FALSE());$S1.$H$338)))'
5679  oSheet.getCellByPosition(
5680  8, sotto).Formula = '=CONCATENATE("SOMMANO [";VLOOKUP(B' + str(
5681  sopra + 2) + ';elenco_prezzi;3;FALSE());"]")'
5682  oSheet.getCellByPosition(
5683  9,
5684  sotto).Formula = '=SUBTOTAL(9;J' + str(sopra +
5685  2) + ':J' + str(sotto +
5686  1) + ')'
5687  oSheet.getCellByPosition(11, sotto).Formula = '=VLOOKUP(B' + str(
5688  sopra + 2) + ';elenco_prezzi;5;FALSE())'
5689  oSheet.getCellByPosition(13, sotto).Formula = '=J' + str(sotto + 1)
5690  oSheet.getCellByPosition(
5691  17,
5692  sotto).Formula = '=AB' + str(sotto + 1) + '*J' + str(sotto + 1)
5693  # oSheet.getCellByPosition(18, sotto).Formula = '=J'+ str(sotto+1) +'*L'+ str(sotto+1)
5694  oSheet.getCellByPosition(
5695  18, sotto).Formula = '=IF(VLOOKUP(B' + str(
5696  sopra + 2) + ';elenco_prezzi;3;FALSE())="%";J' + str(
5697  sotto + 1) + '*L' + str(sotto + 1) + '/100;J' + str(
5698  sotto + 1) + '*L' + str(sotto + 1) + ')'
5699  oSheet.getCellByPosition(27, sotto).Formula = '=VLOOKUP(B' + str(
5700  sopra + 2) + ';elenco_prezzi;4;FALSE())'
5701  oSheet.getCellByPosition(
5702  28,
5703  sotto).Formula = '=S' + str(sotto + 1) + '-AE' + str(sotto + 1)
5704  oSheet.getCellByPosition(29, sotto).Formula = '=VLOOKUP(B' + str(
5705  sopra + 2) + ';elenco_prezzi;6;FALSE())'
5706  oSheet.getCellByPosition(
5707  30, sotto
5708  ).Formula = '=IF(AD' + str(sotto + 1) + '<>""; PRODUCT(AD' + str(
5709  sotto + 1) + '*S' + str(sotto + 1) + '))'
5710  oSheet.getCellByPosition(35, sotto).Formula = '=B' + str(sopra + 2)
5711  oSheet.getCellByPosition(
5712  36, sotto
5713  ).Formula = '=IF(ISERROR(S' + str(sotto + 1) + ');"";IF(S' + str(
5714  sotto + 1) + '<>"";S' + str(sotto + 1) + ';""))'
5715 
5716  formule = []
5717  for n in range (sopra + 2, sotto):
5718 # k += 1
5719 # progress.setValue(k)
5720 
5721  # elimina i collegamenti esterni
5722  if oSheet.getCellByPosition(2, n).CellStyle == 'comp 1-a' or \
5723  oSheet.getCellByPosition(2, n).CellStyle == 'comp 1-a ROSSO' and \
5724  "'" in oSheet.getCellByPosition(2, n).Formula:
5725  ff = oSheet.getCellByPosition(2, n).Formula.split("'")
5726  if len(ff) > 1:
5727  oSheet.getCellByPosition(2, n).Formula = ff[0] + ff[-1][1:]
5728 
5729  rosso = 0
5730  for x in range (5, 8):
5731  if 'ROSSO' in oSheet.getCellByPosition(x, n).CellStyle:
5732  rosso = 1
5733  break
5734  if rosso == 1:
5735  formula = (['=IF(PRODUCT(E' + str(n + 1) + ':I' +
5736  str(n + 1) + ')=0;"";-PRODUCT(E' + str(n + 1) +
5737  ':I' + str(n + 1) + '))'])
5738  else:
5739  formula = (['=IF(PRODUCT(E' + str(n + 1) + ':I' +
5740  str(n + 1) + ')=0;"";PRODUCT(E' + str(n + 1) +
5741  ':I' + str(n + 1) + '))'])
5742  if oSheet.getCellByPosition(4, n).Value < 0:
5743  formula = (['=IF(PRODUCT(E' + str(n + 1) + ':I' +
5744  str(n + 1) + ')=0;"";PRODUCT(E' + str(n + 1) +
5745  ':I' + str(n + 1) + '))'])
5746  formule.append(formula)
5747 
5748  oRange = oSheet.getCellRangeByPosition(9, sopra + 2, 9, sotto - 1)
5749  formule = tuple(formule)
5750  # ~oDoc.CurrentController.select(oRange)
5751  # ~DLG.chi(formule)
5752  oRange.setFormulaArray(formule)
5753 
5754  if oSheet.Name in ('CONTABILITA'):
5755 # progress.setValue(10)
5756  oSheet.getCellByPosition(
5757  2, sopra + 1
5758  ).Formula = '=IF(LEN(VLOOKUP(B' + str(
5759  sopra + 2
5760  ) + ';elenco_prezzi;2;FALSE()))<($S1.$H$335+$S1.$H$336);VLOOKUP(B' + str(
5761  sopra + 2
5762  ) + ';elenco_prezzi;2;FALSE());CONCATENATE(LEFT(VLOOKUP(B' + str(
5763  sopra + 2
5764  ) + ';elenco_prezzi;2;FALSE());$S1.$H$335);" [...] ";RIGHT(VLOOKUP(B' + str(
5765  sopra + 2) + ';elenco_prezzi;2;FALSE());$S1.$H$336)))'
5766  oSheet.getCellByPosition(
5767  8, sotto - 1
5768  ).Formula = '=CONCATENATE("Somma positivi e negativi [";VLOOKUP(B' + str(
5769  sopra + 2) + ';elenco_prezzi;3;FALSE());"]")'
5770  oSheet.getCellByPosition(
5771  8, sotto).Formula = '=CONCATENATE("SOMMANO [";VLOOKUP(B' + str(
5772  sopra + 2) + ';elenco_prezzi;3;FALSE());"]")'
5773  oSheet.getCellByPosition(
5774  9, sotto -
5775  1).Formula = '=IF(SUBTOTAL(9;J' + str(sopra + 2) + ':J' + str(
5776  sotto) + ')<0;"";SUBTOTAL(9;J' + str(
5777  sopra + 2) + ':J' + str(sotto) + '))'
5778  oSheet.getCellByPosition(
5779  11, sotto -
5780  1).Formula = '=IF(SUBTOTAL(9;L' + str(sopra + 2) + ':L' + str(
5781  sotto) + ')<0;"";SUBTOTAL(9;L' + str(
5782  sopra + 2) + ':L' + str(sotto) + '))'
5783  oSheet.getCellByPosition(
5784  9, sotto).Formula = '=J' + str(sotto) + '-L' + str(sotto)
5785  oSheet.getCellByPosition(13, sotto).Formula = '=VLOOKUP(B' + str(
5786  sopra + 2) + ';elenco_prezzi;5;FALSE())'
5787  oSheet.getCellByPosition(
5788  15, sotto).Formula = '=IF(VLOOKUP(B' + str(
5789  sopra + 2) + ';elenco_prezzi;3;FALSE())="%";J' + str(
5790  sotto + 1) + '*N' + str(sotto + 1) + '/100;J' + str(
5791  sotto + 1) + '*N' + str(sotto + 1) + ')'
5792  oSheet.getCellByPosition(
5793  17,
5794  sotto).Formula = '=J' + str(sotto + 1) + '*AB' + str(sotto + 1)
5795  oSheet.getCellByPosition(27, sotto).Formula = '=VLOOKUP(B' + str(
5796  sopra + 2) + ';elenco_prezzi;4;FALSE())'
5797  oSheet.getCellByPosition(
5798  28,
5799  sotto).Formula = '=P' + str(sotto + 1) + '-AE' + str(sotto + 1)
5800  oSheet.getCellByPosition(29, sotto).Formula = '=VLOOKUP(B' + str(
5801  sopra + 2) + ';elenco_prezzi;6;FALSE())'
5802  oSheet.getCellByPosition(
5803  30, sotto
5804  ).Formula = '=IF(AD' + str(sotto + 1) + '<>""; PRODUCT(AD' + str(
5805  sotto + 1) + '*P' + str(sotto + 1) + '))'
5806  oSheet.getCellRangeByName('A2').Formula = '=P2'
5807  oSheet.getCellByPosition(9, sotto -
5808  1).CellStyle = 'Comp-Variante num sotto'
5809  formule = []
5810  for n in range (sopra + 2, sotto - 1):
5811 # k += 1
5812 # progress.setValue(k)
5813 
5814  # elimina i collegamenti esterni
5815  if oSheet.getCellByPosition(2, n).CellStyle == 'comp 1-a' or \
5816  oSheet.getCellByPosition(2, n).CellStyle == 'comp 1-a ROSSO' and \
5817  "'" in oSheet.getCellByPosition(2, n).Formula:
5818  ff = oSheet.getCellByPosition(2, n).Formula.split("'")
5819  if len(ff) > 1:
5820  oSheet.getCellByPosition(2, n).Formula = ff[0] + ff[-1][1:]
5821 
5822  rosso = 0
5823  for x in range (5, 8):
5824  if 'ROSSO' in oSheet.getCellByPosition(x, n).CellStyle:
5825  rosso = 1
5826  break
5827  if rosso == 1:
5828  formule.append (['=IF(PRODUCT(E' + str(n + 1) + ':I' +
5829  str(n + 1) + ')>=0;"";PRODUCT(E' +
5830  str(n + 1) + ':I' + str(n + 1) + ')*-1)', '',
5831  '=IF(PRODUCT(E' + str(n+1) + ':I' +
5832  str(n+1) + ')<=0;"";PRODUCT(E' + str(
5833  n + 1) + ':I' + str(n+1) + '))'])
5834  else:
5835  formule.append (['=IF(PRODUCT(E' + str(n + 1) + ':I' +
5836  str(n + 1) + ')<=0;"";PRODUCT(E' +
5837  str(n + 1) + ':I' + str(n + 1) + '))', '',
5838  '=IF(PRODUCT(E' + str(n+1) + ':I' +
5839  str(n+1) + ')>=0;"";PRODUCT(E' + str(
5840  n + 1) + ':I' + str(n+1) + ')*-1)'])
5841 
5842  oRange = oSheet.getCellRangeByPosition(9, sopra + 2, 11, sotto - 2)
5843  formule = tuple(formule)
5844  oRange.setFormulaArray(formule)
5845 # progress.hide()
5846 
5847 
5848 
5849 
5850 def rigenera_tutte(arg=None, ):
5851  '''
5852  Ripristina le formule in tutto il foglio
5853  '''
5854 
5856 
5857  chiudi_dialoghi()
5858  oDoc = LeenoUtils.getDocument()
5859 
5860  riordina_ElencoPrezzi(oDoc)
5861 
5862  oSheet = oDoc.CurrentController.ActiveSheet
5863  nome = oSheet.Name
5864  stili_cat = LeenoUtils.getGlobalVar('stili_cat')
5865 
5866 
5867  # attiva la progressbar
5868  progress = Dialogs.Progress(Title='Rigenerazione di ' + nome + ' in corso...', Text="Lettura dati")
5869  progress.setLimits(0, LeenoSheetUtils.cercaUltimaVoce(oSheet))
5870  progress.setValue(0)
5871  progress.show()
5872  if nome in ('COMPUTO', 'VARIANTE', 'CONTABILITA'):
5873  try:
5874  oSheet = oDoc.Sheets.getByName(nome)
5875  row = LeenoSheetUtils.prossimaVoce(oSheet, 0, 1, True)
5876  oDoc.CurrentController.select(oSheet.getCellByPosition(0, row))
5877  last = LeenoSheetUtils.cercaUltimaVoce(oSheet)
5878  while row < last:
5879  progress.setValue(row)
5880  rigenera_voce(row)
5881  # ~sistema_stili(row)
5882  row = LeenoSheetUtils.prossimaVoce(oSheet, row, 1, True)
5883  except Exception:
5884  pass
5885  rigenera_parziali(True)
5886  Rinumera_TUTTI_Capitoli2(oSheet)
5887  numera_voci()
5888  fissa()
5889  progress.hide()
5890  # ~comando("CalculateHard")
5892 
5893 
5894 
5895 def sistema_stili(lrow=None):
5896  '''
5897  Ripristina stili di cella per una singola voce.
5898  in COMPUTO, VARIANTE e CONTABILITA
5899  '''
5900  # ~lrow = LeggiPosizioneCorrente()[1]
5901  oDoc = LeenoUtils.getDocument()
5902  oSheet = oDoc.CurrentController.ActiveSheet
5903  try:
5904  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
5905  except Exception:
5906  return
5907  sopra = sStRange.RangeAddress.StartRow
5908  sotto = sStRange.RangeAddress.EndRow
5909  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
5910  for x in range(sopra + 1, sotto - 1):
5911  if 'comp 1-a' in oSheet.getCellByPosition(2, x).CellStyle:
5912  oSheet.getCellByPosition(9, x).CellStyle = 'Blu'
5913  if oSheet.getCellByPosition(9, x).Value < 0:
5914  oSheet.getCellByPosition(2, x).CellStyle = 'comp 1-a ROSSO'
5915  oSheet.getCellByPosition(5,
5916  x).CellStyle = 'comp 1-a PU ROSSO'
5917  oSheet.getCellByPosition(
5918  6, x).CellStyle = 'comp 1-a LUNG ROSSO'
5919  oSheet.getCellByPosition(
5920  7, x).CellStyle = 'comp 1-a LARG ROSSO'
5921  oSheet.getCellByPosition(
5922  8, x).CellStyle = 'comp 1-a peso ROSSO'
5923  else:
5924  oSheet.getCellByPosition(2, x).CellStyle = 'comp 1-a'
5925  oSheet.getCellByPosition(5, x).CellStyle = 'comp 1-a PU'
5926  oSheet.getCellByPosition(6, x).CellStyle = 'comp 1-a LUNG'
5927  oSheet.getCellByPosition(7, x).CellStyle = 'comp 1-a LARG'
5928  oSheet.getCellByPosition(8, x).CellStyle = 'comp 1-a peso'
5929 
5930  if oSheet.Name in ('CONTABILITA'):
5931  oSheet.getCellByPosition(9, sopra + 1).CellStyle = 'vuote2'
5932  oSheet.getCellByPosition(11, sopra +
5933  1).CellStyle = 'Comp-Bianche in mezzo_R'
5934  oSheet.getCellByPosition(9, sotto -
5935  1).CellStyle = 'Comp-Variante num sotto'
5936  oSheet.getCellByPosition(9,
5937  sotto).CellStyle = 'Comp-Variante num sotto'
5938  oSheet.getCellByPosition(13, sotto).CellStyle = 'comp sotto Unitario'
5939  oSheet.getCellByPosition(15,
5940  sotto).CellStyle = 'comp sotto Euro Originale'
5941  oSheet.getCellByPosition(17,
5942  sotto).CellStyle = 'comp sotto Euro Originale'
5943  oSheet.getCellByPosition(11, sotto -
5944  1).CellStyle = 'Comp-Variante num sotto ROSSO'
5945  oSheet.getCellByPosition(11, sotto).CellStyle = 'comp sotto centro_R'
5946  oSheet.getCellByPosition(28, sotto).CellStyle = 'Comp-sotto euri'
5947  for x in range(sopra + 1, sotto):
5948  # ~oSheet.getCellByPosition(11, x).CellStyle = 'Blu ROSSO'
5949  if 'comp 1-a' in oSheet.getCellByPosition(2, x).CellStyle:
5950  oSheet.getCellByPosition(9, x).CellStyle = 'Blu'
5951  elif oSheet.getCellByPosition(
5952  2, x).CellStyle == 'comp sotto centro': # parziale
5953  oSheet.getCellByPosition(
5954  9, x).CellStyle = 'Comp-Variante num sotto'
5955 
5956  for x in range(sopra + 2, sotto - 1):
5957  test = 0
5958  for y in range(2, 8):
5959  if oSheet.getCellByPosition(y, x).String != '':
5960  test = 1
5961  break
5962  for y in range (2, 8):
5963  rosso = 0
5964  if 'ROSSO' in oSheet.getCellByPosition(y, x).CellStyle:
5965  rosso = 1
5966  break
5967  if str(test) + str(rosso) == '10':
5968  oSheet.getCellByPosition(9, x).Formula = '=IF(PRODUCT(E' + str(
5969  x + 1) + ':I' + str(x + 1) + ')=0;"";PRODUCT(E' + str(
5970  x + 1) + ':I' + str(x + 1) + '))'
5971  oSheet.getCellByPosition(2, x).CellStyle = 'comp 1-a'
5972  oSheet.getCellByPosition(5, x).CellStyle = 'comp 1-a PU'
5973  oSheet.getCellByPosition(6, x).CellStyle = 'comp 1-a LUNG'
5974  oSheet.getCellByPosition(7, x).CellStyle = 'comp 1-a LARG'
5975  oSheet.getCellByPosition(8, x).CellStyle = 'comp 1-a peso'
5976  oSheet.getCellByPosition(11, x).String = ''
5977  if str(test) + str(rosso) == '11':
5978  oSheet.getCellByPosition(
5979  11, x).Formula = '=IF(PRODUCT(E' + str(x + 1) + ':I' + str(
5980  x + 1) + ')=0;"";PRODUCT(E' + str(x + 1) + ':I' + str(
5981  x + 1) + '))'
5982  oSheet.getCellByPosition(2, x).CellStyle = 'comp 1-a ROSSO'
5983  oSheet.getCellByPosition(5, x).CellStyle = 'comp 1-a PU ROSSO'
5984  oSheet.getCellByPosition(6,
5985  x).CellStyle = 'comp 1-a LUNG ROSSO'
5986  oSheet.getCellByPosition(7,
5987  x).CellStyle = 'comp 1-a LARG ROSSO'
5988  oSheet.getCellByPosition(8,
5989  x).CellStyle = 'comp 1-a peso ROSSO'
5990  oSheet.getCellByPosition(9, x).String = ''
5991 
5992 
5993 
5994 def rigenera_parziali (arg=False):
5995  '''
5996  arg { boolean }: Se False rigenera solo voce corrente
5997  Rigenera i parziali di tutte le voci
5998  '''
5999  oDoc = LeenoUtils.getDocument()
6001  oSheet = oDoc.CurrentController.ActiveSheet
6002 
6003  if oSheet.Name not in ('COMPUTO', 'CONTABILITA', 'VARIANTE'):
6004  return
6005 
6006  sopra = 4
6007  sotto = SheetUtils.getLastUsedRow(oSheet) + 1
6008  lrow = LeggiPosizioneCorrente()[1]
6009 
6010  if arg == False:
6011  try:
6012  sopra = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.StartRow
6013  except:
6014  return
6015  sotto = LeenoComputo.circoscriveVoceComputo(oSheet, lrow).RangeAddress.EndRow
6016 
6017  # attiva la progressbar
6018  progress = Dialogs.Progress(Title='Rigenerazione in corso...', Text="Parziali")
6019  progress.setLimits(0, sotto - sopra)
6020  n = 0
6021  progress.setValue(n)
6022  progress.show()
6023  if lrow == True:
6024  sopra = lrow
6025  for i in range(sopra, sotto):
6026  n += 1
6027  progress.setValue(n)
6028  if 'Parziale [' in oSheet.getCellByPosition(8, i).Formula:
6029  parziale_core(oSheet, i)
6030  # ~oDoc.enableAutomaticCalculation(True)
6032  progress.hide()
6033  return
6034 
6035 
6036 
6037 def MENU_nuova_voce_scelta(): # assegnato a ctrl-shift-n
6038  '''
6039  Contestualizza in ogni tabella l'inserimento delle voci.
6040  '''
6041  oDoc = LeenoUtils.getDocument()
6043  # ~oDoc.enableAutomaticCalculation(False)
6044  oSheet = oDoc.CurrentController.ActiveSheet
6045 # lrow = LeggiPosizioneCorrente()[1]
6046 
6047  if oSheet.Name in ('COMPUTO', 'VARIANTE'):
6049  elif oSheet.Name == 'Analisi di Prezzo':
6051  elif oSheet.Name == 'CONTABILITA':
6052  # ~LeenoContab.insertVoceContabilita(oSheet, lrow) <<< non va
6053  ins_voce_contab()
6054  elif oSheet.Name == 'Elenco Prezzi':
6055  ins_voce_elenco()
6057  # ~oDoc.enableAutomaticCalculation(True)
6058 
6059 # nuova_voce_contab ##################################################
6060 def ins_voce_contab(lrow=0, arg=1, cod=None):
6061  '''
6062  @@@ MODIFICA IN CORSO CON 'LeenoContab.insertVoceContabilita
6063  Inserisce una nuova voce in CONTABILITA.
6064  '''
6065  oDoc = LeenoUtils.getDocument()
6066  # ~oSheet = oDoc.CurrentController.ActiveSheet
6067  oSheet = oDoc.Sheets.getByName('CONTABILITA')
6068 
6069  stili_contab = LeenoUtils.getGlobalVar('stili_contab')
6070  stili_cat = LeenoUtils.getGlobalVar('stili_cat')
6071 
6072  if lrow == 0:
6073  lrow = LeggiPosizioneCorrente()[1]
6074  if oSheet.getCellByPosition(0, lrow + 1).CellStyle == 'uuuuu':
6075  return
6076  # ~else:
6077  # ~lrow += 1
6078  # nome = oSheet.Name
6079  try:
6080  # controllo che non ci siano atti registrati
6081  partenza = cerca_partenza()
6082  if partenza[2] == '#reg':
6083  sblocca_cont()
6084  if LeenoUtils.getGlobalVar('sblocca_computo') == 0:
6085  return
6086  else:
6087  pass
6088 
6089  except Exception:
6090  pass
6091 
6092  stile = oSheet.getCellByPosition(0, lrow).CellStyle
6093  nSal = 0
6094  # ~if stile in stili_cat:
6095  # ~lrow += 1
6096  # ~stile = oSheet.getCellByPosition(0, lrow).CellStyle
6097  if stile == 'Ultimus_centro_bordi_lati':
6098  i = lrow
6099  while i != 0:
6100  if oSheet.getCellByPosition(23, i).Value != 0:
6101  nSal = int(oSheet.getCellByPosition(23, i).Value)
6102  break
6103  i -= 1
6104  while oSheet.getCellByPosition(0, lrow).CellStyle == stile:
6105  lrow += 1
6106  if oSheet.getCellByPosition(0, lrow).CellStyle == 'uuuuu':
6107  lrow += 1
6108  # nSal += 1
6109  # else
6110  elif stile == 'Comp TOTALI':
6111  pass
6112  if stile in stili_cat:
6113  lrow += 1
6114  elif stile in (stili_contab):
6115  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
6116  nSal = int(oSheet.getCellByPosition(23, sStRange.RangeAddress.StartRow + 1).Value)
6117  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow)
6118  # ~ if stile == 'comp Int_colonna_R_prima':
6119  # ~ lrow += 1
6120 
6121  oSheetto = oDoc.getSheets().getByName('S5')
6122  oRangeAddress = oSheetto.getCellRangeByPosition(0, 22, 48, 26).getRangeAddress()
6123  oCellAddress = oSheet.getCellByPosition(0, lrow).getCellAddress()
6124  oSheet.getRows().insertByIndex(lrow, 5) # inserisco le righe
6125  oSheet.copyRange(oCellAddress, oRangeAddress)
6126  # ~oSheet.getCellRangeByPosition(0, lrow, 48, lrow + 5).Rows.OptimalHeight = True
6127  _gotoCella(1, lrow + 1)
6128 
6129  # ~nSal = 1
6130  # ~if oSheet.getCellByPosition(0,lrow).queryIntersection(oSheet.getCellRangeByName('_Lib_'+str(nSal)).getRangeAddress()):
6131  # ~DLG.chi('appartiene')
6132  # ~else:
6133  # ~DLG.chi('nooooo')
6134  # ~return
6135 
6136  sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
6137  sopra = sStRange.RangeAddress.StartRow
6138  data = 0.0
6139  for n in reversed(range(0, sopra)):
6140  if oSheet.getCellByPosition(
6141  1, n).CellStyle == 'Ultimus_centro_bordi_lati':
6142  break
6143  if oSheet.getCellByPosition(1, n).CellStyle == 'Data_bianca':
6144  data = oSheet.getCellByPosition(1, n).Value
6145  break
6146  if data == 0.0:
6147  oSheet.getCellByPosition(1, sopra +
6148  2).Value = date.today().toordinal() - 693594
6149  else:
6150  oSheet.getCellByPosition(1, sopra + 2).Value = data
6151 
6160  iSheet = oSheet.RangeAddress.Sheet
6161  oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
6162  oCellRangeAddr.Sheet = iSheet
6163  oCellRangeAddr.StartColumn = 0
6164  oCellRangeAddr.EndColumn = 0
6165  oCellRangeAddr.StartRow = lrow + 2
6166  oCellRangeAddr.EndRow = lrow + 2
6167  oSheet.group(oCellRangeAddr, 1)
6168 
6169 
6170  if oDoc.NamedRanges.hasByName('_Lib_' + str(nSal)):
6171  if lrow - 1 == oSheet.getCellRangeByName(
6172  '_Lib_' + str(nSal)).getRangeAddress().EndRow:
6173  nSal += 1
6174 
6175  oSheet.getCellByPosition(23, sopra + 1).Value = nSal
6176  oSheet.getCellByPosition(23, sopra + 1).CellStyle = 'Sal'
6177 
6178  oSheet.getCellByPosition(35, sopra + 4).Formula = '=B' + str(sopra + 2)
6179  oSheet.getCellByPosition(
6180  36, sopra +
6181  4).Formula = '=IF(ISERROR(P' + str(sopra + 5) + ');"";IF(P' + str(
6182  sopra + 5) + '<>"";P' + str(sopra + 5) + ';""))'
6183  oSheet.getCellByPosition(36, sopra + 4).CellStyle = "comp -controolo"
6184  if cod:
6185  oSheet.getCellByPosition(1, sopra + 1).String = cod
6186  numera_voci(0)
6187  if cfg.read('Generale', 'pesca_auto') == '1':
6188  if arg == 0:
6189  return
6190  pesca_cod()
6191 
6192 
6193 
6194 
6195 
6197  '''
6198  Riscrive le intestazioni di colonna e le formule dei totali in Elenco Prezzi.
6199  '''
6201  chiudi_dialoghi()
6202 
6203  oDoc = LeenoUtils.getDocument()
6204  oSheet = oDoc.Sheets.getByName('Elenco Prezzi')
6205 
6206  # oDialogo_attesa = dlg_attesa()
6207  # attesa().start() #mostra il dialogo
6208 
6209  struttura_off()
6210  oCellRangeAddr = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
6211  # SR = oCellRangeAddr.StartRow
6212  ER = oCellRangeAddr.EndRow
6213  # SC = oCellRangeAddr.StartColumn
6214  EC = oCellRangeAddr.EndColumn
6215  oSheet.getCellRangeByPosition(11, 3, EC, ER -
6216  1).clearContents(STRING + VALUE + FORMULA)
6217 
6218  oDoc.CurrentController.freezeAtPosition(0, 3)
6219  oSheet.getCellRangeByPosition(0, 0, 100, 0).CellStyle = "Default"
6220  # riscrivo le intestazioni di colonna
6222  oSheet.getCellRangeByName('L1').String = 'COMPUTO'
6223  oSheet.getCellRangeByName('P1').String = 'VARIANTE'
6224  oSheet.getCellRangeByName('T1').String = 'CONTABILITA'
6225  oSheet.getCellRangeByName('B2').String = 'QUESTA RIGA NON VIENE STAMPATA'
6226  oSheet.getCellRangeByName(
6227  "'Elenco Prezzi'.A2:AA2").CellStyle = "comp In testa"
6228  oSheet.getCellRangeByName("'Elenco Prezzi'.AA2").CellStyle = 'EP-mezzo %'
6229 
6230  oSheet.getCellRangeByName("'Elenco Prezzi'.A3:AA3").CellStyle = "EP-a -Top"
6231  oSheet.getCellRangeByName('A3').String = 'Codice\nArticolo'
6232  oSheet.getCellRangeByName(
6233  'B3').String = 'DESCRIZIONE DEI LAVORI\nE DELLE SOMMINISTRAZIONI'
6234  oSheet.getCellRangeByName('C3').String = 'Unità\ndi misura'
6235  oSheet.getCellRangeByName('D3').String = 'Sicurezza\ninclusa'
6236  oSheet.getCellRangeByName('E3').String = 'Prezzo\nunitario'
6237  oSheet.getCellRangeByName('F3').String = 'Incidenza\nMdO'
6238  oSheet.getCellRangeByName('G3').String = 'Importo\nMdO'
6239  oSheet.getCellRangeByName('H3').String = 'Codice di origine'
6240  oSheet.getCellRangeByName('L3').String = 'Inc. % \nComputo'
6241