BSW.Blog

Calculate Excel Column Name By Number Using Powershell.

function Get-ExcelCol{
param( [int]$Number)
end{
    [string]$res=""
    while($Number -gt 0 ) {
        $res= [System.Convert]::ToChar((($Number-1) % 26)  +65 ) +$res
        $Number=($Number-(($Number-1) % 26))/26
        
        } 
        $res
    }

}

Result:

PS C:\> Get-ExcelCol 26
Z

PS C:\> Get-ExcelCol 27
AA

PS C:\> Get-ExcelCol 52
AZ

PS C:\> Get-ExcelCol 53
BA

Babak
#Powershell #cmdlet #function #excel #column #Get-ExcelCol
1/29/2014 6:31:25 AM
Write Comment

Fast Way To Convert A Column to CSV.

Select replace	(
					(
					select name+','  from sys.databases  
						for xml path ('')
					)+',',',,',''
				) 

Result:

master,tempdb,model,msdb,Customers,ExternalDB

Babak
#column #SQL #SQLServer #CSV
1/29/2014 7:28:03 AM
Write Comment