jsp怎样打印预览和打印数据库中查询出来的表格信息,希望大家帮帮忙啊

jsp怎样打印预览和打印数据库中查询出来的表格信息,希望大家帮帮忙啊,第1张

在<head>中加:

<object id=factory style="display:none"

classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="smsx.cab#Version=6,3,434,26"></object>

<meta name=ProgId content=Excel.Sheet><meta name=Generator content="Microsoft Excel 11">

<style media="print" type="text/css">

.Noprint

{

display: none

}

</style>

在<body>中加:

<input name="print" id="print" type="button" class="Noprint" value="打印" onClick="window.print()">

<input name="print" id="print" type="button" class="Noprint" value="打印预览" onClick="factory.printing.Preview()">

这个会打印出整个jsp页面,不想打印的就设置class="Noprint"。哈,希望有帮助

我最近刚刚实现了这个。是基于Excel的。

'********************************

' 该模块用来实现各种打印功能

'********************************

'打印到excel中

Public Function print2Excel() As Boolean

' On Error GoTo Print2Excel_Error

Dim xlApp As Excel.Application

Dim i, j ,colums As Integer

Dim startRow, startCol As Integer

Dim tmp() As Variant

startRow = 1

startCol = 1

colums =10

Set xlApp = New Excel.Application '注意之前,要在工程-》引用中将支持excel的控件加载进来

Set xlApp = CreateObject("Excel.Application") '激活EXCEL应用程序

xlApp.Visible = False '隐藏或显示EXCEL应用程序窗口

xlApp.SheetsInNewWorkbook = 1 '打开工作簿,strDestination为一个EXCEL报表文件

Set xlBook = xlApp.Workbooks.Add '打开工作簿,strDestination为一个EXCEL报表文件

Set xlSheet = xlBook.Worksheets(1)

xlSheet.PageSetup.Orientation = g_Print_Method

'设置打印数据 g_Print_Data是一个Variant的二维数组,这个你要根据自己的情况作修改

For i = LBound(g_Print_Data) To UBound(g_Print_Data)

For j = LBound(g_Print_Title) To colums - 1

'xlSheet.Cells(startRow, i + startCol).Width = Len(CStr(" " &g_Print_Data(i,j) &" "))

、 Next

Next

'页面设置 g_Preview为全局变量,是否要求预览

If g_Preview = True Then

xlApp.Caption = "打印预览" '设置预览窗口的标题

xlApp.Visible = True '隐藏或显示EXCEL应用程序窗口

xlApp.ActiveSheet.PrintPreview

Else

xlSheet.PrintOut '执行打印

End If

xlApp.DisplayAlerts = False

xlApp.Quit '退出EXCEL

xlApp.DisplayAlerts = True

' xlBook.Save '保存文件

print2Excel = True

Exit Function

Print2Excel_Error:

print2Excel = False

End Function


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10004098.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存