600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 在form中将数据打印到EXCEL文件(单元格合并 改变字体大小等操作)

在form中将数据打印到EXCEL文件(单元格合并 改变字体大小等操作)

时间:2023-09-23 09:18:00

相关推荐

在form中将数据打印到EXCEL文件(单元格合并 改变字体大小等操作)

[标题]在form中将数据打印到EXCEL文件的一些其他问题,请高手帮忙解决!

[发贴人]lizhiqiang

[分类]FORM分类.输出成EXCEL

--------------------------------------------

看过有关 关于数据打印到EXCEL文件的问题,现在的问题是:当数据输出倒Excel后,怎样根据生成数据的行列数,在Excel内自动画出单元格表格(线),怎样根据数据分组情况,进行单元格合并、改变字体大小等操作(通过程序自动实现!)?请高手帮忙解决?

--------------------------------------------

本文整理并转载自:阿莫OracleDeveloper论坛()

第二來源/thread-8835-1-1.html

/******************************************************************/

| Excel文件排版|

/******************************************************************/

--EXCEL排版,配置合并单元格

Procedure SP_ExcelMergeSet(

SheetIN OUT OLE2.obj_type,--工作表对象

P_Row1 IN NUMBER, --起始单元格行坐标

P_Col1 IN NUMBER, --起始单元格列坐标

P_Row2 IN NUMBER, --终止单元格行坐标

P_Col2 IN NUMBER, --终止单元格列坐标

P_Type In Number:=1--是否合并,1:合并;0,不合并

)

Is

CellStart ole2.obj_type;

CellEnd ole2.obj_type;

Rang ole2.Obj_type;

args_End ole2.list_type;

args_Rang ole2.list_type;

args_Start ole2.list_type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--排版-合并单元格

ole2.Set_property(Rang,'MergeCells',1); --设置合并单元格

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

Null;

end;

--EXCEL排版,设置分页线

Procedure SP_ExcelSetPage(

SheetIN OUT OLE2.obj_type,--工作表对象

P_Col IN NUMBER --单元格行坐标

)

Is

--定义单元格对象

Cell ole2.obj_type;

args ole2.list_type;

args_Page ole2.list_type;

--定义分页对象

PageRow Ole2.Obj_Type;

Begin

--配置起始单元格行对象

args:=ole2.create_arglist;

ole2.add_arg(args,P_Col);

PageRow:=ole2.get_obj_property(sheet,'Rows',args);

--设置分页符

ole2.Set_Property(PageRow,'PageBreak',-4135);

--释放对象

ole2.destroy_arglist(args);

ole2.destroy_arglist(args_Page);

ole2.release_obj(Cell);

ole2.release_obj(PageRow);

End;

--EXCEL排版,设置行高

Procedure SP_ExcelSetRowHeight(

Sheet IN OUT OLE2.obj_type,--工作表对象

P_Row1 IN NUMBER, --起始单元格行坐标

P_Row2 IN NUMBER, --终止单元格行坐标

P_RowHeightIn Number --行高

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

Args_Rang Ole2.List_Type;

Rang Ole2.Obj_Type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,1);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(1)||P_Row1||':'||Fn_Get26Change(1)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--单元格排版

ole2.Set_property(Rang,'RowHeight',P_RowHeight); --设置行宽

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

End;

--EXCEL排版,设置列宽

Procedure SP_ExcelSetColumnWeight(

SheetIN OUT OLE2.obj_type,--工作表对象

P_Col1 IN NUMBER, --起始单元格列坐标

P_Col2 IN NUMBER, --终止单元格列坐标

P_ColumnWeight In Number --列宽

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

Args_Rang Ole2.List_Type;

Rang Ole2.Obj_Type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,1);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_col1)||'1'||':'||Fn_Get26Change(P_Col2)||'1');

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--单元格排版

ole2.Set_property(Rang,'ColumnWidth',P_ColumnWeight); --设置列宽

--ole2.Set_property(Rang,'VerticalAlignment',3); --设置垂直对象,居中

--ole2.Set_property(Rang,'HorizontalAlignment',3); --设置水平对齐,居中

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

End;

--EXCEL排版,设置对齐方式

