紧急求救:在线急等!!!!希望各位高手指点.
我设计软件时生成报表统一是用VB中的报表,打印单据时都是打印窗体.
但现在客户的打印机改成针式打印机,而且纸张是连纸(也就是不分页的纸,好长好长,打到哪撕到哪),这样打印报表时在表头和表尾都会留下好长的空白,更要命的是最后一页如果记录数还不满一页时留下的空白更大,而打印据时,每打印一张小小的单据都占据一张A4纸张大小,浪费更大,
请问我该如何解决这个问题???????????????????????????????????????????
问题点数:100、回复次数:17Top
1 楼thinkeasy(Nothing)回复于 2002-06-24 19:37:46 得分 50
改打印的程序,用行打印Top
2 楼thinkeasy(Nothing)回复于 2002-06-24 19:38:46 得分 0
就是说用Printer对像来打印,
或是设置打印纸的大小,也可能搞定,我没试过Top
3 楼lonelystarcn(虫虫)回复于 2002-06-24 19:39:14 得分 0
但我现在的报表太多了,有20张,怎么改?时间不够,报表中能有不分页打印吗?Top
4 楼qhzxcz(真想练练降龙十八掌)回复于 2002-06-24 19:40:31 得分 50
同意楼上,printer比较灵活,但有些麻烦Top
5 楼lonelystarcn(虫虫)回复于 2002-06-24 19:46:12 得分 0
我现在的想法是:
当需要打印报表时用Printer对象将纸张大小改为A4,毕竟这浪费一点没什么大关系,
当需要打印单据时用Printer对象将纸张大小自定义大小成单据大小,
请问这样可以吗?
谁能给出两功能的代码????
我现在可是在出差现场给客户改啊!!Top
6 楼thinkeasy(Nothing)回复于 2002-06-24 19:49:38 得分 0
使用下面的代码打印,里面有打印纸的设置
With ComDialog1
.CancelError = True
.flags = cdlPDReturnDC + cdlPDNoPageNums + &H100000
Me.ActiveForm.RTBox1.SelLength = 0
.ShowPrinter
If Err <> mscomdlg.cdlCancel Then
Me.ActiveForm.RTBox1.SelPrint .hdc
End If
End WithTop
7 楼thinkeasy(Nothing)回复于 2002-06-24 19:50:12 得分 0
还有Printer的PaperSize属性Top
8 楼lonelystarcn(虫虫)回复于 2002-06-24 19:54:14 得分 0
当要设置纸张大小为A4时
Printer.Papersize=????
当要设置纸张大小为20cm*10cm时
Printer.Papersize=????
Top
9 楼qhzxcz(真想练练降龙十八掌)回复于 2002-06-24 19:56:33 得分 0
将以下代码放在模块中Option Explicit
Public Enum PrinterOrientationConstants
OrientPortrait = 1
OrientLandscape = 2
End Enum
'Printer.PaperSize = vbPRPSA3
Private Type DEVMODE
dmDeviceName As String * 32
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 32
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Type PRINTER_DEFAULTS
pDataType As String
pDevMode As Long
DesiredAccess As Long
End Type
Private Type PRINTER_INFO_2
pServerName As Long
pPrinterName As Long
pShareName As Long
pPortName As Long
pDriverName As Long
pComment As Long
pLocation As Long
pDevMode As Long
pSepFile As Long
pPrintProcessor As Long
pDataType As Long
pParameters As Long
pSecurityDescriptor As Long
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_PAPERSIZE = 3
Private Const DM_IN_BUFFER = 8
Private Const DM_OUT_BUFFER = 2
Private Const DM_ORIENTATION = &H1
Private Const DM_PAPERSIZE = &H2&
Private Const DMPAPER_A3 = 8 ' A3 297 x 420 mm
Private Const DMPAPER_A4 = 9 ' A4 210 x 297 mm
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As _
Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function DocumentProperties Lib "winspool.drv" _
Alias "DocumentPropertiesA" (ByVal hWnd As Long, ByVal hPrinter As Long, _
ByVal pDeviceName As String, pDevModeOutput As Any, pDevModeInput As Any, _
ByVal fMode As Long) As Long
Private Declare Function GetPrinter Lib "winspool.drv" _
Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long
Private Declare Function SetPrinter Lib "winspool.drv" _
Alias "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pPrinter As Any, ByVal Command As Long) As Long
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, ByVal lpPort As String, _
ByVal iIndex As Long, ByVal lpOutput As String, lpDevMode As DEVMODE) As Long
Function SetDefaultPrinterOrientation(ByVal eOrientation As _
PrinterOrientationConstants, ByVal strPaperSize As String) As Boolean
Dim bDevMode() As Byte
Dim bPrinterInfo2() As Byte
Dim hPrinter As Long
Dim lResult As Long
Dim nSize As Long
Dim sPrnName As String
Dim dm As DEVMODE
Dim pd As PRINTER_DEFAULTS
Dim pi2 As PRINTER_INFO_2
' Get device name of default printer
sPrnName = Printer.DeviceName
' PRINTER_ALL_ACCESS required under
' NT, because we're going to call
' SetPrinter
pd.DesiredAccess = PRINTER_ALL_ACCESS
' Get a handle to the printer.
If OpenPrinter(sPrnName, hPrinter, pd) Then
' Get number of bytes requires for
' PRINTER_INFO_2 structure
Call GetPrinter(hPrinter, 2&, 0&, 0&, nSize)
' Create a buffer of the required size
ReDim bPrinterInfo2(1 To nSize) As Byte
' Fill buffer with structure
lResult = GetPrinter(hPrinter, 2, bPrinterInfo2(1), _
nSize, nSize)
' Copy fixed portion of structure
' into VB Type variable
Call CopyMemory(pi2, bPrinterInfo2(1), Len(pi2))
' Get number of bytes requires for
' DEVMODE structure
nSize = DocumentProperties(0&, hPrinter, sPrnName, _
0&, 0&, 0)
' Create a buffer of the required size
ReDim bDevMode(1 To nSize)
' If PRINTER_INFO_2 points to a DEVMODE
' structure, copy it into our buffer
If pi2.pDevMode Then
Call CopyMemory(bDevMode(1), ByVal pi2.pDevMode, Len(dm))
Else
' Otherwise, call DocumentProperties
' to get a DEVMODE structure
Call DocumentProperties(0&, hPrinter, sPrnName, _
bDevMode(1), 0&, DM_OUT_BUFFER)
End If
' Copy fixed portion of structure
' into VB Type variable
Call CopyMemory(dm, bDevMode(1), Len(dm))
With dm
' Set new orientation
Select Case strPaperSize
Case "A3"
.dmPaperSize = DMPAPER_A3
Case "A4"
.dmPaperSize = DMPAPER_A4
End Select
.dmOrientation = eOrientation
.dmFields = DM_ORIENTATION + DM_PAPERSIZE
End With
' Copy our Type back into buffer
Call CopyMemory(bDevMode(1), dm, Len(dm))
' Set new orientation
Call DocumentProperties(0&, hPrinter, sPrnName, _
bDevMode(1), bDevMode(1), DM_IN_BUFFER Or _
DM_OUT_BUFFER)
' Point PRINTER_INFO_2 at our
' modified DEVMODE
pi2.pDevMode = VarPtr(bDevMode(1))
' Set new orientation system-wide
lResult = SetPrinter(hPrinter, 2, pi2, 0&)
' Clean up and exit
Call ClosePrinter(hPrinter)
SetDefaultPrinterOrientation = True
Else
SetDefaultPrinterOrientation = False
End If
End Function
做如此调用:
SetDefaultPrinterOrientation 2, "A4" '其中第一个参数表示横式或者纵式Top
10 楼thinkeasy(Nothing)回复于 2002-06-24 19:57:01 得分 0
VbPRPSLetter 1 信笺, 8 1/2 x 11 英寸。
VbPRPSLetterSmall 2 +A611 小型信笺, 8 1/2 x 11 英寸。
VbPRPSTabloid 3 小型报, 11 x 17 英寸。
VbPRPSLedger 4 分类帐, 17 x 11 英寸。
VbPRPSLegal 5 法律文件, 8 1/2 x 14 英寸。
VbPRPSStatement 6 声明书,5 1/2 x 8 1/2 英寸。
VbPRPSExecutive 7 行政文件,7 1/2 x 10 1/2 英寸。
VbPRPSA3 8 A3, 297 x 420 毫米
VbPRPSA4 9 A4, 210 x 297 毫米
VbPRPSA4Small 10 A4小号, 210 x 297 毫米
VbPRPSA5 11 A5, 148 x 210 毫米
VbPRPSB4 12 B4, 250 x 354 毫米
VbPRPSB5 13 B5, 182 x 257 毫米
VbPRPSFolio 14 对开本, 8 1/2 x 13 英寸。
VbPRPSQuarto 15 四开本, 215 x 275 毫米。
VbPRPS10x14 16 10 x 14 英寸。
VbPRPS11x17 17 11 x 17 英寸。
VbPRPSNote 18 便条,8 1/2 x 11 英寸。
VbPRPSEnv9 19 #9 信封, 3 7/8 x 8 7/8 英寸。
VbPRPSEnv10 20 #10 信封, 4 1/8 x 9 1/2 英寸。
VbPRPSEnv11 21 #11 信封, 4 1/2 x 10 3/8 英寸。
VbPRPSEnv12 22 #12 信封, 4 1/2 x 11 英寸。
VbPRPSEnv14 23 #14 信封, 5 x 11 1/2 英寸。
VbPRPSCSheet 24 C 尺寸工作单
VbPRPSDSheet 25 D 尺寸工作单
VbPRPSESheet 26 E 尺寸工作单
VbPRPSEnvDL 27 DL 型信封, 110 x 220 毫米
VbPRPSEnvC3 29 C3 型信封, 324 x 458 毫米
VbPRPSEnvC4 30 C4 型信封, 229 x 324 毫米
VbPRPSEnvC5 28 C5 型信封, 162 x 229 毫米
VbPRPSEnvC6 31 C6 型信封, 114 x 162 毫米
VbPRPSEnvC65 32 C65 型信封,114 x 229 毫米
VbPRPSEnvB4 33 B4 型信封, 250 x 353 毫米
VbPRPSEnvB5 34 B5 型信封,176 x 250 毫米
VbPRPSEnvB6 35 B6 型信封, 176 x 125 毫米
VbPRPSEnvItaly 36 信封, 110 x 230 毫米
VbPRPSEnvMonarch 37 信封大王, 3 7/8 x 7 1/2 英寸。
VbPRPSEnvPersonal 38 信封, 3 5/8 x 6 1/2 英寸。
VbPRPSFanfoldUS 39 U.S. 标准复写簿, 14 7/8 x 11 英寸。
VbPRPSFanfoldStdGerman 40 德国标准复写簿, 8 1/2 x 12 英寸。
VbPRPSFanfoldLglGerman 41 德国法律复写簿, 8 1/2 x 13 英寸。
VbPRPSUser 256 用户定义
Top
11 楼lonelystarcn(虫虫)回复于 2002-06-24 20:03:49 得分 0
当要设置纸张大小为20cm*10cm时
Printer.Papersize=256
那么如何定义长宽成20cm*10cm呢?Top
12 楼thinkeasy(Nothing)回复于 2002-06-24 20:06:13 得分 0
Printer.Width
printer.HeightTop
13 楼lonelystarcn(虫虫)回复于 2002-06-24 20:08:08 得分 0
因为这是在Printer对象中设置,
但打印却不是用Printer对象打印,不知这样可不可以?Top
14 楼thinkeasy(Nothing)回复于 2002-06-24 20:09:03 得分 0
好像可以吧Top
15 楼lonelystarcn(虫虫)回复于 2002-06-24 20:11:35 得分 0
我明天试试,谢谢大家
谁还有方法的?Top
16 楼qhzxcz(真想练练降龙十八掌)回复于 2002-06-24 20:55:43 得分 0
DEVMODE
The DEVMODE data structure contains information about the device initialization and environment of a printer.
typedef struct _devicemode { // dvmd
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
union {
struct {
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
};
POINTL dmPosition;
};
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmReserved1;
DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
DWORD dmPanningWidth;
DWORD dmPanningHeight;
#endif
#endif /* WINVER >= 0x0400 */
} DEVMODE;
Members
dmDeviceName
Specifies the the "friendly" name of the printer; for example, "PCL/HP LaserJet" in the case of PCL/HP LaserJet®. This string is unique among device drivers. Note that this name may be truncated to fit in the dmDeviceName array.
dmSpecVersion
Specifies the version number of the initialization data specification on which the structure is based.
dmDriverVersion
Specifies the printer driver version number assigned by the printer driver developer.
dmSize
Specifies the size, in bytes, of the DEVMODE structure, not including any private driver-specific data that might follow the structure's public members. Set this member to sizeof(DEVMODE) to indicate the version of the DEVMODE structure being used.
dmDriverExtra
Contains the number of bytes of private driver-data that follow this structure. If a device driver does not use device-specific information, set this member to zero.
dmFields
A set of bit flags that specify whether certain members of the DEVMODE structure have been initialized. If a field is initialized, its corresponding bit flag is set, otherwise the bit flag is clear. A printer driver supports only those DEVMODE structure members that are appropriate for the printer technology.
The following bit flags are defined, and are listed here with the corresponding structure members: Value Structure Member
DM_ORIENTATION dmOrientation
DM_PAPERSIZE dmPaperSize
DM_PAPERLENGTH dmPaperLength
DM_PAPERWIDTH dmPaperWidth
DM_POSITION dmPosition
DM_SCALE dmScale
DM_COPIES dmCopies
DM_DEFAULTSOURCE dmDefaultSource
DM_PRINTQUALITY dmPrintQuality
DM_COLOR dmColor
DM_DUPLEX dmDuplex
DM_YRESOLUTION dmYResolution
DM_TTOPTION dmTTOption
DM_COLLATE dmCollate
DM_FORMNAME dmFormName
DM_LOGPIXELS dmLogPixels
DM_BITSPERPEL dmBitsPerPel
DM_PELSWIDTH dmPelsWidth
DM_PELSHEIGHT dmPelsHeight
DM_DISPLAYFLAGS dmDisplayFlags
DM_DISPLAYFREQUENCY dmDisplayFrequency
DM_ICMMETHOD dmICMMethod
DM_ICMINTENT dmICMIntent
DM_MEDIATYPE dmMediaType
DM_DITHERTYPE dmDitherType
DM_PANNINGWIDTH Windows NT 5.0 and later: dmPanningWidth
DM_PANNINGHEIGHT Windows NT 5.0 and later: dmPanningHeight
dmOrientation
For printer devices only, selects the orientation of the paper. This member can be either DMORIENT_PORTRAIT (1) or DMORIENT_LANDSCAPE (2).
dmPaperSize
For printer devices only, selects the size of the paper to print on. This member can be set to zero if the length and width of the paper are both set by the dmPaperLength and dmPaperWidth members. Otherwise, the dmPaperSize member can be set to one of the following predefined values: Value Meaning
DMPAPER_LETTER Letter, 8 1/2- by 11-inches
DMPAPER_LEGAL Legal, 8 1/2- by 14-inches
DMPAPER_A4 A4 Sheet, 210- by 297-millimeters
DMPAPER_CSHEET C Sheet, 17- by 22-inches
DMPAPER_DSHEET D Sheet, 22- by 34-inches
DMPAPER_ESHEET E Sheet, 34- by 44-inches
DMPAPER_LETTERSMALL Letter Small, 8 1/2- by 11-inches
DMPAPER_TABLOID Tabloid, 11- by 17-inches
DMPAPER_LEDGER Ledger, 17- by 11-inches
DMPAPER_STATEMENT Statement, 5 1/2- by 8 1/2-inches
DMPAPER_EXECUTIVE Executive, 7 1/4- by 10 1/2-inches
DMPAPER_A3 A3 sheet, 297- by 420-millimeters
DMPAPER_A4SMALL A4 small sheet, 210- by 297-millimeters
DMPAPER_A5 A5 sheet, 148- by 210-millimeters
DMPAPER_B4 B4 sheet, 250- by 354-millimeters
DMPAPER_B5 B5 sheet, 182- by 257-millimeter paper
DMPAPER_FOLIO Folio, 8 1/2- by 13-inch paper
DMPAPER_QUARTO Quarto, 215- by 275-millimeter paper
DMPAPER_10X14 10- by 14-inch sheet
DMPAPER_11X17 11- by 17-inch sheet
DMPAPER_NOTE Note, 8 1/2- by 11-inches
DMPAPER_ENV_9 #9 Envelope, 3 7/8- by 8 7/8-inches
DMPAPER_ENV_10 #10 Envelope, 4 1/8- by 9 1/2-inches
DMPAPER_ENV_11 #11 Envelope, 4 1/2- by 10 3/8-inches
DMPAPER_ENV_12 #12 Envelope, 4 3/4- by 11-inches
DMPAPER_ENV_14 #14 Envelope, 5- by 11 1/2-inches
DMPAPER_ENV_DL DL Envelope, 110- by 220-millimeters
DMPAPER_ENV_C5 C5 Envelope, 162- by 229-millimeters
DMPAPER_ENV_C3 C3 Envelope, 324- by 458-millimeters
DMPAPER_ENV_C4 C4 Envelope, 229- by 324-millimeters
DMPAPER_ENV_C6 C6 Envelope, 114- by 162-millimeters
DMPAPER_ENV_C65 C65 Envelope, 114- by 229-millimeters
DMPAPER_ENV_B4 B4 Envelope, 250- by 353-millimeters
DMPAPER_ENV_B5 B5 Envelope, 176- by 250-millimeters
DMPAPER_ENV_B6 B6 Envelope, 176- by 125-millimeters
DMPAPER_ENV_ITALY Italy Envelope, 110- by 230-millimeters
DMPAPER_ENV_MONARCH Monarch Envelope, 3 7/8- by 7 1/2-inches
DMPAPER_ENV_PERSONAL 6 3/4 Envelope, 3 5/8- by 6 1/2-inches
DMPAPER_FANFOLD_US US Std Fanfold, 14 7/8- by 11-inches
DMPAPER_FANFOLD_STD_GERMAN German Std Fanfold, 8 1/2- by 12-inches
DMPAPER_FANFOLD_LGL_GERMAN German Legal Fanfold, 8 1/2- by 13-inches
dmPaperLength
For printer devices only, overrides the length of the paper specified by the dmPaperSize member, either for custom paper sizes or for devices such as dot-matrix printers, which can print on a page of arbitrary length. These values, along with all other values in this structure that specify a physical length, are in tenths of a millimeter.
dmPaperWidth
For printer devices only, overrides the width of the paper specified by the dmPaperSize member.
dmPosition
Windows NT 5.0 and later, Windows 98: For display devices only, a POINTL structure that indicates the positional coordinates of the display device in reference to the desktop area. The primary display device is always located at coordinates (0,0).
Top
17 楼lonelystarcn(虫虫)回复于 2002-06-25 21:28:23 得分 0
嘿嘿.....今天终于用了一个笨方法解决了该问题,
在控制面板的打印机属性中设置纸张大小成单据大小,
然后设置各报表的顶边界为0,底边界为40,标头提到报表标题栏中
这样打印出来的报表即使分页了也看不出来,
谢谢所有这此留言的高手们.
Top




