4.3 版
在 C# 中,我尝试使用 headless 选项将 XLSX 转换为 PDF,但是当我从 ASP.NET 或简单的命令提示符运行它时没有任何反应。
var pdfProcess = new Process();
pdfProcess.StartInfo.FileName = exe;
pdfProcess.StartInfo.Arguments = param + " \"" + fullDocPath +"\"";
pdfProcess.Start();
exe 和参数在哪里:
C:\Program Files (x86)\LibreOffice 4\program\soffice.exe
-norestore -nofirststartwizard -nologo -headless -convert-to pdf "c:\UDS_Docs\temp\Teller Roster National.xlsx"
我使用 GUI 来测试 LibreOffice 可以转换文件并且工作正常。
最佳答案
以下是如何在 ASP.NET MVC 网站上免费将 Excel、Word 等转换为 PDF:
免费安装 LibreOffice
将当前目录设置为与现有 XLS 相同的文件夹。这似乎是缺失的部分。
运行这个:
"C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" -norestore -nofirststartwizard -headless -convert-to pdf "TheFile.xlsx"
在 C# 中:
var pdfProcess = new Process();
pdfProcess.StartInfo.FileName = exePdf;
pdfProcess.StartInfo.Arguments = "-norestore -nofirststartwizard -headless -convert-to pdf \"TheFile.xlsx\"";
pdfProcess.StartInfo.WorkingDirectory = docPath; //This is really important
pdfProcess.Start();
确保您的 WorkerProcess 可以访问该 exe,默认情况下它没有。
关于c# - LibreOffice 在 ASP.NET MVC 中将 XLSX 转换为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26814534/