2 Importazione computo/variante/contabilità/prezzario 
    7 from xml.etree.ElementTree 
import ElementTree, ParseError
 
    8 from com.sun.star.table 
import CellRangeAddress
 
   14 import LeenoDialogs 
as DLG
 
   18 import LeenoSheetUtils
 
   29     ''' legge i dati anagrafici generali ''' 
   33         DatiGenerali = dati.getchildren()[0][0]
 
   35         datiAnagrafici[
'comune'] = DatiGenerali[1].text 
or '' 
   36         datiAnagrafici[
'oggetto'] = DatiGenerali[3].text 
or '' 
   37         datiAnagrafici[
'committente'] = DatiGenerali[4].text 
or '' 
   38         datiAnagrafici[
'impresa'] = DatiGenerali[5].text 
or '' 
   40         datiAnagrafici['percprezzi'] = DatiGenerali[0].text or '' 
   41         datiAnagrafici['provincia'] = DatiGenerali[2].text or '' 
   42         datiAnagrafici['parteopera'] = DatiGenerali[6].text or '' 
   45         datiAnagrafici[
'comune'] = 
'' 
   46         datiAnagrafici[
'oggetto'] = 
'' 
   47         datiAnagrafici[
'committente'] = 
'' 
   48         datiAnagrafici[
'impresa'] = 
'' 
   54     ''' legge SuperCapitoli ''' 
   57     listaSuperCapitoli = []
 
   58     if CapCat.find(
'PweDGSuperCapitoli'):
 
   59         PweDGSuperCapitoli = CapCat.find(
'PweDGSuperCapitoli').getchildren()
 
   60         for elem 
in PweDGSuperCapitoli:
 
   61             id_sc = elem.get(
'ID')
 
   64                 codice = elem.find(
'Codice').text
 
   65             except AttributeError:
 
   67             dessintetica = elem.find(
'DesSintetica').text
 
   69                 percentuale = elem.find(
'Percentuale').text
 
   74             diz[
'codice'] = codice
 
   75             diz[
'dessintetica'] = dessintetica
 
   76             diz[
'percentuale'] = percentuale
 
   77             listaSuperCapitoli.append(diz)
 
   78     return listaSuperCapitoli
 
   82     ''' legge Capitoli ''' 
   86     if CapCat.find(
'PweDGCapitoli'):
 
   87         PweDGCapitoli = CapCat.find(
'PweDGCapitoli').getchildren()
 
   88         for elem 
in PweDGCapitoli:
 
   89             id_sc = elem.get(
'ID')
 
   92                 codice = elem.find(
'Codice').text
 
   93             except AttributeError:
 
   95             dessintetica = elem.find(
'DesSintetica').text
 
   97                 percentuale = elem.find(
'Percentuale').text
 
  102             diz[
'codice'] = codice
 
  103             diz[
'dessintetica'] = dessintetica
 
  104             diz[
'percentuale'] = percentuale
 
  105             listaCapitoli.append(diz)
 
  110     ''' legge SottoCapitoli ''' 
  113     listaSottoCapitoli = []
 
  114     if CapCat.find(
'PweDGSubCapitoli'):
 
  115         PweDGSubCapitoli = CapCat.find(
'PweDGSubCapitoli').getchildren()
 
  116         for elem 
in PweDGSubCapitoli:
 
  117             id_sc = elem.get(
'ID')
 
  119                 codice = elem.find(
'Codice').text
 
  120             except AttributeError:
 
  123                 codice = elem.find(
'Codice').text
 
  124             except AttributeError:
 
  126             dessintetica = elem.find(
'DesSintetica').text
 
  128                 percentuale = elem.find(
'Percentuale').text
 
  133             diz[
'codice'] = codice
 
  134             diz[
'dessintetica'] = dessintetica
 
  135             diz[
'percentuale'] = percentuale
 
  136             listaSottoCapitoli.append(diz)
 
  137     return listaSottoCapitoli
 
  141     ''' legge SuperCategorie ''' 
  144     listaSuperCategorie = []
 
  145     if CapCat.find(
'PweDGSuperCategorie'):
 
  146         PweDGSuperCategorie = CapCat.find(
 
  147             'PweDGSuperCategorie').getchildren()
 
  148         for elem 
in PweDGSuperCategorie:
 
  149             id_sc = elem.get(
'ID')
 
  150             dessintetica = elem.find(
'DesSintetica').text
 
  152                 percentuale = elem.find(
'Percentuale').text
 
  153             except AttributeError:
 
  155             supcat = (id_sc, dessintetica, percentuale)
 
  156             listaSuperCategorie.append(supcat)
 
  157     return listaSuperCategorie
 
  161     ''' legge Categorie ''' 
  165     if CapCat.find(
'PweDGCategorie'):
 
  166         PweDGCategorie = CapCat.find(
'PweDGCategorie').getchildren()
 
  167         for elem 
