Question
colorier un chiffre negative en rouge
- arnold
- Auteur du sujet
- Visiteur
-
merci pour votre aide.
j'ai loupe $c ce ma faute.
[code:1]$c = \"- 400\"
$e = [Int64]$color1.$c[/code:1]
j'ai teste une autre maniere suivant (HTML):
la aussi sa ne fonctionne pas.
la valeur est bien rouge. par contre j'ai 2 champ
a côte à côte?
[code:1]if (([Int64]$crim) -eq 0) # % green
{$Con5 = \"<tr><th>Criminalités</th>
<td style = text-align:right;/>\"+$bsec1+\"</td>
<td style = text-align:right;/>$secoldC</td>
<td style = text-align:right;color:#B3B3B3;/>$secdate2</td>
<th></th>
<td style = text-align:right;color:#008000;/>$crim $pcent</td>
<td style = text-align:right;/>$SecIdxA2</td>
if (([Int64]$seAoldB«») -le 0){
<td style = text-align:right;color:#E30000;/>$seAoldC</td>
}
else {
td style = text-align:right;/>$seAoldC</td>
}
<td style = text-align:right;/>$SecIdxB2</td>
<td style = text-align:right;/>$seBoldC</td>
<th></th></tr>}[/code:1]
resultat de sortie:
$con5
<tr><th>Criminalités</th>
<td style = text-align:right;/> 841 429</td>
<td style = text-align:right;/> 62</td>
<td style = text-align:right;color:#B3B3B3;/> 1</td>
<th></th>
<td style = text-align:right;color:#008000;/>0 %</td>
<td style = text-align:right;/> 198 673</td>
if (([Int64]-373) -le 0){
<td style = text-align:right;color:#E30000;/>- 373</td>
}
else {
<td style = text-align:right;/>- 373</td>
}
<td style = text-align:right;/>3 366 016</td>
<td style = text-align:right;/> 248</td>
<th></th></tr>
plus s'avance, plus je suis perdue.
doit je eclate le bloc?
respectueusement
arnold
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
- Messages : 6311
- Remerciements reçus 68
Tu peux me tutoyer.bonjour monsieur,
arnold écrit:
Tu n'est pas le seul si cela peut te rassurerplus s'avance, plus je suis perdue.
C'est souvent comme ça avec PowerShell.
Dans ton exemple, tu mixtes des données et du code.
C'est possible :
[code:1]
$Con5 =@\"
<tr><th>debut</th>
<td style = text-align:right;/>fin</td>
$(
if ($j -le 0)
{\"<td style = text-align:right;color:#E30000;/>Var1</td>\"}
else
{ \"<td style = text-align:right;/>Var2</td>\"}
)#nested code
<td style = text-align:right;/>$SecIdxB2</td>
<td style = text-align:right;/>$seBoldC</td>
<th></th></tr>
\"@
[/code:1]
Mais dans ton cas,je ne pense pas que ce soit ce que tu souhaites faire.
[code:1]
td style = text-align:right;/>$SecIdxA2</td>\"
if (([Int64]$seAoldB«») -le 0){
\"<td style = text-align:right;color:#E30000;/>$seAoldC</td>\"
}
else {
\"td style = text-align:right;/>$seAoldC</td>\"
}
\"<td style = text-align:right;/>$SecIdxB2</td>
...\"
[/code:1]
Si tu veux que le résultat de tout ces traitements aille dans une varaible mieux vaut utiliser un fonction dédié ou un script bloc.
[code:1]
$sb={
\"<tr><th>debut</th>\"
\"<td style = text-align:right;/>fin</td>\"
if ($j -le 0)
{\"<td style = text-align:right;color:#E30000;/>Var1</td>\"}
else
{ \"<td style = text-align:right;/>Var2</td>\"}
\"<td style = text-align:right;/>$SecIdxB2</td>\"
\"<td style = text-align:right;/>$seBoldC</td>\"
\"<th></th></tr>\"
}
$con5=&sb
function New-HtmlPage($j) {
\"<tr><th>debut</th>\"
\"<td style = text-align:right;/>fin</td>\"
if ($j -le 0)
{\"<td style = text-align:right;color:#E30000;/>Var1</td>\"}
else
{ \"<td style = text-align:right;/>Var2</td>\"}
\"<td style = text-align:right;/>$SecIdxB2</td>\"
\"<td style = text-align:right;/>$seBoldC</td>\"
\"<th></th></tr>\"
}
$con5=New-HtmlPage $j
[/code:1]
Effectivement de découper les blocs aidera à débugger/maintenir le code. : $Header,$Body,...
En même temps, j'ai l'impression d'être hors-sujet
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- arnold
- Auteur du sujet
- Visiteur
-
bonjour a vous
j'ai trouver la solution de mettre en rouge
le nombre negative pour une page html:
(on peut donne toutes couleur au besoin)
if ([int64]var2 -lt 0) {
$var2.style.color=\"#E30000\"; }
pour info :
$var2.style.font=\"10pt Arial\";
uops, les commande DotNet
merci a vous
arnold
Connexion ou Créer un compte pour participer à la conversation.
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- colorier un chiffre negative en rouge