Procedure SP_ExcelSetAlign(

SheetIN OUT OLE2.obj_type,--工作表对象

P_Row1 IN NUMBER, --起始单元格列坐标

P_Col1 IN NUMBER, --起始单元格行坐标

P_Row2 IN NUMBER, --终止单元格列坐标

P_Col2 IN NUMBER, --终止单元格行坐标

P_VerticalAlign In Number:=3, --垂直方向对齐模式,0:两端对齐;1:向上;2:向下;3:居中

P_HorizontalAlign In Number:=3 --水平方向对齐模式,0:两端对齐;1:向左;2:向右;3:居中

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

Args_Rang Ole2.List_Type;

Rang Ole2.Obj_Type;

P_Vertical Number;

P_Horizontal Number;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--单元格排版

If P_VerticalAlign=0 Then

P_Vertical:=-4130; --两端对齐

ElsIf P_VerticalAlign=1 Then

P_Vertical:=-4160; --向左对齐

ElsIf P_VerticalAlign=2 Then

P_Vertical:=-4107; --向右对齐

ElsIf P_VerticalAlign=3 Then

P_Vertical:=-4108; --居中对齐

End If;

If P_HorizontalAlign=0 Then

P_Horizontal:=1; --两端对齐

ElsIf P_HorizontalAlign=1 then

P_Horizontal:=-4131; --向上对齐

ElsIf P_HorizontalAlign=2 Then

P_Horizontal:=-4152; --向下对齐

ElsIf P_HorizontalAlign=3 Then

P_Horizontal:=-4108; --居中对齐

End If;

ole2.Set_property(Rang,'VerticalAlignment',P_Vertical); --设置垂直对象,居中

ole2.Set_property(Rang,'HorizontalAlignment',P_Horizontal); --设置水平对齐,居中

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

End;

--EXCEL排版,设置自动换行

Procedure SP_AutoNewLine(

SheetIN OUT OLE2.obj_type,--工作表对象

P_Row1 IN NUMBER, --起始单元格列坐标

P_Col1 IN NUMBER, --起始单元格行坐标

P_Row2 IN NUMBER, --终止单元格列坐标

P_Col2 IN NUMBER, --终止单元格行坐标

P_Type In Number:=0 --是否自动换行,1:自动换行,0:不自动换行

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

Args_Rang Ole2.List_Type;

Rang Ole2.Obj_Type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

ole2.Set_property(Rang,'WrapText',P_Type); --设置自动换行

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

End;

--EXCEL排版,配置边框线

Procedure SP_ExcelBorderSet_Old(

SheetIN OUT OLE2.obj_type, --工作表对象

P_Row1 IN NUMBER,--起始单元格行坐标

P_Col1 IN NUMBER,--起始单元格列坐标

P_Row2 IN NUMBER,--终止单元格行坐标

P_Col2 IN NUMBER,--终止单元格列坐标

P_Type In Number:=1 --设置是否加边框,1:加边框;0:不加边框

)

Is

--定义单元格对象

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

args_Rang ole2.list_type;

Rang ole2.Obj_type;

--定义边框对象

Args_Border_AllOut Ole2.List_Type; --5

Args_Border_AllIn Ole2.List_Type; --6

Args_Border_OutLeft Ole2.List_Type; --7

Args_Border_OutTop Ole2.List_Type; --8

Args_Border_OutBottom Ole2.List_Type; --9

Args_Border_OutRight Ole2.List_Type; --10

Args_Border_InVertical Ole2.List_Type; --11

Args_Border_InHorizontal Ole2.List_Type; --12

border_AllIn ole2.obj_type;

border_AllOut ole2.obj_type;

border_OutLeft ole2.obj_type;

border_OutTop ole2.obj_type;

border_OutBottom ole2.obj_type;

border_OutRight ole2.obj_type;

border_InVertical ole2.obj_type;

border_InHorizontal ole2.obj_type;

Begin

--配置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--配置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--配置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--配置边框线对象 BORDERline

Args_Border_AllOut:=Ole2.Create_ArgList; --所有外框,用于初始化

Ole2.Add_Arg(Args_Border_AllOut,5);

Args_Border_AllIn :=Ole2.Create_ArgList;--所有内框,用于初始化

Ole2.Add_Arg(Args_Border_AllIn,6);

Args_Border_OutLeft:=Ole2.Create_ArgList;--外框左边

Ole2.Add_Arg(Args_Border_OutLeft,7);

Args_Border_OutTop:=Ole2.Create_ArgList;--外框上边

Ole2.Add_Arg(Args_Border_OutTop,8);

Args_Border_OutBottom:=Ole2.Create_ArgList;--外框下边

Ole2.Add_Arg(Args_Border_OutBottom,9);

Args_Border_OutRight:=Ole2.Create_ArgList;--外框右边

Ole2.Add_Arg(Args_Border_OutRight,10);

Args_Border_InVertical:=Ole2.Create_ArgList;--内框垂直

Ole2.Add_Arg(Args_Border_InVertical,11);

Args_Border_InHorizontal:=Ole2.Create_ArgList;--内框水平垂直

Ole2.Add_Arg(Args_Border_InHorizontal,12);

Border_AllOut:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_AllOut);

Border_AllIn:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_AllIn);