in PweDGCategorie:
 
  168             id_sc = elem.get(
'ID')
 
  169             dessintetica = elem.find(
'DesSintetica').text
 
  171                 percentuale = elem.find(
'Percentuale').text
 
  172             except AttributeError:
 
  174             cat = (id_sc, dessintetica, percentuale)
 
  175             listaCategorie.append(cat)
 
  176     return listaCategorie
 
  180     ''' legge SottoCategorie ''' 
  183     listaSottoCategorie = []
 
  184     if CapCat.find(
'PweDGSubCategorie'):
 
  185         PweDGSubCategorie = CapCat.find(
'PweDGSubCategorie').getchildren()
 
  186         for elem 
in PweDGSubCategorie:
 
  187             id_sc = elem.get(
'ID')
 
  188             dessintetica = elem.find(
'DesSintetica').text
 
  190                 percentuale = elem.find(
'Percentuale').text
 
  191             except AttributeError:
 
  193             subcat = (id_sc, dessintetica, percentuale)
 
  194             listaSottoCategorie.append(subcat)
 
  195     return listaSottoCategorie
 
  199     ''' legge capitoli e categorie ''' 
  205         'SuperCategorie': [],
 
  212         CapCat = dati.find(
'PweDGCapitoliCategorie')
 
  213     except AttributeError:
 
  233     ''' legge i dati generali di analisi ''' 
  236         PweDGAnalisi = dati.find(
'PweDGModuli').getchildren()[0]
 
  239             speseGenerali = float(PweDGAnalisi.find(
'SpeseGenerali').text) / 100
 
  244             utiliImpresa = float(PweDGAnalisi.find(
'UtiliImpresa').text) / 100
 
  249             oneriAccessoriSicurezza = float(PweDGAnalisi.find(
'OneriAccessoriSc').text) / 100
 
  251             oneriAccessoriSicurezza = 0
 
  253         speseutili = PweDGAnalisi.find('SpeseUtili').text 
  254         confquantita = PweDGAnalisi.find('ConfQuantita').text 
  260         oneriAccessoriSicurezza = 0
 
  263         'SpeseGenerali': speseGenerali,
 
  264         'UtiliImpresa': utiliImpresa,
 
  265         'OneriAccessoriSicurezza': oneriAccessoriSicurezza
 
  270     ''' legge le impostazioni di approssimazione numerica ''' 
  273         PweDGConfigNumeri = dati.find(
'PweDGConfigurazione')
 
  274     except AttributeError:
 
  275         PweDGConfigNumeri = 
None 
  277     if PweDGConfigNumeri 
is None:
 
  279     PweDGConfigNumeri = PweDGConfigNumeri.getchildren()[0]
 
  282     partiUguali = PweDGConfigNumeri.find(
'PartiUguali')
 
  284         res[
'PartiUguali'] = int(partiUguali.text.split(
'.')[-1].split(
'|')[0])
 
  288     larghezza = PweDGConfigNumeri.find(
'Larghezza')
 
  290         res[
'Larghezza'] = int(larghezza.text.split(
'.')[-1].split(
'|')[0])
 
  294     lunghezza = PweDGConfigNumeri.find(
'Lunghezza')
 
  296         res[
'Lunghezza'] = int(lunghezza.text.split(
'.')[-1].split(
'|')[0])
 
  300     hPeso = PweDGConfigNumeri.find(
'HPeso')
 
  302         res[
'HPeso'] = int(hPeso.text.split(
'.')[-1].split(
'|')[0])
 
  306     quantita = PweDGConfigNumeri.find(
'Quantita')
 
  308         res[
'Quantita'] = int(quantita.text.split(
'.')[-1].split(
'|')[0])
 
  312     prezzi = PweDGConfigNumeri.find(
'Prezzi')
 
  314         res[
'Prezzi'] = int(prezzi.text.split(
'.')[-1].split(
'|')[0])
 
  318     prezziTotale = PweDGConfigNumeri.find(
'PrezziTotale')
 
  320         res[
'PrezziTotale'] = int(prezziTotale.text.split(
'.')[-1].split(
'|')[0])
 
  324     Divisa = PweDGConfigNumeri.find('Divisa').text 
  325     ConversioniIN = PweDGConfigNumeri.find('ConversioniIN').text 
  326     FattoreConversione = PweDGConfigNumeri.find('FattoreConversione').text 
  327     Cambio = PweDGConfigNumeri.find('Cambio').text 
  328     ConvPrezzi = PweDGConfigNumeri.find('ConvPrezzi').text.split('.')[-1].split('|')[0] 
  329     ConvPrezziTotale = PweDGConfigNumeri.find('ConvPrezziTotale').text.split('.')[-1].split('|')[0] 
  330     IncidenzaPercentuale = PweDGConfigNumeri.find('IncidenzaPercentuale').text.split('.')[-1].split('|')[0] 
  331     Aliquote = PweDGConfigNumeri.find('Aliquote').text.split('.')[-1].split('|')[0] 
  337     ''' compilo Anagrafica generale ''' 
  339     oSheet = oDoc.getSheets().getByName(
'S2')
 
  340     oSheet.getCellByPosition(2, 2).String = datiAnagrafici[
'oggetto']
 
  341     oSheet.getCellByPosition(2, 3).String = datiAnagrafici[
'comune']
 
  342     oSheet.getCellByPosition(2, 5).String = datiAnagrafici[
'committente']
 
  343     oSheet.getCellByPosition(3, 16).String = datiAnagrafici[
'impresa']
 
  347     ''' compila i dati generali dell'analisi, ovvero le percentuali relative ''' 
  349     oSheet = oDoc.getSheets().getByName(
'S1')
 
  351     oSheet.getCellByPosition(7, 318).Value = datiGeneraliAnalisi[
'OneriAccessoriSicurezza']
 
  352     oSheet.getCellByPosition(7, 319).Value = datiGeneraliAnalisi[
'SpeseGenerali']
 
  353     oSheet.getCellByPosition(7, 320).Value = datiGeneraliAnalisi[
'UtiliImpresa']
 
  357     ''' compila le approssimazioni modificando la precisione nelle relative celle ''' 
  359     if 'PartiUguali' in approssimazioni:
 
  361     if 'Lunghezza' in approssimazioni:
 
  363     if 'Larghezza' in approssimazioni:
 
  365     if 'HPeso' in approssimazioni:
 
  367     if 'Quantita' in approssimazioni:
 
  368         for el 
