There is a task to convert xlsx files to pdf and ods for downloading from the site.

What is the best way to organize this process automatically, having Windows Server 2012 installed with Excel?

There are over a hundred xlsx files and they are constantly changing, so it’s best to have the script run directly from the download page and run on the fly.

1 answer 1

Under the proposed conditions, one of the conversion options is implemented using a Windows script server (Windows Script Host), a vbs script containing the conversion commands, and generating the necessary command line in php followed by a call.

Sample script call, generated in php:

cscript xls-pdf.vbs <полный путь до файла в формате xls> 

For example:

 cscript xls-pdf.vbs "D:\07-Проекты\soQu489061 (Конвертация-xls-в-pdf-и-ods)\Excel-PDF-ODS.xlsx" 

Vbs script code (name file xls-pdf.vbs )

 ' ограничения: файл XLS с одним листом ' передаваемые параметры ' Полное Имя Файла в формате XLS ' Полное Имя Файла в формате PDF ' Полное Имя Файла в формате ODS xlsFile = WScript.arguments(0) ' отладка 'MsgBox (xlsFile) arStr = Split (xlsFile, ".") 'отладка 'MsgBox (arStr(0)) pdfFile = arStr(0) & ".pdf" odsFile = arStr(0) & ".ods" ' отладка 'MsgBox (pdfFile) 'MsgBox (odsFile) Set xlsObj = CreateObject("Excel.Application") 'xlsObj.Visible = True Set xlsWrkBk = xlsObj.WorkBooks.Open (xlsFile) xlsObj.DisplayAlerts = False ' 60 - OpenDocument Spreadsheet xlsWrkBk.SaveAs odsFile, 60 ' 0 - PDF xlsWrkBk.ActiveSheet.ExportAsFixedFormat 0, pdfFile, 0, True, False,,,False xlsWrkBk.Close xlsObj.Quit WScript.Quit