Border_OutLeft:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutLeft);

Border_OutTop:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutTop);

Border_OutBottom:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutBottom);

Border_OutRight:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutRight);

Border_InVertical:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_InVertical);

Border_InHorizontal:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_InHorizontal);

--设置边框线

--初始化边框线

ole2.Set_property(Border_AllIn,'LineStyle',0); --初始化所有内边框线

ole2.Set_property(Border_AllOut,'LineStyle',0); --初始化所有外边框线

If P_Type=1 Then

--设置外框

ole2.Set_property(Border_OutLeft,'LineStyle',1); --设置外边框左边

ole2.Set_property(Border_OutRight,'LineStyle',1); --设置外边框右边

ole2.Set_property(Border_OutTop,'LineStyle',1); --设置外边框上边

ole2.Set_property(Border_OutBottom,'LineStyle',1); --设置外边框下边

--设置内框

If Not P_Col1=P_Col2 Then --垂直单元格不相同,才需要设置内框垂直边框线

ole2.Set_property(Border_InVertical,'LineStyle',1); --设置内框垂直边框线

End If;

If Not P_Row1=P_Row2 Then --水平单元格不相同,才需要设置内框水平边框线

ole2.Set_property(Border_InHorizontal,'LineStyle',1); --设置内框水平边框线

End If;

End If;

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

--定义边框对象

ole2.destroy_arglist(Args_Border_AllOut);

ole2.destroy_arglist(Args_Border_AllIn);

ole2.destroy_arglist(Args_Border_OutLeft);

ole2.destroy_arglist(Args_Border_OutTop);

ole2.destroy_arglist(Args_Border_OutBottom);

ole2.destroy_arglist(Args_Border_OutRight);

ole2.destroy_arglist(Args_Border_InVertical);

ole2.destroy_arglist(Args_Border_InHorizontal);

ole2.release_obj(border_AllIn);

ole2.release_obj(border_AllOut);

ole2.release_obj(border_OutLeft);

ole2.release_obj(border_OutTop);

ole2.release_obj(border_OutBottom);

ole2.release_obj(border_OutRight);

ole2.release_obj(border_InVertical);

ole2.release_obj(border_InHorizontal);

end;

--EXCEL排版,配置边框线(边框线可控制)

Procedure SP_ExcelBorderSet( SheetIN OUT OLE2.obj_type,--工作表对象

P_Row1IN NUMBER, --起始单元格行坐标 P_Col1IN NUMBER, --起始单元格列坐标P_Row2IN NUMBER, --终止单元格行坐标

P_Col2 IN NUMBER, --终止单元格列坐标

P_OutType In Number:=1, --设置外部边框是否加边框线,1:加边框;0:不加边框P_VerticalType In Number:=0, --设置内部纵向是否加边框线,1:加边框;0:不加边框P_HorizontalType In Number:=0 --设置内部横向是否加边框线,1:加边框;0:不加边框 )

Is

--定义单元格对象

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

args_Rang ole2.list_type;

Rang ole2.Obj_type;

--定义边框对象

Args_Border_AllOut Ole2.List_Type; --5

Args_Border_AllIn Ole2.List_Type; --6

Args_Border_OutLeft Ole2.List_Type; --7

Args_Border_OutTop Ole2.List_Type; --8

Args_Border_OutBottom Ole2.List_Type; --9

Args_Border_OutRight Ole2.List_Type; --10

Args_Border_InVertical Ole2.List_Type; --11

Args_Border_InHorizontal Ole2.List_Type; --12

border_AllIn ole2.obj_type;

border_AllOut ole2.obj_type;

border_OutLeft ole2.obj_type;

border_OutTop ole2.obj_type;

border_OutBottom ole2.obj_type;

border_OutRight ole2.obj_type;

border_InVertical ole2.obj_type;

border_InHorizontal ole2.obj_type;

Begin

--配置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--配置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--配置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--配置边框线对象 BORDERline

Args_Border_AllOut:=Ole2.Create_ArgList; --所有外框,用于初始化

Ole2.Add_Arg(Args_Border_AllOut,5);

Args_Border_AllIn :=Ole2.Create_ArgList;--所有内框,用于初始化

Ole2.Add_Arg(Args_Border_AllIn,6);

Args_Border_OutLeft:=Ole2.Create_ArgList;--外框左边

Ole2.Add_Arg(Args_Border_OutLeft,7);

Args_Border_OutTop:=Ole2.Create_ArgList;--外框上边

Ole2.Add_Arg(Args_Border_OutTop,8);

Args_Border_OutBottom:=Ole2.Create_ArgList;--外框下边

Ole2.Add_Arg(Args_Border_OutBottom,9);

Args_Border_OutRight:=Ole2.Create_ArgList;--外框右边

Ole2.Add_Arg(Args_Border_OutRight,10);

Args_Border_InVertical:=Ole2.Create_ArgList;--内框垂直

Ole2.Add_Arg(Args_Border_InVertical,11);

Args_Border_InHorizontal:=Ole2.Create_ArgList;--内框水平垂直

Ole2.Add_Arg(Args_Border_InHorizontal,12);

Border_AllOut:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_AllOut);

Border_AllIn:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_AllIn);

Border_OutLeft:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutLeft);

Border_OutTop:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutTop);

Border_OutBottom:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutBottom);

Border_OutRight:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_OutRight);

Border_InVertical:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_InVertical);

Border_InHorizontal:=ole2.Get_Obj_Property(Rang,'Borders',Args_Border_InHorizontal);

--设置边框线

--初始化边框线

ole2.Set_property(Border_AllIn,'LineStyle',0); --初始化所有内边框线

ole2.Set_property(Border_AllOut,'LineStyle',0); --初始化所有外边框线

If P_OutType=1 Then

--设置外框

ole2.Set_property(Border_OutLeft,'LineStyle',1); --设置外边框左边

ole2.Set_property(Border_OutRight,'LineStyle',1); --设置外边框右边

ole2.Set_property(Border_OutTop,'LineStyle',1); --设置外边框上边

ole2.Set_property(Border_OutBottom,'LineStyle',1); --设置外边框下边

End If;

If P_VerticalType=1 Then

--设置内框纵向

If Not P_Col1=P_Col2 Then --垂直单元格不相同,才需要设置内框垂直边框线

ole2.Set_property(Border_InVertical,'LineStyle',1); --设置内框垂直边框线

End If;

End If;

If P_HorizontalType=1 Then

If Not P_Row1=P_Row2 Then --水平单元格不相同,才需要设置内框水平边框线

ole2.Set_property(Border_InHorizontal,'LineStyle',1); --设置内框水平边框线

End If;

End If;

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

--定义边

ole2.destroy_arglist(Args_Border_AllIn);

ole2.destroy_arglist(Args_Border_OutLeft);

ole2.destroy_arglist(Args_Border_OutTop);

ole2.destroy_arglist(Args_Border_OutBottom);

ole2.destroy_arglist(Args_Border_OutRight);

ole2.destroy_arglist(Args_Border_InVertical);

ole2.destroy_arglist(Args_Border_InHorizontal);

ole2.release_obj(border_AllIn);

ole2.release_obj(border_AllOut);

ole2.release_obj(border_OutLeft);

ole2.release_obj(border_OutTop);

ole2.release_obj(border_OutBottom);

ole2.release_obj(border_OutRight);

ole2.release_obj(border_InVertical);

ole2.release_obj(border_InHorizontal);

end;

--EXCEL排版,配置单元格数值类型

Procedure SP_ExcelCellType(Sheet IN OUT OLE2.obj_type,--工作表对象

P_Row1IN NUMBER, --起始单元格行坐标

P_Col1 IN NUMBER,--起始单元格列坐标

P_Row2IN NUMBER, --终止单元格行坐标

P_Col2 IN NUMBER,--终止单元格列坐标

P_TypeIn Varchar2:='Char'

--设置是否加边框,'char'字符型,'date'日期型,'number999'999数值型,'Number.99' 999.99数值型,'Number9,999.99' 9,999.99数值型

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

Args_Rang Ole2.List_Type;

Rang Ole2.Obj_Type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col1);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--设置单元格类型

if Upper(P_Type)='CHAR' Then

ole2.Set_property(Rang,'NumberFormatLocal','@'); --设置单元格类型(通用型)

ElsIf Upper(P_Type)='DATE' Then

ole2.Set_property(Rang,'NumberFormatLocal','yyyy.mm.dd'); --设置单元格类型(日期型)

ElsIf Upper(P_Type)='NUMBER999' Then

ole2.Set_property(Rang,'NumberFormatLocal','0_ '); --设置单元格类型(数值型999)

ElsIf Upper(P_Type)='NUMBER999.99' Then

ole2.Set_property(Rang,'NumberFormatLocal','0.00_ '); --设置单元格类型(数值型999.99)

ElsIf Upper(P_Type)='NUMBER9,999.99' Then

ole2.Set_property(Rang,'NumberFormatLocal','#,##0.00'); --设置单元格类型(数值型999,999.99)

End If;

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

ole2.release_obj(Rang);

End;

--EXCEL排版,打印设置

Procedure SP_ExcelPrintSet(Sheet IN OUT OLE2.obj_type, --工作表对象

P_PrintTitleRows In VarChar2:='$1/:$1', --每页标题行

P_RightFooter In VarChar2:='&/;P/&N' , --页脚(打印页数/总页数)

P_RightHeader In VarChar2:='&D&T', --设置页眉打印日期和时间

P_LeftMargin In Number:=12, --设置左边距

P_RightMargin In Number:=12, --设置右边距

P_TopMargin In Number:=20, --设置上边距

P_BottomMargin In Number:=20, --设置下边距

P_HeaderMargin In Number:=12, --设置页眉边距

P_FooterMargin In Number:=12, --设置页脚边距

P_CenterHorizontally In Number:=1,--设置水平居中,1:水平居中,0:不水平居中

P_CenterVertically In Number:=1,--设置垂直居中,1:垂直居中,0:水垂直居中

P_Orientation In Number:=1,--设置打印方向,1:纵向打印,2:横向打印

P_ZoomIn Number:=100--设置打印比例

)

Is

PrintSet ole2.obj_type;

Begin

--设置打印设置对象 PrintSet

PrintSet:=ole2.get_obj_property(Sheet,'PageSetup');

--打印设置

ole2.Set_property(PrintSet,'PrintTitleRows',P_PrintTitleRows); --设置每页必须打印的行

ole2.Set_property(PrintSet,'RightFooter',P_RightFooter); --设置页脚打印页数/总页数

ole2.Set_property(PrintSet,'RightHeader',P_RightHeader); --设置页眉打印日期和时间

ole2.Set_property(PrintSet,'LeftMargin',P_LeftMargin); --设置左边距

ole2.Set_property(PrintSet,'RightMargin',P_RightMargin); --设置右边距

ole2.Set_property(PrintSet,'TopMargin',P_TopMargin); --设置上边距

ole2.Set_property(PrintSet,'BottomMargin',P_BottomMargin); --设置下边距

ole2.Set_property(PrintSet,'HeaderMargin',P_HeaderMargin); --设置页眉边距

ole2.Set_property(PrintSet,'FooterMargin',P_FooterMargin); --设置页脚边距

ole2.Set_property(PrintSet,'CenterHorizontally',P_CenterHorizontally); --设置水平居中

ole2.Set_property(PrintSet,'CenterVertically',P_CenterVertically); --设置垂直居中

ole2.Set_property(PrintSet,'Orientation',P_Orientation); --设置打印方向

ole2.Set_property(PrintSet,'Zoom',P_Zoom); --设置打印比例

--释放对象

ole2.release_obj(PrintSet);

end;

--EXCEL排版,字体设置