in (
'Comp-Variante num sotto', 
'An-lavoraz-input', 
'Blu'):
 
  370     if 'Prezzi' in approssimazioni:
 
  371         for el 
in (
'comp sotto Unitario', 
'An-lavoraz-generica'):
 
  373     if 'PrezziTotale' in approssimazioni:
 
  374         for el 
in (
'comp sotto Euro Originale', 
'Livello-0-scritta mini val',
 
  375                    'Livello-1-scritta mini val', 
'livello2 scritta mini',
 
  376                    'Comp TOTALI', 
'Ultimus_totali_1', 
'Ultimus_bordo',
 
  377                    'ULTIMUS_3', 
'Ultimus_Bordo_sotto',
 
  378                    'Comp-Variante num sotto', 
'An-valuta-dx', 
'An-1v-dx',
 
  379                    'An-lavoraz-generica', 
'An-lavoraz-Utili-num sin'):
 
  384     ''' legge l'elenco prezzi e le eventuali voci di analisi prezzi ''' 
  386     dizionarioArticoli = {}
 
  389     listaTariffeAnalisi = []
 
  391     PweElencoPrezzi = misurazioni.getchildren()[0]
 
  394     epitems = PweElencoPrezzi.findall(
'EPItem')
 
  397         id_ep = elem.get(
'ID')
 
  398         dizionarioArticolo = {}
 
  400             tipoep = elem.find(
'TipoEP').text
 
  403         tariffa = elem.find(
'Tariffa').text 
or '' 
  404         articolo = elem.find(
'Articolo').text
 
  405         desridotta = elem.find(
'DesRidotta').text
 
  406         destestesa = elem.find(
'DesEstesa').text  
 
  408             desridotta = elem.find(
'DesBreve').text
 
  409         except AttributeError:
 
  412             desbreve = elem.find(
'DesBreve').text
 
  413         except AttributeError:
 
  416         unmisura = elem.find(
'UnMisura').text 
or '' 
  417         if elem.find(
'Prezzo1').text == 
'0' or elem.find(
'Prezzo1').text 
is None:
 
  420             prezzo1 = float(elem.find(
'Prezzo1').text)
 
  422             prezzo2 = elem.find(
'Prezzo2').text
 
  426             prezzo3 = elem.find(
'Prezzo3').text
 
  430             prezzo4 = elem.find(
'Prezzo4').text
 
  434             prezzo5 = elem.find(
'Prezzo5').text
 
  438             idspcap = elem.find(
'IDSpCap').text
 
  439         except AttributeError:
 
  442             idcap = elem.find(
'IDCap').text
 
  443         except AttributeError:
 
  447            idsbcap = elem.find('IDSbCap').text 
  448         except AttributeError: 
  452             flags = elem.find(
'Flags').text
 
  453         except AttributeError:
 
  456             data = elem.find(
'Data').text
 
  457         except AttributeError:
 
  464             if float(elem.find(
'IncSIC').text) != 0:
 
  465                 IncSIC = float(elem.find(
'IncSIC').text) / 100
 
  469             if float(elem.find(
'IncMDO').text) != 0:
 
  470                 IncMDO = float(elem.find(
'IncMDO').text) / 100
 
  474             if float(elem.find(
'IncMAT').text) != 0:
 
  475                 IncMAT = float(elem.find(
'IncMAT').text) / 100
 
  479             if float(elem.find(
'IncATTR').text) != 0:
 
  480                 IncATTR = float(elem.find(
'IncATTR').text) / 100
 
  484             adrinternet = elem.find(
'AdrInternet').text
 
  485         except AttributeError:
 
  488             pweepanalisi = elem.find(
'PweEPAnalisi').text
 
  492         dizionarioArticolo[
'tipoep'] = tipoep
 
  493         dizionarioArticolo[
'tariffa'] = tariffa
 
  494         dizionarioArticolo[
'articolo'] = articolo
 
  495         dizionarioArticolo[
'desridotta'] = desridotta
 
  496         dizionarioArticolo[
'destestesa'] = destestesa
 
  497         dizionarioArticolo[
'desridotta'] = desridotta
 
  498         dizionarioArticolo[
'desbreve'] = desbreve
 
  499         dizionarioArticolo[
'unmisura'] = unmisura
 
  500         dizionarioArticolo[
'prezzo1'] = prezzo1
 
  501         dizionarioArticolo[
'prezzo2'] = prezzo2
 
  502         dizionarioArticolo[
'prezzo3'] = prezzo3
 
  503         dizionarioArticolo[
'prezzo4'] = prezzo4
 
  504         dizionarioArticolo[
'prezzo5'] = prezzo5
 
  505         dizionarioArticolo[
'idspcap'] = idspcap
 
  506         dizionarioArticolo[
'idcap'] = idcap
 
  507         dizionarioArticolo[
'flags'] = flags
 
  508         dizionarioArticolo[
'data'] = data
 
  509         dizionarioArticolo[
'adrinternet'] = adrinternet
 
  511         dizionarioArticolo[
'IncSIC'] = IncSIC
 
  512         dizionarioArticolo[
'IncMDO'] = IncMDO
 
  513         dizionarioArticolo[
'IncMAT'] = IncMDO
 
  514         dizionarioArticolo[
'IncATTR'] = IncMDO
 
  516         dizionarioArticolo['pweepanalisi'] = pweepanalisi 
  522         dizionarioArticoli[id_ep] = dizionarioArticolo
 
  526         pweepanalisi = elem.find(
'PweEPAnalisi')
 
  528             PweEPAR = pweepanalisi.find(
'PweEPAR')
 
  531         if PweEPAR 
