I am wondering if you can help, I want to be able to format column B
to a Number column on export instead of running send keys once the csv has been created.
I have looked at a few examples on Stack as well as other forums but unfortunately not very clear. any help would be awesome.
please see below my script, the top half is extracting the data from an sql
db and then creates a csv
with the result
$command = $connection.CreateCommand()
$command.CommandText = "SELECT T_CUSTOMERPRICELIST.C_DESCRIPTION AS ROLE , T_CUSTOMERPRICELISTBASESTANDARDRULE_PRICEDEFINITION.C_NETPRICE AS PRICE,T_CUSTOMERPRICELIST.C_REFERENCE AS MIN_QTY, T_CUSTOMERPRICELIST.C_REFERENCE AS FLAT_OR_DISCOUNT_PRICE, T_PRODUCT.C_D_PRODUCTID AS PRODUCT_ID
FROM T_CUSTOMERPRICELISTPRODUCTSTANDARDRULE
INNER JOIN T_CUSTOMERPRICELIST ON T_CUSTOMERPRICELISTPRODUCTSTANDARDRULE.C__OWNER_ = T_CUSTOMERPRICELIST.C_ID
INNER JOIN T_PRODUCT ON T_CUSTOMERPRICELISTPRODUCTSTANDARDRULE.C_PRODUCT = T_PRODUCT.C_ID
INNER JOIN T_CUSTOMERPRICELISTBASESTANDARDRULE_PRICEDEFINITION ON T_CUSTOMERPRICELISTPRODUCTSTANDARDRULE.C_ID = T_CUSTOMERPRICELISTBASESTANDARDRULE_PRICEDEFINITION.C__OWNER_
WHERE T_CUSTOMERPRICELIST.C_REFERENCE = '1' AND T_PRODUCT.C_D_PRODUCTID IS NOT NULL;"
$dataSet = New-Object System.Data.DataSet
$adapter = New-Object System.Data.SqlClient.SqlDataAdapter $command
$adapter.Fill($dataSet) | Out-Null
$DataSet.Tables[0] | export-csv -Path "C:\Program Files\Redec_ScanIQ\RI Scan IQ\IQCustomerPrice\CustPrice.csv" -NoTypeInformation
Start-Process "C:\Program Files\Redec_ScanIQ\RI Scan IQ\IQCustomerPrice\CustPrice.csv"
Start-sleep -Seconds 2
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#[Microsoft.VisualBasic.Interaction]::AppActivate(“Microsoft Excel (32 Bit)”)
[System.Windows.Forms.SendKeys]::SendWait(“{Right 1}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{Down 1}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“^+{Down}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“%{h}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{o}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{e}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{tab}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{down 1}”)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait(“{Enter}”)
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait(“^{s}”)
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait(“{enter}”)
Start-Sleep -Milliseconds 500
Stop-Process -Name EXCEL -force
This image is Before the Send Keys
This image is After the Send Keys
this is the csv
which is produced, and the column named PRICE needs to be formatted to number
$csv1 = Import-Csv "C:\Program Files\Redec_ScanIQ\RI Scan IQ\IQCustomerPrice\CustPrice.csv"
$csv2 = Import-Csv "C:\Program Files\Redec_ScanIQ\RI Scan IQ\customerpriceorig\OldFile.csv"
$differences = Compare-Object $csv1 $csv2 -Property PRICE -SyncWindow 0 -PassThru |Where-Object SideIndicator -eq '<=' |Select * -Exclude SideIndicator
$differences |Export-Csv "C:\Program Files\Redec_ScanIQ\RI Scan IQ\customerpriceorig\import\csvFinal.csv" -NoTypeInformation