Procedure SP_ExcelFontSet(SheetIN OUT OLE2.obj_type, --工作表对象

P_Row1 IN NUMBER,--起始单元格行坐标

P_Col1 IN NUMBER, --起始单元格列坐标

P_Row2 IN NUMBER,--终止单元格行坐标

P_Col2 IN NUMBER,--终止单元格列坐标

P_FontName In VarChar2 :='宋体', --字体名称

P_FontSize In Number :=12, --字体大小

P_FontBold In Number :=0, --是否粗体,1:粗体;0:不粗体

P_FontItalic In Number :=0--是否斜体,1:斜体;0:不斜体

)

Is

CellStart ole2.obj_type;

args_Start ole2.list_type;

CellEnd ole2.obj_type;

args_End ole2.list_type;

args_Rang ole2.list_type;

Rang ole2.list_type;

Font Ole2.List_Type;

Begin

--设置起始单元格对象 CellStart

args_Start:=ole2.create_arglist;

ole2.add_arg(args_Start,P_Row1);

ole2.add_arg(args_Start,P_Col2);

CellStart:=ole2.get_obj_property(sheet,'Cells',args_Start);

--设置终止单元格对象 CellEnd

args_End:=ole2.create_arglist;

ole2.add_arg(args_End,P_Row2);

ole2.add_arg(args_End,P_Col2);

CellEnd:=ole2.get_obj_property(sheet,'Cells',args_End);

--设置排版单元格对象 Rang

args_Rang:=ole2.create_arglist;

ole2.add_arg(args_Rang,FN_Get26Change(P_Col1)||P_Row1||':'||Fn_Get26Change(P_Col2)||P_Row2);

--ole2.add_arg_Obj(args_Rang,CellStart);

--ole2.add_arg_Obj(args_Rang,CellEnd);

Rang:=ole2.get_obj_property(sheet,'Range',args_Rang);

--设置字体对象 FONT

Font:=ole2.get_obj_property(Rang,'font');

--设置字体

ole2.Set_property(font,'size',P_FontSize); --设置字体大小

ole2.Set_property(font,'Name',P_FontName); --设置字体名称

ole2.Set_property(font,'Bold',P_FontBold); --设置字体粗体

ole2.Set_property(font,'Italic',P_FontItalic); --设置字体斜体

--释放对象

ole2.destroy_arglist(args_Start);

ole2.destroy_arglist(args_End);

ole2.destroy_arglist(args_Rang);

ole2.release_obj(Font);

ole2.release_obj(Rang);

ole2.release_obj(CellStart);

ole2.release_obj(CellEnd);

end;

/******************************************************************/

| 保存Excel文件|

/******************************************************************/

Procedure SP_SaveExcelFile(Appli IN OUT OLE2.obj_type,

Book IN OUT OLE2.obj_type,

Sheet IN OUT OLE2.obj_type,

FileName IN VARCHAR2

)

IS

args ole2.list_type;

BEGIN

--保存文件

args := ole2.create_arglist;

ole2.add_arg(args, FileName);

ole2.invoke(book, 'Save', args);

ole2.destroy_arglist(args);

END;

/******************************************************************/

|写入数据至Excel文件 |

/******************************************************************/

PROCEDURE SP_WriteExcelFile(SheetIN OUT OLE2.obj_type,

Val IN VARCHAR2,

X IN NUMBER,

Y IN NUMBER

)

IS

Cell ole2.obj_type;

args ole2.list_type;

BEGIN

--设置单元格

args:=ole2.create_arglist;

ole2.add_arg(args,X);

ole2.add_arg(args,Y);

cell:=ole2.get_obj_property(sheet,'cells',args);

ole2.destroy_arglist(args);

ole2.Set_property(cell,'value',Val);

ole2.release_obj(cell);

END;

PROCEDURE SP_SumCells( --列求和

SheetIN OUT OLE2.obj_type,

X IN NUMBER,

Y IN NUMBER,

P_Row1 IN NUMBER,--起始单元格行坐标

P_Row2 IN NUMBER --终止单元格行坐标

)

IS

Cell ole2.obj_type;

args ole2.list_type;

BEGIN

--设置单元格

args:=ole2.create_arglist;

ole2.add_arg(args,X);

ole2.add_arg(args,Y);

cell:=ole2.get_obj_property(sheet,'cells',args);

ole2.destroy_arglist(args);

ole2.Set_property(cell,'value','=SUM('||FN_Get26Change(Y)||P_Row1||':'||FN_Get26Change(Y)||P_Row2||')');

ole2.release_obj(cell);

END;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。