is not None:
 
  532             EPARItem = PweEPAR.findall(
'EPARItem')
 
  537                 an_tipo = el.find('Tipo').text 
  539                 id_ep = el.find(
'IDEP').text
 
  540                 an_des = el.find(
'Descrizione').text
 
  541                 an_um = el.find(
'Misura').text
 
  545                     an_qt = el.find(
'Qt').text.replace(
' ', 
'')
 
  549                     an_pr = el.find(
'Prezzo').text.replace(
' ', 
'')
 
  553                 an_fld = el.find('FieldCTL').text 
  555                 an_rigo = (id_ep, an_des, an_um, an_qt, an_pr)
 
  556                 analisi.append(an_rigo)
 
  557             listaAnalisi.append([tariffa, destestesa, unmisura, analisi, prezzo1])
 
  558             listaTariffeAnalisi.append(tariffa)
 
  561             articolo_modificato = (
 
  570             listaArticoli.append(articolo_modificato)
 
  572         'DizionarioArticoli': dizionarioArticoli,
 
  573         'ListaArticoli': listaArticoli,
 
  574         'ListaAnalisi': listaAnalisi,
 
  575         'ListaTariffeAnalisi': listaTariffeAnalisi
 
  580     ''' leggo voci di misurazione e righe ''' 
  584         PweVociComputo = misurazioni.getchildren()[1]
 
  585         vcitems = PweVociComputo.findall(
'VCItem')
 
  589             id_vc = elem.get(
'ID')
 
  590             id_ep = elem.find(
'IDEP').text
 
  591             quantita = elem.find(
'Quantita').text
 
  593                 datamis = elem.find(
'DataMis').text
 
  594             except AttributeError:
 
  597                 flags = elem.find(
'Flags').text
 
  598             except AttributeError:
 
  601                 idspcat = elem.find(
'IDSpCat').text
 
  602             except AttributeError:
 
  605                 idcat = elem.find(
'IDCat').text
 
  606             except AttributeError:
 
  609                 idsbcat = elem.find(
'IDSbCat').text
 
  610             except AttributeError:
 
  614                CodiceWBS = elem.find('CodiceWBS').text 
  615             except AttributeError: 
  618             righi_mis = elem.getchildren()[-1].findall(
'RGItem')
 
  625                 rgitem = el.get('ID') 
  627                 idvv = el.find(
'IDVV').text
 
  628                 if el.find(
'Descrizione').text 
is not None:
 
  629                     descrizione = el.find(
'Descrizione').text
 
  632                 partiuguali = el.find(
'PartiUguali').text
 
  633                 if partiuguali != 
None:
 
  634                     if '  ' in partiuguali:
 
  636                 lunghezza = el.find(
'Lunghezza').text
 
  637                 if lunghezza != 
None:
 
  640                 larghezza = el.find(
'Larghezza').text
 
  641                 if larghezza != 
None:
 
  644                 hpeso = el.find(
'HPeso').text
 
  648                 quantita = el.find(
'Quantita').text
 
  649                 flags = el.find(
'Flags').text
 
  663                 mia.append(riga_misura[0])
 
  664                 for el 
in riga_misura[1:]:
 
  672                                 el = 
'=' + el.replace(
'.', 
',')
 
  674                 lista_righe.append(riga_misura)
 
  675             diz_misura[
'id_vc'] = id_vc
 
  676             diz_misura[
'id_ep'] = id_ep
 
  677             diz_misura[
'quantita'] = quantita
 
  678             diz_misura[
'datamis'] = datamis
 
  679             diz_misura[
'flags'] = flags
 
  680             diz_misura[
'idspcat'] = idspcat
 
  681             diz_misura[
'idcat'] = idcat
 
  682             diz_misura[
'idsbcat'] = idsbcat
 
  683             diz_misura[
'lista_rig'] = lista_righe
 
  685             new_id = PL.strall(idspcat) + 
'.' + PL.strall(idcat) + 
'.' + PL.strall(idsbcat)
 
  686             new_id_l = (new_id, diz_misura)
 
  687             prova_l.append(new_id_l)
 
  688             listaMisure.append(diz_misura)
 
  691         if len(listaMisure) != 0 
and ordina:
 
  692             riordine = sorted(prova_l, key=
lambda el: el[0])
 
  695                 listaMisure.append(el[1])
 
  699         Text=
"Nel file scelto non risultano esserci voci di misurazione,\n" 
  700             "perciò saranno importate le sole voci di Elenco Prezzi.\n\n" 
  701             "Si tenga conto che:\n" 
  702             "- sarà importato solo il 'Prezzo 1' dell'elenco;\n" 
  703             "- a seconda della versione, il formato XPWE potrebbe\n" 
  704             "  non conservare alcuni dati come le incidenze di\n" 
  705             "  sicurezza e di manodopera!" 
  712     oSheet.getCellRangeByPosition(0, startRow, 0, endRow).CellStyle = 
"EP-aS" 
  713     oSheet.getCellRangeByPosition(1, startRow, 1, endRow).CellStyle = 
"EP-a" 
  714     oSheet.getCellRangeByPosition(2, startRow, 4, endRow).CellStyle = 
"EP-mezzo" 
  715     oSheet.getCellRangeByPosition(5, startRow, 5, endRow).CellStyle = 
"EP-mezzo %" 
  716     oSheet.getCellRangeByPosition(6, startRow, 7, endRow).CellStyle = 
"EP-mezzo" 
  717     oSheet.getCellRangeByPosition(8, startRow, 9, endRow).CellStyle = 
"EP-sfondo" 
  718     oSheet.getCellRangeByPosition(11, startRow, 11, endRow).CellStyle = 
'EP-mezzo %' 
  719     oSheet.getCellRangeByPosition(15, startRow, 15, endRow).CellStyle = 
'EP-mezzo %' 
  720     oSheet.getCellRangeByPosition(19, startRow, 19, endRow).CellStyle = 
'EP-mezzo %' 
  721     oSheet.getCellRangeByPosition(26, startRow, 26, endRow).CellStyle = 
'EP-mezzo %' 
  722     oSheet.getCellRangeByPosition(12, startRow, 12, endRow).CellStyle = 
'EP statistiche_q' 
  723     oSheet.getCellRangeByPosition(16, startRow, 16, endRow).CellStyle = 
'EP statistiche_q' 
  724     oSheet.getCellRangeByPosition(20, startRow, 20, endRow).CellStyle = 
'EP statistiche_q' 
  725     oSheet.getCellRangeByPosition(23, startRow, 23, endRow).CellStyle = 
'EP statistiche_q' 
  726     oSheet.getCellRangeByPosition(13, startRow, 13, endRow).CellStyle = 
'EP statistiche' 
  727     oSheet.getCellRangeByPosition(17, startRow, 17, endRow).CellStyle = 
'EP statistiche' 
  728     oSheet.getCellRangeByPosition(21, startRow, 21, endRow).CellStyle = 
'EP statistiche' 
  729     oSheet.getCellRangeByPosition(24, startRow, 25, endRow).CellStyle = 
'EP statistiche' 
  730     if color 
is not None:
 
  731         oSheet.getCellRangeByPosition(0, startRow, 0, endRow).CellBackColor = color
 
  735     for el 
in capitoliCategorie[catName]:
 
  736         tariffa = el.get(
'codice')
 
  737         if tariffa 
is not None:
 
  738             destestesa = el.get(
'dessintetica')
 
  739             titolo = (tariffa, destestesa, 
'', 
'', 
'', 
'', 
'')
 
  740             resList.append(titolo)
 
  741     return tuple(resList)
 
  745     progStart = progress.getValue()
 
  747     colonne = len(dati[0])
 
  750     oSheet.getRows().insertByIndex(3, righe)
 
  755         sliced = dati[riga:riga + step]
 
  757         oRange = oSheet.getCellRangeByPosition(
 
  762         oRange.setDataArray(sliced)
 
  768         progress.setValue(riga + progStart)
 
  772     ''' compila l'elenco prezzi ''' 
  778     arrayArticoli = tuple(elencoPrezzi[
'ListaArticoli'])
 
  779     righeArticoli = len(arrayArticoli)
 
  782     righeSuperCapitoli = len(arraySuperCapitoli)
 
  785     righeCapitoli = len(arrayCapitoli)
 
  788     righeSottoCapitoli = len(arraySottoCapitoli)
 
  791     righeTotali = righeArticoli + righeSuperCapitoli + righeCapitoli + righeSottoCapitoli
 
  794     progress.setLimits(0, righeTotali)
 
  798     oSheet = oDoc.getSheets().getByName(
'Elenco Prezzi')
 
  802     aggiungo i capitoli alla lista delle voci 
  803      giallo(16777072,16777120,16777168) 
  804      verde(9502608,13696976,15794160) 
  805      viola(12632319,13684991,15790335) 
  809     if righeSuperCapitoli:
 
  817     if righeSottoCapitoli:
 
  820     PL.riordina_ElencoPrezzi(oDoc)
 
  824     ''' Compilo Analisi di prezzo ''' 
  825     numAnalisi = len(elencoPrezzi[
'ListaAnalisi'])
 
  829         progress.setLimits(0, numAnalisi)
 
  831         progress.setValue(val)
 
  837         for el 
in elencoPrezzi[
'ListaAnalisi']:
 
  838             prezzo_finale = el[-1]
 
  843             lrow = sStRange.RangeAddress.StartRow + 2
 
  844             oSheet.getCellByPosition(0, lrow).String = el[0]
 
  845             oSheet.getCellByPosition(1, lrow).String = el[1]
 
  846             oSheet.getCellByPosition(2, lrow).String = el[2]
 
  851                    'MANODOPERA', 
'MATERIALI', 
'NOLI', 
'TRASPORTI',
 
  852                    'ALTRE FORNITURE E PRESTAZIONI', 
'overflow'):
 
  853                     if el[3][y][1] != 
'overflow':
 
  857                     if elencoPrezzi[
'DizionarioArticoli'].get(el[3][y][0]) 
is not None:
 
  858                         oSheet.getCellByPosition(0, n).String = (
 
  859                            elencoPrezzi[
'DizionarioArticoli'].get(el[3][y][0]).get(
'tariffa'))
 
  862                         oSheet.getCellByPosition(0, n).String = 
'' 
  864                             oSheet.getCellByPosition(1, n).String = x[1]
 
  866                             oSheet.getCellByPosition(1, n).String = 
'' 
  867                         oSheet.getCellByPosition(2, n).String = x[2]
 
  869                             float(x[3].replace(
',', 
'.'))
 
  870                             oSheet.getCellByPosition(3, n).Value = float(x[3].replace(
',', 
'.'))
 
  872                             oSheet.getCellByPosition(3, n).Value = 0
 
  874                             float(x[4].replace(
',', 
'.'))
 
  875                             oSheet.getCellByPosition(4, n).Value = float(x[4].replace(
',', 
'.'))
 
  877                             oSheet.getCellByPosition(4, n).Value = 0
 
  878                     if el[3][y][1] 
not in (
 
  879                        'MANODOPERA', 
'MATERIALI', 
'NOLI', 
'TRASPORTI',
 
  880                        'ALTRE FORNITURE E PRESTAZIONI', 
'overflow'):
 
  881                         if el[3][y][3] == 
'':
 
  882                             oSheet.getCellByPosition(3, n).Value = 0
 
  886                                 oSheet.getCellByPosition(3, n).Value = el[3][y][3]
 
  888                                 oSheet.getCellByPosition(3, n).Formula = 
'=' + el[3][y][3]
 
  892             startRow = sStRange.RangeAddress.StartRow
 
  893             endRow = sStRange.RangeAddress.EndRow
 
  894             for m 
in reversed(range(startRow, endRow)):
 
  895                 if(oSheet.getCellByPosition(0, m).String == 
'Cod. Art.?' and 
  896                    oSheet.getCellByPosition(0, m - 1).CellStyle == 
'An-lavoraz-Cod-sx'):
 
  897                     oSheet.getRows().removeByIndex(m, 1)
 
  898                 if oSheet.getCellByPosition(0, m).String == 
'Cod. Art.?':
 
  899                     oSheet.getCellByPosition(0, m).String = 
'' 
  900             if oSheet.getCellByPosition(6, startRow + 2).Value != prezzo_finale:
 
  901                 oSheet.getCellByPosition(6, startRow + 2).Value = prezzo_finale
 
  906             progress.setValue(val)
 
  911         PL.tante_analisi_in_ep()
 
  914 def compilaComputo(oDoc, elaborato, capitoliCategorie, elencoPrezzi, listaMisure, progress):
 
  915     ''' compila il computo ''' 
  918     if elaborato == 
'VARIANTE':
 
  919         if oDoc.getSheets().hasByName(
'VARIANTE'):
 
  923             oSheet.getRows().removeByIndex(2, 4)
 
  924     elif elaborato == 
'CONTABILITA':
 
  928         oSheet = oDoc.getSheets().getByName(elaborato)
 
  931     if oSheet.getCellByPosition(1, 4).String == 
'Cod. Art.?':
 
  932         if elaborato == 
'CONTABILITA':
 
  933             oSheet.getRows().removeByIndex(3, 5)
 
  935             oSheet.getRows().removeByIndex(3, 4)
 
  937     oCellRangeAddr = CellRangeAddress()
 
  939     oCellRangeAddr.Sheet = oSheet.RangeAddress.Sheet
 
  955     progress.setLimits(0, len(listaMisure))
 
  957     progress.setValue(val)
 
  959     for el 
in listaMisure:
 
  961         datamis = el.get(
'datamis')
 
  963         idspcat = el.get(
'idspcat')
 
  965         idcat = el.get(
'idcat')
 
  967         idsbcat = el.get(
'idsbcat')
 
  976         if elaborato != 
'CONTABILITA':
 
  979                 if idspcat != testspcat:
 
  985             except UnboundLocalError:
 
  996             except UnboundLocalError:
 
 1001                 if idsbcat != testsbcat:
 
 1006             except UnboundLocalError:
 
 1009         if elaborato == 
'CONTABILITA':
 
 1016         ID = el.get(
'id_ep')
 
 1021             oSheet.getCellByPosition(1, lrow + 1).String = elencoPrezzi[
'DizionarioArticoli'].get(ID).get(
'tariffa')
 
 1026         idVoceComputo = el.get(
'id_vc')
 
 1030         mappaVociRighe[idVoceComputo] = lrow + 1
 
 1034         oSheet.getCellByPosition(0, lrow + 1).String = str(numeroVoce)
 
 1040         lista_righe = el.get(
'lista_rig')
 
 1041         nrighe = len(lista_righe)
 
 1045             endRow = startRow + nrighe
 
 1050                 oSheet.getRows().insertByIndex(startRow + 1, nrighe - 1)
 
 1053             oRangeAddress = oSheet.getCellRangeByPosition(0, startRow, 250, startRow).getRangeAddress()
 
 1056             for n 
in range(startRow + 1, endRow):
 
 1057                 oCellAddress = oSheet.getCellByPosition(0, n).getCellAddress()
 
 1058                 oSheet.copyRange(oCellAddress, oRangeAddress)
 
 1059                 if elaborato == 
'CONTABILITA':
 
 1060                     oSheet.getCellByPosition(1, n).String = 
'' 
 1061                     oSheet.getCellByPosition(1, n).CellStyle = 
'Comp-Bianche in mezzo_R' 
 1064             if elaborato == 
'CONTABILITA':
 
 1065                 oSheet.getCellByPosition(1, startRow).Formula = (
 
 1066                     '=DATE(' + datamis.split(
'/')[2] +
 
 1067                     ';' + datamis.split(
'/')[1] + 
';' +
 
 1068                     datamis.split(
'/')[0] + 
')' 
 1070                 oSheet.getCellByPosition(1, startRow).Value = oSheet.getCellByPosition(1, startRow).Value
 
 1071             for mis 
in lista_righe:
 
 1074                 if mis[0] 
is not None:
 
 1075                     descrizione = mis[0].strip()
 
 1076                     oSheet.getCellByPosition(2, startRow).String = descrizione
 
 1081                 if mis[3] 
is not None:
 
 1083                         oSheet.getCellByPosition(5, startRow).Value = float(mis[3].replace(
',', 
'.'))
 
 1086                         oSheet.getCellByPosition(5, startRow).Formula = 
'=' + str(mis[3]).split(
'=')[-1]
 
 1089                 if mis[4] 
is not None:
 
 1091                         oSheet.getCellByPosition(6, startRow).Value = float(mis[4].replace(
',', 
'.'))
 
 1094                         oSheet.getCellByPosition(6, startRow).Formula = 
'=' + str(mis[4]).split(
'=')[-1]
 
 1097                 if mis[5] 
is not None:
 
 1099                         oSheet.getCellByPosition(7, startRow).Value = float(mis[5].replace(
',', 
'.'))
 
 1102                         oSheet.getCellByPosition(7, startRow).Formula = 
'=' + str(mis[5]).split(
'=')[-1]
 
 1105                 if mis[6] 
is not None:
 
 1107                         oSheet.getCellByPosition(8, startRow).Value = float(mis[6].replace(
',', 
'.'))
 
 1110                         oSheet.getCellByPosition(8, startRow).Formula = 
'=' + str(mis[6]).split(
'=')[-1]
 
 1113                     PL.parziale_core(oSheet, startRow)
 
 1114                     if elaborato != 
'CONTABILITA':
 
 1115                         oSheet.getRows().removeByIndex(startRow + 1, 1)
 
 1119                     vedi = mappaVociRighe.get(mis[9])
 
 1121                         test = PL.vedi_voce_xpwe(oSheet, startRow, vedi)
 
 1124                                             Text=
"Il file di origine è particolarmente disordinato.\n" 
 1125                                                  "Riordinando il computo trovo riferimenti a voci " 
 1126                                                  "non ancora inserite.\n\n" 
 1127                                                  "Al termine dell'importazione controlla la voce con tariffa " +
 
 1128                                                  elencoPrezzi[
'DizionarioArticoli'].get(ID).get(
'tariffa') +
 
 1129                                                  "\nella riga n." + str(lrow + 2) +
 
 1130                                                  " del foglio, evidenziata qui a sinistra.")
 
 1131                         oSheet.getCellByPosition(44, startRow).String = (
 
 1132                             elencoPrezzi[
'DizionarioArticoli'].get(ID).get(
'tariffa'))
 
 1136                         for x 
in range(5, 9):
 
 1138                                 if oSheet.getCellByPosition(x, startRow).Value != 0:
 
 1139                                     oSheet.getCellByPosition(x, startRow).Value = abs(oSheet.getCellByPosition(x, startRow).Value)
 
 1144                         if elaborato == 
'CONTABILITA':
 
 1153                 startRow = startRow + 1
 
 1157         progress.setValue(val)
 
 1162         PL.Rinumera_TUTTI_Capitoli2(oSheet)
 
 1170     Importazione dati dal formato XPWE 
 1175     if isLeenoDoc == 
False:
 
 1182         for el 
in (
"COMPUTO", 
"VARIANTE", 
"CONTABILITA"):
 
 1184                 vals.append(oDoc.getSheets().getByName(el).getCellRangeByName(
'A2').Value)
 
 1188         vals = [
None, 
None, 
None]
 
 1192     elabdest = DLG.ScegliElabDest(
 
 1193         Title=
"Importa dal formato XPWE",
 
 1194         AskTarget=isLeenoDoc,
 
 1198         ValVariante=vals[1],
 
 1199         ValContabilita=vals[2]
 
 1202     if elabdest 
is None:
 
 1204     elaborato = elabdest[
'elaborato']
 
 1205     destinazione = elabdest[
'destinazione']
 
 1206     ordina = elabdest[
'ordina']
 
 1209     if elaborato 
in (
'Elenco', 
'CONTABILITA'):
 
 1213     if filename 
in (
'Cancel', 
'', 
None):
 
 1217     tree = ElementTree()
 
 1219         tree.parse(filename)
 
 1222                             Text=
"È stato riscontrato un errore nel contenuto del file\n" 
 1223                                  "Accertati il file sia in formato XPWE.")
 
 1225     except PermissionError:
 
 1227                             Text=
"Impossibile leggere il file\n" 
 1228                                  "Accertati che il nome del file sia corretto.")
 
 1232     root = tree.getroot()
 
 1233     logging.debug(list(root))
 
 1236     progress = 
