I am trying to import a tab delimited file into excel using powershell. Some of my numbers are very long and I need to import them as text to preserve them. I made an Excel Macro of the process and I want to incorporate the "Preserve Formatting" parameter. Everything in the macro from .TextFileStartRow = 1 till the end is represented in the powershell script but earlier parameters are omitted.
How do I communicate to skip those parameters? Is there a way to preserve the format using the [blahblah.interop.excel]::____ format and insert one line in?
Below is my powershell and further down is a snippet from the macro
$thing = "C:\Users\michaelw\Desktop\Nasty 19\Testfile.txt" #where the original files are $excel = New-Object -ComObject Excel.Application Add-Type -AssemblyName Microsoft.Office.Interop.Excel $excel.Visible = $true $excel.DisplayAlerts = $false $wb = $excel.Workbooks.OpenText( $thing, # file to open [Microsoft.Office.Interop.Excel.XlPlatform]::xlWindows, 1, # start from row 1 [Microsoft.Office.Interop.Excel.XlTextParsingType]::xlDelimited, [Microsoft.Office.Interop.Excel.XlTextQualifier]::xlTextQualifierDoubleQuote, $false, # Consecutive Delimiter $true, # tab $false, # semicolon $false, # comma $false, # space $false, # use other '|') With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Users\michaelw\Desktop\Nasty 19\Testfile.txt", _ Destination:=Range("$A$1")) .CommandType = 0 .Name = "Testfile" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With