规格:
使用的语言和软件:
代码:
#Define locations and delimiter
$csv = "\\READYSHARE\USB_Storage\Trucking_Inc\SomeFile.csv" #Location of the source file
$xlsx = "\\READYSHARE\USB_Storage\Trucking_Inc\SomeFile2.xlsx" #Desired location of output
$delimiter = "," #Specify the delimiter used in the file
# Create a new Excel workbook with one empty sheet
$excel = New-Object -ComObject excel.application
$workbook = $excel.Workbooks.Add(1)
$worksheet = $workbook.worksheets.Item(1)
# Build the QueryTables.Add command and reformat the data
$TxtConnector = ("TEXT;" + $csv)
$Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1"))
$query = $worksheet.QueryTables.item($Connector.name)
$query.TextFileOtherDelimiter = $delimiter
$query.TextFileParseType = 1
$query.TextFileColumnDataTypes = ,1 * $worksheet.Cells.Columns.Count
$query.AdjustColumnWidth = 1
# Execute & delete the import query
$query.Refresh()
$query.Delete()
# Save & close the Workbook as XLSX.
$Workbook.SaveAs($xlsx,51)
$excel.Quit()
作业错误: 以用户身份执行:NT Service \ SQLAgent $ Server。 ... l.exe-文件“ C:\ Scripts \ trasaction.ps1”,Microsoft Excel无法访问文件“ \ READYSHARE \ USB_Storage \ Trucking_Inc \ SomeFile2.csv”。有几种可能的原因:文件名或路径不存在。该文件正在被另一个程序使用。您要保存的工作簿与当前打开的工作簿具有相同的名称。在C:\ Scripts \ trasaction.ps1:12处char:1 + $ Workbook = $ excel.Workbooks.Open($ ExcelFilePath)+ ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:OperationStopped:(:) [],COMException + FullyQualifiedErrorId:System.Runtime.InteropServices.COMException您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:13处char:1 + $ Worksheet = $ Workbook.Sheets.Item(1)+ ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:21 char:1 +外文件-FilePath C:\ Scripts \ process.txt -InputObject $ Columns.Cells ... + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:22 char:1 + Write-Host $ Columns.Cells(5,5).Value + ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:161处char:1 + $ eRow = $ Worksheet.cells.item(1,1).entireRow + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在null上调用方法值表达式。在C:\ Scripts \ trasaction.ps1:162处char:1 + $ active = $ eRow.activate()+ ~~~~~~~~~~~~~~~~~~~~~~~~~ 〜+ CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:163处char:1 + $ active = $ eRow.insert($ xlShiftDown)+ ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:164 char:1 + $ Worksheet.Cells.item(1,1)=“ TRANSACTION_DATE” + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式。在C:\ Scripts \ trasaction.ps1:165 char:1 + $ Worksheet.Cells.item(1,2)=“ AMOUNT” + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:166处char:1 + $ Worksheet.Cells.item(1,3)=“ TYPE_OF_AUTHORIZATION_AND_DATE” + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能在空值表达式上调用方法。在C:\ Scripts \ trasaction.ps1:167 char:1 + $ Worksheet.Cells.item(1,4)=“ CHECK_NUMBER” + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您不能...处理退出代码0。步骤成功了。
尝试过的东西。
注意:
通过手动打开cmd并执行,此powershell脚本在命令提示符下运行良好。甚至可以通过ISE(x86)手动运行。
但是,从工作中使用它时,您会收到上面列出的错误。
我试图获取readyshare驱动器来赋予SQLSeverAgent权限,但又恢复为原始权限。我拥有的路由器是NightHawk路由器 而且我没有在路由器中看到任何设置来提供允许通过Windows 10尝试的权限,但又恢复为原始权限的设置。
检查了邮件中的这些建议
未应用。
是否有我可能不知道的解决方法或选项?需要一些指导或正确方向的指针。