Chargement assembly System.Drawing
Bonjour,
J'ai codé un bon gros script PowerShell faisant des modifs dans des Excels.
Et depuis peu, il refuse de faire fonctionner les fonctions pour colorier les cases !
Voici l'erreur qu'il répète :
Code:
1 2 3 4 5 6 7 8 9 10 11
| Type [System.Drawing.Color] introuvable : assurez-vous que l'assembly
contenant ce type est chargé.
Au caractère
Z:\Excel_CSVtoXLSX_CourierNew_AutoFit_Color.ps1:195 : 17
+ $objWorksheet.Cells.Item($row,$col).Interior.Color =
[System.Dra ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidOperation : (System.Drawing.Color:TypeNam
e) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound |
Les 2 lignes causant cette erreur sont :
Code:
1 2 3 4 5 6 7 8
| if (($col -eq 1) -or ($col -eq 2) -or ($col -eq 3) -or ($col -eq 6) -or ($col -eq 7))
{
$objWorksheet.Cells.Item($row,$col).Interior.Color = [System.Drawing.Color]::FromArgb(216, 228, 188)
}
else
{
$objWorksheet.Cells.Item($row,$col).Interior.Color = [System.Drawing.Color]::FromArgb(242, 220, 219)
} |
Sachant que plus haut j'ai tapé :
Code:
1 2 3 4 5 6 7 8
| $objWorksheet.Cells.Item($row,$col).Font.Name = "Courier New"
$objWorksheet.Cells.Item($row,$col).Font.Bold = $True
[system.reflection.assembly]::loadWithPartialname("Microsoft.Office.Interop.Excel") | out-Null
[system.reflection.assembly]::loadWithPartialname("System.Drawing") | out-Null
$xlConstants = "microsoft.office.interop.excel.Constants" -as [type]
#xlBottom xlTop xlCenter
$objWorksheet.Cells.Item($row,$col).VerticalAlignment = $xlConstants::xlTop
$objWorksheet.Cells.Item($row,$col).HorizontalAlignment = $xlConstants::xlCenter |
Bref, je ne comprends pas pourquoi mon assembly n'est pas chargé !
Avez-vous une piste ? Merci !