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 ...
随机推荐
- PHP导出CSV文件
经常会碰到需要从数据库中导出数据到Excel文件,用一些开源的类库,比如PHPExcel,确实比较容易实现,但对大量数据的支持很不好,很容易到达PHP内存使用上限.这里的方法是利用fputcsv写CS ...
- POJ - 2041Unreliable Message
这里的算法非常简单,就是“模拟”,注意编写每个传令官的算法时先分开测试,放在一起就会混淆. POJ - 2041Unreliable Message Time Limit: 1000MS Memory ...
- linux下在eclipse上运行hadoop自带例子wordcount
启动eclipse:打开windows->open perspective->other->map/reduce 可以看到map/reduce开发视图.设置Hadoop locati ...
- SqlSever中Index Seek的匹配规则(一)
我们知道在SqlServer中,索引对查询语句的优化起着巨大的作用,一般来说在执行计划中出现了Index Seek的步骤,我们就认为索引命中了.但是Index Seek中有两个部分是值得我们注意的,我 ...
- SSAS计算列如果是中文名称时,必须要在名字外加中括号
在SSAS中建计算列的时候,如果你给计算列起的是中文名字,一定记住要在名字外加中括号,比如下面这个例子中我们建了一个叫 客服流失数 的计算列 下面图中没有在计算列名称上加中括号这是错误的,因为使用中文 ...
- html规范整体结构
<!DOCTYPE html><html lang="zh"><head> <meta charset="utf-8" ...
- android 项目学习随笔十五(ShareSDK开放平台)
ShareSDK开放平台http://www.mob.com/#/
- std::map 自定义排序
PS:开发中难免会用到快速检索的数据结构-map , 很多时候map自身提供的排序不能满足我们的需要或者不支持我们自定的数据结构的排序,解决办法就是自己实现排序. 这里的小案例是:我们要经用户的has ...
- Ubuntu检测磁盘是否挂载
Ubuntu默认不自动挂载磁盘. 只是学习Bash使用,需优化如使用 # file: mountAll.sh # include color support # a list of variables ...
- Error: 16GU盘变1G,恢复
最近装win10,chromium os之后,删除U盘中的文件,发现不能删除,脑子一热格式化了,发现16G突然变成了1G,这不是坑爹吗,刚买的新U盘呀.立马百度,发现有说是买的被骗了,有的说使用某个软 ...