Using Powershell and Excel 2016, I'm trying to open a .xlsx file, extract a single page, and save this page as a .csv with a " ; " delimiter. The problem is that while Excel expects " ; " delimiter when opening a csv file, it always saves them with a " , " delimiter.
I'd prefer to not have to change any settings, this is a script i'm writing for a project that needs to work natively on any pc, so having to go and change settings every time I need it to run on another computer would be problematic.
I already checked that the list delimiter settigs in windows was indeed a " ; ", and it is.
I tried every type of CSV saving described in the microsoft doc (https://learn.microsoft.com/fr-fr/office/vba/api/excel.xlfileformat), what's weird is that when saving a file from the GUI version, I only have 3 versions of CSV, instead of 5 listed on the website, and one of them is "CSV with " ; " delimiter", which works as intended, but I can't seem to use this type of file when saving using Excel via Powershell
There's apparently a "local" flag that can be activated for Excel to use the delimiter settings of windows, but I have no idea of how ot activate it in Powershell and I'd prefer not to use this since it means that the program wouldn't work on a Windows with a different delimiter configuration.
# Args[0] : file to open
# [1] : file to save
# page_to_extract : name of the page I need
# I open an Excel session
$excel_session = New-Object -Com Excel.Application
$excel_session.displayAlerts = $false
# I open the file I need to extract the page from
$excel_workbook = $excel_session.workbooks.open($args[0])
# I load in the page
$excel_worksheet = $excel_workbook.worksheets($page_to_extract)
# I save the page using a csv type (6,22,24,62,23)
$excel_worksheet.saveAs($args[1], 6)
$excel_session.quit()
This code always saves my csv with a " , " delimiter, I need " ; " instead.
I need to use Powershell and ONLY Powershell for this, no windows settings, no excel settings.