Hi Nathaniel & Kvprasoon,
Thanks for the quick response on my query.
Firstly, when I try to install the ImportExcel via powershell as Admin I get below error ( I work in a very restricted environment, so I requested temp admin access for this which stays good for 24 hours )
Install-Module -Name PSExcel
PackageManagement\Install-Package : No match was found for the specified search criteria and module name ‘PSExcel’.
Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ … $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power…InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
PS C:\windows\system32> Get-PSRepository
WARNING: Unable to find module repositories.
So I’m working with COM object as ImportExcel wasn’t available.
Secondly, I wrote a script to download the file from sharepoint, puts them in separate csv file for each sheets & converts into TXT file for 2 of the sheets.
Finally used the get-content & set-content to concatenate the 2 TXT files into a single TXT file.
How does my final output/TXT looks: ( Sheet3.TXT )
UserID
–
thy3245
rop9087
ew36645
tyt0975
rtio9065
trew2345
io90789
Am trying to delete/truncate all spaces on the final TXT file & remove the column name as well, but the Trim() function doesn’t do the job am looking for.
- Remove the spaces
- Remove Column name: UserID & --
My script looks like below:
#Specify the path of the Output CSV files
$Newfile = “C:\Users\Desktop\Script\Sheet1”
$Newfile2 = “C:\Users\Desktop\Script\Sheet2”
Create an Object Excel.Application using Com interface
$objExcel = New-Object -ComObject Excel.Application
Disable the ‘visible’ property so the document won’t open in excel
$objExcel.Visible = $false
Open the Excel file and save it in $WorkBook
$WorkBook = $objExcel.Workbooks.Open($FilePath)
Load the WorkSheet ‘Sheet1’ & ‘Sheet2’
$WorkSheet = $WorkBook.Worksheets | where-object {$.name -like “Sheet1”}
$WorkSheet2 = $WorkBook.Worksheets | where-object{$.name -like “Sheet2”}
#SaveAs option to ‘;’ limited Excel sheet to CSV format
$WorkSheet.SaveAs($Newfile+“.csv”,6,0, 0, 0, 0, 0, 0, 0, $true)
$WorkSheet2.SaveAs($Newfile2+“.csv”,6,0, 0, 0, 0, 0, 0, 0, $true)
Import-Csv C:\Users\Desktop\Script\Sheet1.csv -Delimiter ‘;’ | Select-Object UserID -Skip 1 | Out-File C:\Users\Desktop\Script\Sheet1.txt
Import-Csv C:\Users\Desktop\Script\Sheet2.csv -Delimiter ‘;’ | Select-Object UserID -Skip 1 | Out-File C:\Users\Desktop\Script\Sheet2.txt
Get-Content Sheet1.txt, Sheet2.txt | Set-Content Sheet3.txt
#Close the WorkBook
$WorkBook.close($false)
#Close the Excel connection
$objExcel.Quit()