⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printproc2.~pas

📁 公交行业的管理系统
💻 ~PAS
字号:
unit PrintProc2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ComObj, ComCtrls,Printers;
Procedure OpenExcelApp; {call the excel application}
function  DeviceDetect():Integer;
Procedure PrintInit(PathName:String;TableName:String);{Open the right worksheet}
procedure WriteCell(i,j:integer;Value:AnsiString);{write data to the cells}
procedure PrintExcelShow;{show the excel table}
procedure PrintPreview; {preview}
procedure PrintOut; {print}
procedure CloseActiveBook;{Close the active workbook}
procedure CloseExcelApp; {close the excel application}
procedure OpenForEdit(PathName:String;TableName:String);
procedure WriteCellForEdit(i,j:integer;Value:AnsiString);
procedure PrintExcelEdit;
function Converter(conValue:single):String; //一位
function ConverterPercent(constr:string):String;//两位
function SpecDataDiv(sDiv:string;sDivd:String;sAddPar:Integer):string;
procedure ClearData(ListView:TListView;Rows:Integer;RowNum:Integer;Cols:Integer;ColNum:Integer);
{procedure WritePageHeader(LeftHeader,CenterHeader:String);}
implementation
var
ExcelApp,ExcelWorkBook:variant;
ExcelEditApp,ExcelEditWorkBook:variant;
ColumnsNum:Integer;
RowsNum:Integer;
Range:Variant;

Procedure OpenExcelApp;
begin
        ExcelApp:=CreateOleObject('excel.application');
end;

function  DeviceDetect():Integer;
var
pDevice,PDriver,pPort:array[0..255] of char;
hDMode:THandle;
begin
        try
        begin
                Printer.GetPrinter(pDevice,pDriver,pPort,hDMode);
                DeviceDetect:=1;
        end
        except
        begin
                ShowMessage('当前打印机不可用');
                DeviceDetect:=0;
                exit;
        end
        end;

end;

Procedure PrintInit(PathName:String;TableName:String);
var TablePath,DestinationTable:String;
begin
        ExcelApp.workbooks.close;
        TablePath := PathName+'Template\'+TableName + '.xls';
        DestinationTable := PathName + 'Report\'+TableName+ 'Temp.xls';
        CopyFile(PChar(TablePath),PChar(DestinationTable),false);
        ExcelApp.Workbooks.Open(DestinationTable);
        ExcelWorkBook:=ExcelApp.workbooks[1].worksheets[1];
        ExcelWorkBook.activate;
        ExcelApp.visible:=false;

end;

procedure WriteCell(i,j:integer;Value:AnsiString);
begin
        ExcelWorkBook.cells(i,j):=Value;
end;

procedure PrintExcelShow;
begin
        ExcelApp.visible:=true;
end;
procedure PrintPreview;
begin
        ExcelApp.ActiveSheet.PrintPreview;
        ExcelApp.activeworkbook.saved:=true;
end;
procedure PrintOut;
begin
        try
        begin

                ExcelApp.ActiveSheet.PrintOut;
                ExcelApp.activeworkbook.saved:=true;
        end
        except
        begin
                ShowMessage('当前打印机不可用!');
        end
        end;
end;
procedure CloseActiveBook;
begin
        ExcelApp.workbooks.close;
        ExcelApp.visible:=false;

end;
procedure CloseExcelApp;
begin
        excelApp.quit;
end;
function Converter(conValue:single):String;
var
        i:Integer;
        k:char;
        tempstr:string;
        DesStr:String;
        constr:String;
begin
        constr:=FloatToStr(conValue);

        if(pos('.',constr)=0)then
        begin
                DesStr:=ConStr;
                Converter:=DesStr;
        end
        else
        begin
                i:=pos('.',constr);
                k:=constr[i+2];
                DesStr:=copy(constr,0,i+1);
                if(k >='5')then
                begin
                        Converter:=floattostr(strtofloat(DesStr)+0.1);
                end
                else
                begin
                        Converter:=DesStr;
                end;
        end;
