If I use the following code from phpspreadsheet documentation:
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('template.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getCell('A1')->setValue('John');
$worksheet->getCell('A2')->setValue('Smith');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls');
The template loaded has a specific paper type set for my printer, so that I can simply print it without changing anything. However when using the above code, this setting is lost, and the default paper slot of my printer is used. This results in me not beeing able to just print the excel file using powershell, because I need to manually set the paper type. Anyone got a clue how to get around this issue, either from within php or the powershell used to print it? The powershell code I am using is: Param ( [string]$name )
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $false
$filename = "C:\somepath\" + $name + ".xlsx"
$wb = $xl.Workbooks.Open($filename)
$ws = $wb.WorkSheets.Item(1)
$ws.PrintOut()
$xl.quit()