Reputation: 1645
i have a PHP web site and i am writing some data to an Excel file. My Excel file can be downloaded with a button. It opens a window or download manager (if configured). So far everything is ok. Now i want to send this file automatically to the Client's default printer. When users click print, web page must send the "EXCEL FILE" to printer. NOT like the "window.print()" function in JavaScript.
Is there a way to do this with javascript or AJAX ? Does the client have to download the Excel file in order to send it to default printer ? I tried to use a hidden "iframe" with "src = bla_bla.xls" but it automatically opens the download window.
Briefly i want this Excel file, which is prepared on server, to be sent to client's default printer and open up the print options window.
Upvotes: 1
Views: 2168
Reputation: 1239
I think that the problems you are getting with the security obstacles with activex is because you are embedding excel into a webpage. It should be posssible to print a worksheet by publishing the sheet as HTML using Excel's publish method. I use this to create an HTML for emails.
Dim rngeTableRange As Range
Dim lsTableFileName As String
lsTableFileName = <filepath and name for HTML output as string>
Set rngeTableRange = ActiveSheet.UsedRange
ActiveWorkbook.PublishObjects.Add(xlSourceRange, lsTableFileName, _
rngeTableRange.Parent.Name, rngeTableRange.Address, xlHtmlStatic).Publish True
If you want the printout to appear to be a spreadsheet you can add borders before publishing the worksheet. The following VBA code will put a border around each cell:
With ActiveSheet.UsedRange.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
End With
The result should be an HTML image of the spreadheet that dosn't lead to the security warnings and I would assume would be printable.
Upvotes: 1
Reputation: 5749
To do this ... you need a client-side scriptlanguage like javascript or vb. php is server-side and don't know anything about the client's printer ..
Upvotes: 0