Dialogs.Progress(Title=
"Importazione file XPWE in corso", Text=
"Lettura dati")
 
 1237     progress.setLimits(0, 6)
 
 1238     progress.setValue(0)
 
 1245     dati = root.find(
'PweDatiGenerali')
 
 1247         dati = root.getchildren()[0].find(
'PweDatiGenerali')
 
 1251     progress.setValue(1)
 
 1255     progress.setValue(2)
 
 1259     progress.setValue(3)
 
 1263     progress.setValue(4)
 
 1265     misurazioni = root.find(
'PweMisurazioni')
 
 1266     if misurazioni == 
None:
 
 1267         misurazioni = root.getchildren()[0].find(
'PweMisurazioni')
 
 1273     progress.setValue(5)
 
 1276     if elaborato != 
'Elenco':
 
 1280     progress.setValue(6)
 
 1286     if destinazione == 
'NUOVO':
 
 1287         oDoc = PL.creaComputo(0)
 
 1292     progress = 
Dialogs.Progress(Title=
"Importazione file XPWE in corso", Text=
"")
 
 1299     progress.setText(
"Compilazione dati generali di analisi")
 
 1303     progress.setText(
"Compilazione approssimazioni")
 
 1307     progress.setText(
"Compilazione anagrafica generale")
 
 1311     progress.setText(
"Compilazione elenco prezzi")
 
 1312     if elaborato == 
