I am facing a problem on the Powershell Excel ComObject where I am unable to accept a delimiter other than comma ,. Some of the external .csv files received use a different delimiter such as semicolon ;, pipeline | etc.
So, is there any solution on it to make it accepting custom delimiters? I tried using Import-Csv $fileloop -Delimiter ';' and it works. However I wish to remain using -ComObject to proceed as my script are all written using ComObject, and I need it to parse and check for columns and rows and some extra function.
Below is the relevant code snippet of opening .csv file for further processes:
$path = "C:\Users\1.csv"
$objexcel = New-Object -ComObject Excel.Application
$workbook = $objexcel.Workbook.Open($path)
$worksheet = $workbook.activesheet
$colMax = ($WorkSheet.UsedRange.Columns).count
$intcolMax = $colMax
$intRowMax = ($WorkSheet.UsedRange.Rows).count
.....
I did research on some related topics and tested, none of them were working:
Testing results:
1. The script need high portability, which means the script will pass to another users to use, so need to avoid using setting method on the region & language settings on windows.
2. The script need process large size and large amount of .csv file, hence need to avoid using method such as Import-Csv $fileloop -Delimiter ';'| Export-Csv $commadelimiteroutput -Delimiter ',' to rebuild a new .csv file into comma delimiter and then use the ComObject to process.
If this is lacking information or not clear, kindly let me know.