duandou1903
duandou1903
2012-08-28 09:06
浏览 127
已采纳

将Excel文件发送到客户端的打印机

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.

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP网站,我正在将一些数据写入Excel文件。 我的Excel文件可以通过按钮下载。 它会打开一个窗口或下载管理器(如果已配置)。 到目前为止一切都很好。 现在我想将此文件自动发送到客户端的默认打印机。 当用户单击打印时,网页必须将“EXCEL FILE”发送给打印机。 不像JavaScript中的“window.print()”函数。

有没有办法用javascript或AJAX做到这一点? 客户端是否必须下载Excel文件才能将其发送到默认打印机? 我尝试使用隐藏的“iframe”和“src = bla_bla.xls”但它会自动打开下载窗口。

简单地说我想要这个 Excel 文件, 在服务器上准备,发送到客户端的默认打印机并打开打印选项窗口。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtwr2012
    dtwr2012 2012-08-28 09:12
    已采纳

    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 ..

    点赞 评论
  • dqa35710
    dqa35710 2012-09-22 09:40

    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.

    点赞 评论

相关推荐