'CONTABILITA':
 
 1313         capitoliCategorie = {
'SuperCapitoli': [], 
'Capitoli': [], 
'SottoCapitoli': [], 
'SuperCategorie': [], 
'Categorie': [], 
'SottoCategorie': []}
 
 1317     progress.setText(
"Compilazione analisi prezzi")
 
 1328     if len(listaMisure) == 0:
 
 1332                      Text=
"Importate n." +
 
 1333                            str(len(elencoPrezzi[
'ListaArticoli'])) +
 
 1334                            " voci dall'elenco prezzi\ndel file: " + filename)
 
 1335         oSheet = oDoc.getSheets().getByName(
'Elenco Prezzi')
 
 1336         oDoc.CurrentController.setActiveSheet(oSheet)
 
 1343     progress.setText(f
'Compilazione {elaborato}')
 
 1344     compilaComputo(oDoc, elaborato, capitoliCategorie, elencoPrezzi, listaMisure, progress)
 
 1349     PL.GotoSheet(elaborato)
 
 1350     progress.setText(
"Adattamento altezze righe")
 
 1352     progress.setText(
"Fine")
 
 1355     oSheet = oDoc.getSheets().getByName(elaborato)
 
 1358     Dialogs.Ok(Text=
'Importazione di\n\n' + elaborato + 
'\n\neseguita con successo!')