// CALCULS RAYNAUX v3.04 DE /// InDesign CS1-CC JavaScript //// Danke Rainer Klute und Astrid für für die deutsche Version. //// Danke Anne-Maris Paris für die englische Version. /* AD-BCV 03-2016 */ TestTable(); function TestTable() { if (app.selection.length == 1){ var LaSelection = app.selection[0]; var LeParent = app.selection[0].parent; var TypeSelection = LaSelection.constructor.name; var TypeParent = LeParent.constructor.name; var Cellules = false; var LaLigne = ""; var LaColonne = ""; if (((TypeSelection == "InsertionPoint" || TypeSelection == "Character" || TypeSelection == "Paragraph" || TypeSelection == "Word" || TypeSelection == "Text") && TypeParent == "Cell") || TypeSelection == "Cell" || TypeSelection == "Table"){ var Cellules = false; if ((TypeSelection == "Cell" || TypeSelection == "Table") && LaSelection.cells.length > 1){ Cellules = true; } if (TypeSelection == "Cell"){ var LignesSelection = LaSelection.rows.length; var ColonnesSelection = LaSelection.columns.length; if (ColonnesSelection == 1){ LaColonne = LaSelection.name.split(":")[0]; } if (LignesSelection == 1){ LaLigne = LaSelection.name.split(":")[1]; } } if (TypeSelection == "InsertionPoint" || TypeSelection == "Character" || TypeSelection == "Paragraph" || TypeSelection == "Word" || TypeSelection == "Text"){ LaColonne = LeParent.name.split(":")[0]; LaLigne = LeParent.name.split(":")[1]; } NouvelleFenetre(Cellules,LaColonne,LaLigne); } else{ alert ("Platzieren Sie den Cursor in einer Tabelle oder wählen Sie Tabellenzellen aus"); } } else{ alert ("Platzieren Sie den Cursor in einer Tabelle oder wählen Sie Tabellenzellen aus"); } } function NouvelleFenetre(Cellules,LaColonne,LaLigne){ var Fenetre = app.dialogs.add({name:"CALCULS RAYNAUX v3.04 DE"}); if (Cellules){ var ListeDeroulantSens = ["é"]; // pourquoi ? éh éh ! var ListeDeroulantSens = ["Ausgewählte Zellen","Alle Zeilen","Alle Spalten"]; var NombreSens = 0; } else{ var ListeDeroulantSens = ["Alle Zeilen","Alle Spalten"]; var NombreSens = 1; } var ListeDeroulantOperation = ["Addieren","Subtrahieren","Multiplizieren", "Dividieren"]; var ListeDeroulantDecimales = ["0","1","2"]; var ListeDeroulantSeparateurs = ["FR : 1 234,56","EN : 1,234.56","DE : 1.234,56"]; var ListeSeparateurs = [[" ",","],[",","."],[".",","]]; var ListeDeroulantOption = ["Zum Ergebnis addieren:","Vom Ergebnis subtrahieren:","Ergebnis multiplizieren mit:","Ergebnis dividieren durch:","%-Wert vom Ergebnis:","%-Wert zum Ergebnis addieren:","%-Wert vom Ergebnis subtrahieren:"]; var ListeDeroulantDevise = ["€","$","£","¥"] with(Fenetre){ with(dialogColumns.add()){ with(borderPanels.add()){ staticTexts.add({staticLabel:"Operation:"}); with(dialogColumns.add()){ var MenuDeroulantOperation = dropdowns.add({stringList:ListeDeroulantOperation, selectedIndex:0}); } } staticTexts.add({staticLabel:" "}); with(borderPanels.add()){ staticTexts.add({staticLabel:"Anwenden auf:"}); with (dialogColumns.add()){ with (dialogColumns.add()){ var MenuDeroulantSens = dropdowns.add({stringList:ListeDeroulantSens, selectedIndex:0}); } } } staticTexts.add({staticLabel:" "}); var ChoixDecimales = enablingGroups.add({staticLabel:"Auf-/Abrunden:", checkedState:false}); with (ChoixDecimales){ with(borderPanels.add()){ with(dialogColumns.add()){ var MenuDeroulantDecimales = dropdowns.add({stringList:ListeDeroulantDecimales, selectedIndex:2}); } staticTexts.add({staticLabel:"Dezimalstellen"}); } with(borderPanels.add()){ with(dialogColumns.add()){ var DecimalesForce = checkboxControls.add({staticLabel:"Dezimalstellen immer ergänzen", checkedState:false}); } } } staticTexts.add({staticLabel:" "}); var ChoixSeparateurs = enablingGroups.add({staticLabel:"Tausender- und Dezimaltrennzeichen", checkedState:false}); with (ChoixSeparateurs){ with(borderPanels.add()){ with(dialogColumns.add()){ var MenuDeroulantSeparateurs = dropdowns.add({stringList:ListeDeroulantSeparateurs, selectedIndex:0}); } staticTexts.add({staticLabel:"(1234.56 als Voreinstellung)"}); } } staticTexts.add({staticLabel:" "}); var ChoixOption = enablingGroups.add({staticLabel:"Option:", checkedState:false}); with (ChoixOption){ with(borderPanels.add()){ with(dialogColumns.add()){ var MenuDeroulantOption = dropdowns.add({stringList:ListeDeroulantOption, selectedIndex:0}); } with (dialogColumns.add()){ var CaseValeurOption = realEditboxes.add(); } } } staticTexts.add({staticLabel:" "}); var ChoixDevise = enablingGroups.add({staticLabel:"Währung:", checkedState:false}); with (ChoixDevise){ with(borderPanels.add()){ with(dialogColumns.add()){ var MenuDeroulantDevise = dropdowns.add({stringList:ListeDeroulantDevise, selectedIndex:0}); } } with(borderPanels.add()){ with(dialogColumns.add()){ var DeviseAvant = checkboxControls.add({staticLabel:"Währungssymbol vor dem Ergebnis", checkedState:false}); } } } staticTexts.add({staticLabel:" "}); with(borderPanels.add()){ with(dialogColumns.add()){ var ChoixVide = checkboxControls.add({staticLabel:"0 ignorieren", checkedState:false}); } } } } var MesChoix = Fenetre.show(); if (MesChoix == true){ var Sens = MenuDeroulantSens.selectedIndex+NombreSens; var Operation = MenuDeroulantOperation.selectedIndex; var Decimales = ChoixDecimales.checkedState; var ValeurDecimales = ListeDeroulantDecimales[MenuDeroulantDecimales.selectedIndex]; var ForceDecimales = DecimalesForce.checkedState; var Separateurs = ChoixSeparateurs.checkedState; var ValeurSeparateurs = ListeSeparateurs[MenuDeroulantSeparateurs.selectedIndex]; var Option = MenuDeroulantOption.selectedIndex; var ValeurOption = CaseValeurOption.editValue; var ValidationOption = ChoixOption.checkedState; var ValidationDevise = ChoixDevise.checkedState; var OptionDevise = ListeDeroulantDevise[MenuDeroulantDevise.selectedIndex]; var Option2Devise = DeviseAvant.checkedState; var ValidationVide = ChoixVide.checkedState; Fenetre.destroy(); Calcul(Sens,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide); } else{ Fenetre.destroy(); } } function Calcul(Sens,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide){ var Cellule = app.selection[0]; var Tableau = Cellule.parent; if (Cellule.constructor.name == "Table"){ Tableau = app.selection[0]; } if (Tableau.constructor.name == "Cell"){ Cellule = Cellule.parent; Tableau = Tableau.parent; var NbreCellule = app.selection[0].length; } var NbreLignes = Tableau.rows.length; var NbreColonnes = Tableau.columns.length; var NomCellule = Cellule.name; var Ligne = NomCellule.split(":")[1]; var Colonne = NomCellule.split(":")[0]; var Dernier = -1; var Premier = 0; if (Sens == 0){ if (NbreCellule == 0){ app.select(Tableau.columns[Number(Colonne)].cells.itemByRange(Number(Ligne),Number(Ligne))); } TotalCellules(app.selection[0].cells,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide); } else{ if (Sens == 1){ for (var j =0; NbreLignes >= j+1 ; j ++){ app.select(Tableau.rows[Number(j)].cells.itemByRange(Number(Premier),Dernier)); TotalCellules(app.selection[0].cells,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide); } } else{ for (var j =0; NbreColonnes >= j+1 ; j ++){ app.select(Tableau.columns[Number(j)].cells.itemByRange(Number(Premier),Dernier)); TotalCellules(app.selection[0].cells,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide); } } } } function TotalCellules(cells,Operation,Decimales,ValeurDecimales,ForceDecimales,Separateurs,ValeurSeparateurs,Option,ValeurOption,ValidationOption,ValidationDevise,OptionDevise,Option2Devise,ValidationVide){ for (var k = 0; cells.length > k; k++){ if (k !=0 && k != cells.length-1 && cells[k].texts[0].contents == "0" && Operation==3){ if (!confirm("ACHTUNG: Division durch 0!\n\nMöchten Sie fortfahren?")){ return; } } var con=cells[k].texts[0].contents.match(/[^ \-,.0-9€$£¥]/g); if (k != cells.length-1 && con != null){ if (!confirm("ACHTUNG:\nDie Tabelle enthält Zeichen, die keine Ziffern bzw. Währungssymbole sind!\n\nMöchten Sie fortfahren?")){ return; } } } if (ValidationOption == true && ValeurOption == 0 && (Option == 2 || Option == 3 || Option ==4)){ if (!confirm("ACHTUNG:\nKein gültiger Wert\nSie riskieren eine Multiplikation bzw. Division durch 0!\n\nMöchten Sie fortfahren?")){ return; } } var Total = ParseVirgule(cells[0].texts[0].contents); for (var j = 1; cells.length > j+1; j++){ try{ if (Operation==0) { Total += ParseVirgule(cells[j].texts[0].contents); } if (Operation==1) { Total = Total - (ParseVirgule(cells[j].texts[0].contents)); } if (Operation==2) { Total = Total * (ParseVirgule(cells[j].texts[0].contents)); } if (Operation==3) { Total = Total / (ParseVirgule(cells[j].texts[0].contents)); } } catch (e) {} } if (ValidationOption == true){ if (Option == 0) {Total_Calcul=Total + ValeurOption;} if (Option == 1) {Total_Calcul=Total - ValeurOption;} if (Option == 2) {Total_Calcul=Total * ValeurOption;} if (Option == 3) {Total_Calcul=Total / ValeurOption;} if (Option == 4) {Total_Calcul=(Total * ValeurOption)/100; } if (Option == 5) {Total_Calcul=Total + ((Total * ValeurOption)/100); } if (Option == 6) {Total_Calcul=Total - ((Total * ValeurOption)/100); } } else{Total_Calcul=Total;} Resultat_Final = ""; if (!isFinite(Total_Calcul)){ if (ValidationVide == false){ if (Total_Calcul !== Total_Calcul){ Resultat_Final = "Unmöglich !"; } else{ Resultat_Final = "Unendlich !"; } } } else{ if (ValidationVide == 1 && Total_Calcul == 0){ var Resultat_Final = ""; } else{ if (Decimales == 1){ // Arrondis Total_Calcul = Math.round(Total_Calcul*(Math.pow(10,ValeurDecimales)))/(Math.pow(10,ValeurDecimales)); if (ForceDecimales == true){// Forcer les 0 après la virgule Total_Calcul = Total_Calcul.toString(); if (Total_Calcul.indexOf(".") == -1){ NbrDecimales = 0; } else { CoupeDecimales = Total_Calcul.split("."); NbrDecimales = CoupeDecimales[1].length; } if (NbrDecimales < ValeurDecimales){ if (NbrDecimales == 0){ Total_Calcul += "."; } for (var i=0; i<(ValeurDecimales-NbrDecimales);i++){ Total_Calcul += "0"; } } } } var Total_Text = Total_Calcul.toString(); if (Separateurs == 1){ Virgule = ""; if (Total_Text.indexOf(".") != -1){ var Virgule = Total_Text.substr(Total_Text.indexOf("."), Total_Text.length); Total_Text = Total_Text.substr(0, Total_Text.indexOf(".")); } for (var i = Total_Text.length, j=3, k; j