【发布时间】:2020-12-22 16:59:09
【问题描述】:
我使用 PowerShell 模块 ImportExcel 将 Excel 文件转换为 csv 文件:
exportCSV.ps1:
Param(
[string]$cInput,
[string]$cOutput,
[string]$cSheet
)
if (!$cInput -Or !$cOutput -Or !$cSheet) { Write-Host "failed" }
else {
try {
Import-Excel -WorksheetName $cSheet -Path $cInput -NoHeader | Export-Csv $cOutput -NoTypeInformation -encoding utf8
Write-Host "done"
} catch {
Write-Host $error
}
}
运行脚本的命令:
powershell -File "D:\test\exportCSV.ps1" -cInput "D:\test\testFile.xlsx" -cOutput "D:\test\testFile.csv" -cSheet "Sheet 1"
当我直接在 cmd 中运行此脚本时,它可以正常工作。但是当我在 php 中使用shell_exec() 运行时,出现以下错误:
Exception calling "Load" with "1" argument(s): "Exception of type 'System.OutOfMemoryException' was thrown."
testFile.xlsx 有 91,094 KB。当我使用只有 27,307 KB 的文件时,它也适用于 PHP 的 shell_exec()。我已经在php.ini (256M) 中检查了memory_limit,所以这应该不是问题。
【问题讨论】:
标签: php excel powershell shell-exec