end;
function SpecDataDiv(sDiv:string;sDivd:String;sAddPar:Integer):string;
var
        iReturn:String;
        iDiv:single;
        iDivd:single;
        iResult:single;
begin
        iDiv:=StrToFloat(sDiv);
        iDivd:=StrToFloat(sDivd);
        if iDivd=0 then
        begin
                iResult:=0;
        end
        else
        begin
                iResult:=iDiv/iDivd*sAddPar;
        end;

        iReturn:=FloatToStr(iResult);

        if sAddPar=100 then
        begin
                SpecDataDiv:=ConverterPercent(iReturn);
        end
        else
        begin
                SpecDataDiv:=Converter(StrToFloat(iReturn));
        end;

end;

procedure ClearData(ListView:TListView;Rows:Integer;RowNum:Integer;Cols:Integer;ColNum:Integer);
var
        iRows:Integer;
        iRowNum:Integer;
        iCols:Integer;
        iColNum:Integer;
        ClearObject:TListView;
begin
        ClearObject:=ListView;

        for iRowNum := 0 to Rows-1 do
        begin
                for  iColNum:= 0 to Cols-1 do
                begin
                        ClearObject.Items[iRowNum+RowNum].SubItems[iColNum+ColNum]:='';
                end;
        end;
end;

function ConverterPercent(constr:string):String;
var     i:Integer;
        k:char;
        tempstr:string;
        DesStr:String;
begin
        if(pos('.',constr)=0)then
        begin
                DesStr:=ConStr;
                ConverterPercent:=DesStr;
        end
        else
        begin
                i:=pos('.',constr);
                k:=constr[i+3];
                DesStr:=copy(constr,0,i+2);
                if(k >='5')then
                begin
                        ConverterPercent:=floattostr(strtofloat(DesStr)+0.01);
                end
                else
                begin
                        ConverterPercent:=DesStr;
                end;
        end;
end;

procedure OpenForEdit(PathName:String;TableName:String);
var TablePath,DestinationTable:String;
begin
        ExcelEditApp:=CreateOleObject('excel.application');
        ExcelEditApp.workbooks.close;
        TablePath := PathName+'Template\'+TableName + '.xls';
        DestinationTable := PathName + 'Report\'+TableName+ 'Temp.xls';
        CopyFile(PChar(TablePath),PChar(DestinationTable),false);
        ExcelEditApp.Workbooks.Open(DestinationTable);
        ExcelEditWorkBook:=ExcelEditApp.workbooks[1].worksheets[1];
        ExcelEditWorkBook.activate;
        ExcelEditApp.visible:=false;
end;

procedure WriteCellForEdit(i,j:integer;Value:AnsiString);
begin
        ExcelEditWorkBook.cells(i,j):=Value;
end;
procedure PrintExcelEdit;
begin
        ExcelEditApp.visible:=true;
        ExcelEditApp.activeworkbook.saved:=true;
end;
{procedure WritePageHeader(LeftHeader,CenterHeader:String);
var i:Integer;
begin
        try
        begin
                for i:= 1 to ColumnsNum do
                begin
                        ExcelWorkBook.Columns[i].Font.Size := 8;
                        ExcelWorkBook.Columns[i].HorizontalAlignment := 3;
                        ExcelWorkBook.Columns[i].AutoFit;
                        //2 -left, 3 -center, 4 -right;
                end;
                Range := ExcelWorkBook.Range[ExcelWorkBook.Cells[1,1],ExcelWorkBook.Cells[1,ColumnsNum]];
                Range.Merge;
                Range.Characters.Font.Size := 10;
                Range.Value := LeftHeader;
                Range.HorizontalAlignment := 3;

                Range := ExcelWorkBook.Range[ExcelWorkBook.Cells[2,1],ExcelWorkBook.Cells[2,ColumnsNum]];
                Range.Merge;
                Range.Characters.Font.Size := 10;
                Range.Value := LeftHeader;
                Range.HorizontalAlignment := 4;
                Range.Value := Now();

        end
        except
        begin
                ShowMessage('打印机不可用!');
        end
        end
end;}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -