Creating Excel File in Oracle Forms
Below is the example to create an excel file in Oracle Forms.
Pass the Sql query string to the below procedure to generate an Excel file using Ole2 package.
PROCEDURE Create_Excel_File (CSQL Varchar2)
Is
source_cursor Integer;
l_colCnt Number Default 0;
l_descTbl Dbms_sql.desc_tab;
newval1 Varchar2 (4000);
application OLE2.OBJ_TYPE;
workbooks OLE2.OBJ_TYPE;
workbook OLE2.OBJ_TYPE;
worksheets OLE2.OBJ_TYPE;
worksheet OLE2.OBJ_TYPE;
colour OLE2.OBJ_TYPE;
cell OLE2.OBJ_TYPE;
RANGE OLE2.OBJ_TYPE;
range_col OLE2.OBJ_TYPE;
range_row OLE2.OBJ_TYPE;
args OLE2.LIST_TYPE;
rows_processed Number;
row_n Number;
VAL Varchar2 (100);
x Number;
filename Varchar2 (200);
BEGIN
BEGIN
source_cursor := Dbms_Sql.open_Cursor;
Dbms_Sql.parse (source_cursor, cSql, 2);
Dbms_Sql.describe_Columns (c => source_cursor, col_cnt => l_colCnt, desc_t => l_descTbl);
EXCEPTION
When Others
Then
Error_Message (SQLERRM);
RETURN;
END;
application := OLE2.CREATE_OBJ ('Excel.Application');
OLE2.SET_PROPERTY (application, 'Visible', 'False');
workbooks := OLE2.GET_OBJ_PROPERTY (application, 'Workbooks');
workbook := OLE2.GET_OBJ_PROPERTY (workbooks, 'Add');
worksheets := OLE2.GET_OBJ_PROPERTY (workbook, 'Worksheets');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (args, 1);
worksheet := OLE2.GET_OBJ_PROPERTY (worksheets, 'Item', args);
OLE2.DESTROY_ARGLIST (args);
For T In 1 .. l_colCnt
LOOP
BEGIN
Dbms_Sql.define_Column (source_cursor, T, newval1, 4000);
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (args, 1);
OLE2.ADD_ARG (args, T); --Next column
cell := OLE2.GET_OBJ_PROPERTY (worksheet, 'Cells', args);
OLE2.DESTROY_ARGLIST (args);
colour := ole2.get_obj_property (cell, 'Borders');
ole2.set_property (colour, 'ColorIndex', 1);
ole2.Release_obj (colour);
colour := ole2.get_obj_property (cell, 'Interior');
ole2.set_property (colour, 'ColorIndex', 15);
ole2.Release_obj (colour);
OLE2.SET_PROPERTY (cell, 'Value', l_descTbl (T).col_name);
OLE2.Release_obj (cell);
EXCEPTION
When Others
Then
Null;
END;
END LOOP;
Rows_processed := Dbms_Sql.EXECUTE (source_cursor);
row_n := 1;
LOOP
IF Dbms_Sql.fetch_Rows (source_cursor) > 0
Then
For T In 1 .. l_colCnt
LOOP
BEGIN
Dbms_Sql.column_Value (source_cursor, T, newval1);
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (args, row_n + 1);
OLE2.ADD_ARG (args, T); --Next column
cell := OLE2.GET_OBJ_PROPERTY (worksheet, 'Cells', args);
OLE2.DESTROY_ARGLIST (args);
colour := ole2.get_obj_property (cell, 'Borders');
ole2.set_property (colour, 'ColorIndex', 1);
ole2.Release_obj (colour);
OLE2.SET_PROPERTY (cell, 'Value', newval1);
OLE2.Release_obj (cell);
EXCEPTION
When Others
Then
EXIT;
END;
newval1 := Null;
END LOOP;
Else
EXIT;
END IF;
row_n := row_n + 1;
END LOOP;
Dbms_Sql.close_Cursor (source_cursor);
-- Autofit columns
RANGE := OLE2.GET_OBJ_PROPERTY (worksheet, 'UsedRange');
range_col := OLE2.GET_OBJ_PROPERTY (RANGE, 'Columns');
range_row := OLE2.GET_OBJ_PROPERTY (RANGE, 'Rows');
OLE2.INVOKE (range_col, 'AutoFit');
OLE2.INVOKE (range_row, 'AutoFit');
OLE2.Release_obj (RANGE);
OLE2.Release_obj (range_col);
OLE2.Release_obj (range_row);
-- Get filename and path
filename := 'Yourexcel.xls';
-- Save as worksheet
IF Nvl (filename, '0') <> '0'
Then
OLE2.SET_PROPERTY (application, 'Visible', 'True');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (args, filename);
OLE2.INVOKE (worksheet, 'SaveAs', args);
OLE2.DESTROY_ARGLIST (args);
END IF;
-- OLE2.INVOKE( workbook ,'Close');
OLE2.Release_obj (worksheet);
OLE2.Release_obj (worksheets);
OLE2.Release_obj (workbook);
OLE2.Release_obj (workbooks);
OLE2.Release_obj (application);
END;
Download demo form from the following link Generate Excel Report
Creating Excel File in Oracle Forms的更多相关文章
- Formatting Excel File Using Ole2 In Oracle Forms
Below is the some useful commands of Ole2 to format excel file in Oracle Forms.-- Change font size a ...
- Create Hierarchical Tree To Control Records In Oracle Forms
Download Source Code Providing an example form for creating hierarchical trees in Oracle Forms to co ...
- Changing Icon File Of Push Button At Runtime In Oracle Forms 6i
Set Icon_File property in When-Mouse-Enter trigger Suppose you are creating icon based menu system i ...
- Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g
Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...
- Writing Text File From A Tabular Block In Oracle Forms
The example given below for writing text file or CSV using Text_IO package from a tabular block in O ...
- Creating, Stopping, Re-Starting and Deleting a Timer in Oracle Forms
I have written many posts previously on Timers in Oracle Forms like how to change images randomly wi ...
- Creating Custom Login Screen In Oracle Forms 10g
Below is the example plsql unit to validate login credentials and after successful validation open a ...
- Creating Dynamic LOV in Oracle D2k Forms
Dynamic Lov is a good idea for the form where too many Lov requirement is there with different recor ...
- Oracle Forms 10g Tutorial Ebook Download - Oracle Forms Blog
A step by step tutorial for Oracle Forms 10g development. This guide is helpful for freshers in Orac ...
随机推荐
- yii2复选框
Yii2复选框的具体使用方法如下,以商品中的品牌为例在页面显示 第一种方法:使用ActiveForm::checkBoxlist()(这种方法可以把后台获取到的数据都生成复选框),具体使用如下: &l ...
- YZM的全排列
50073081 YZM的全排列 [试题描述] 一天,老师给可怜的YZM出了一道题:写出1~n的全排列.YZM写了一天也没写出来.请你帮帮快跪的YZM,输出1~n的全排列.注:这里n为9 [输入要求] ...
- MyEcplise中关于部署文件不成功的问题
MyEclipse 点击 部署 按钮 无效 正常情况下,当我们点击MyEclipse任务栏上的部署按钮时,会弹出项目部署框,如下图: 但我们有时也会遇到点击部署按钮怎么也弹不出项目部署框的 ...
- T-sql语句中GO的作用及语法【转】
1. 作用: 向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号.2. 语法:一批 Transact-SQL 语句GO如Select 1Select 2Select ...
- javascript 深拷贝
javascript存在两种拷贝:浅拷贝.深拷贝. 它们最大的区别在于引用类型的拷贝上:浅拷贝复制的是引用(指针),深拷贝复制的是里面的数据. 由于以上原因,在下例中 浅拷贝修改的值影响了声明的对象a ...
- git-gui
使用Git.Git GUI和TortoiseGit http://zengrong.net/post/1722.htm 但云桌面不能安装,则TortoiseGit不能使用! 只能想到用totalcmd ...
- 【python cookbook】【数据结构与算法】19.同时对数据做转换和换算
问题:我们需要调用一个换算函数(例如sum().min().max()),但是首先需对数据做转换或者筛选处理 解决方案:非常优雅的方法---在函数参数中使用生成器表达式 例如: # 计算平方和 num ...
- PHPExcel读取excel文件示例
PHPExcel读取excel文件示例PHPExcel最新版官方下载网址:http://phpexcel.codeplex.com/PHPExcel是一个非常方便生成Excel格式文件的类,官方下载包 ...
- Backup: Array in Perl6
Array in Perl6 继承List,而List又继承Iterable,Positional,Cool ARRAY.pop ARRAY.shift ARRAY.push: VALUES ARRA ...
- ECshop中defined('IN_ECS')的实现原理
在PHP中经常看到如下代码 if (!defined('IN_ECS')) { die('Hacking attempt'); } 实现的原因以及原理如下: ecs ...