Hi,
I use this code (found somewhere) to convert csv to xls. It works perfectly when there is no national characters.
But when I am trying to convert csv file which is encoded in ISO 2859-2 it results in some text errors (like Waciciel or Sd). When I am doing it manually from excel (Data -> from text -> set encoding 2859-2 ...) everything is ok
Any idea how to set it up the same way in this script?
### Set input and output path $inputCSV = "C:\tmp\test.CSV" $outputXLSX = "C:\tmp\test.xls" ### Create a new Excel Workbook with one empty sheet which name is the file $excel = New-Object -ComObject excel.application $workbook = $excel.Workbooks.Add(1) $worksheet = $workbook.worksheets.Item(1) $worksheet.name = "$((GCI $inputCSV).basename)" ### Build the QueryTables.Add command ### QueryTables does the same as when clicking "Data From Text" in Excel $TxtConnector = ("TEXT;" + $inputCSV) $Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1")) $query = $worksheet.QueryTables.item($Connector.name) ### Set the delimiter ( , or ; ) according to your regional settings $query.TextFileOtherDelimiter = $Excel.Application.International(5) ### Set the format to delimited and text for every column ### A trick to create an array of 2s is used with the preceding comma ### this options don't seems necessary $query.TextFileParseType = 1 $query.TextFileColumnDataTypes = ,2 * $worksheet.Cells.Columns.Count ### change decimal separator as "." (can be ",") $query.TextFileDecimalSeparator = "." $query.AdjustColumnWidth = 1 ### Execute & delete the import query # using my_output avoid having an outuput that display true $my_output = $query.Refresh() $query.Delete() ### Save & close the Workbook as XLS. $Workbook.SaveAs($outputXLSX,56) $excel.Quit()