Question Export textbox vers .csv

Plus d'informations
il y a 4 ans 5 mois #29387 par Chipaux
Export textbox vers .csv a été créé par Chipaux
Bonjour à tous et avant tout merci pour la richesse du site!

Je débute en PowerShell. Mon but est de créer un formulaire qui sera déployé sur des postes afin de remonter des données que je ne peut pas récupérer informatiquement (localisation, affectation..).

Le hic, c'est que j'aimerai que mon bouton \"envoyer\" enregistre mes données de ce formulaire vers un fichier type CSV.

J'ai regardé sur plusieurs sites, mais je ne pense pas avoir encore assez de pratique pour trouver ma solution.

Voici le sript fini, auquel je souhaite exporter mes données.

[code:1]
# Fenêtre générale.

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form
$form.Text = 'INVENTAIRE'
$form.Size = New-Object System.Drawing.Size(900,700)
$form.StartPosition = 'CenterScreen'


# Création bouton d'envoie en bas à droite
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(500,600)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'ENVOYER'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)


# Logo entreprise en bas à droite.
$pic = New-Object System.Windows.Forms.PictureBox
$pic.Size = New-Object System.Drawing.Size(100, 100)
$pic.Image = [System.Drawing.Image]::FromFile(\"mon_image\"«»)
$pic.Location = New-Object System.Drawing.Point(10,540)
$pic.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
$form.Controls.Add($pic)

# Création entête description.
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(550,30)
$label.Text = 'Ce formulaire a pour but de resencer l.ensemble des postes de travail du site.'
$form.Controls.Add($label)


# Partie 1
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,70)
$label.Size = New-Object System.Drawing.Size(100,20)
$label.Text = 'ETIQUETTE 1'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(120,70)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

# Partie 2
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,100)
$label.Size = New-Object System.Drawing.Size(100,20)
$label.Text = 'ETIQUETTE 2'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(120,100)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

# Localisation du poste
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,200)
$label.Size = New-Object System.Drawing.Size(270,20)
$label.Text = 'LOCALISATION DU POSTE (ex:N1INF7)'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(280,200)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

# Pôle de compétence
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,230)
$label.Size = New-Object System.Drawing.Size(270,20)
$label.Text = 'POLE DE COMPETENCE'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(280,230)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

# UA/UF
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,260)
$label.Size = New-Object System.Drawing.Size(270,20)
$label.Text = 'UA/UF'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(280,260)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

# Texte de fin
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,500)
$label.Size = New-Object System.Drawing.Size(550,30)
$label.Text = 'Pour toute information complémentaire, contactez xxxxxx'
$form.Controls.Add($label)


$form.Topmost = $true

$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}

[/code:1]

Merci par avance pour vos trucs et astuces!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 ans 5 mois #29389 par Laurent Dardenne
Salut,
Coonadorator écrit:

Merci par avance pour vos trucs et astuces!

Déjà nomme tes composants de manière unique :
[code:1]
# Partie 2

$label = New-Object System.Windows.Forms.Label
...
$textBox = New-Object System.Windows.Forms.TextBox


# Localisation du poste
$label = New-Object System.Windows.Forms.Label
...
$textBox = New-Object System.Windows.Forms.TextBox

[/code:1]
:silly:
Puis dans une fonction récupère les données de tous tes textbox

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.066 secondes
Propulsé par Kunena