GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  D2K
Go To First  |  Previous Question  |  Next Question 
 D2K  |  Question 39 of 71    Print  
How can I acces a field of a existing excel file i.e. cell a1,c8 by using ole and how we use OLE ?

  
Total Answers and Comments: 1 Last Update: November 03, 2006     Asked by: parthaspaul 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: paparao03
 

check the following procedure

PACKAGE RPT2XLS IS
 -- Font style constants
 BOLD constant binary_integer := 1;
 ITALIC constant binary_integer := 2;
 UNDERLINE constant binary_integer := 4;

 -- Horizontal alignment constants
 SUBTYPE xlHAlign IS binary_integer;
 CENTER        CONSTANT xlHAlign := -4108;
 CENTERACROSSSELECTION CONSTANT xlHAlign := 7;
 DISTRIBUTED      CONSTANT xlHAlign := -4117;
 FILL         CONSTANT xlHAlign := 5;
 GENERAL        CONSTANT xlHAlign := 1;
 JUSTIFY        CONSTANT xlHAlign := -4130;
 LEFT         CONSTANT xlHAlign := -4131;
 RIGHT         CONSTANT xlHAlign := -4152;

 PROCEDURE put_cell(ColNo binary_integer, CellValue in varchar2,
           FontName in varchar2 DEFAULT null,
           FontSize in binary_integer DEFAULT null,
           FontStyle in binary_integer DEFAULT null,
           FontColor in binary_integer DEFAULT null,
           BgrColor in binary_integer DEFAULT null,
           Format in varchar2 DEFAULT null,
           Align in xlHAlign DEFAULT null
           );
 PROCEDURE new_line;
 PROCEDURE run;
 PROCEDURE release_memory;

END;

PACKAGE BODY RPT2XLS IS

 TYPE ExcelCell IS RECORD(RowNo binary_integer,
              ColNo binary_integer,
              Val varchar2(2000),
              FontName varchar2(20),
              FontSize binary_integer,
              FontStyle binary_integer,
              FontColor binary_integer,
              BgrColor binary_integer,
               Format varchar2(60),
              Align xlHAlign
              );
 TYPE ExcelCells IS TABLE OF ExcelCell;
 Cell ExcelCells := ExcelCells();

 CurrentRow binary_integer := 1;

 PROCEDURE new_line IS
 BEGIN
  CurrentRow := CurrentRow + 1;
 END;
 

 PROCEDURE put_cell(ColNo binary_integer, CellValue in varchar2,
           FontName in varchar2 DEFAULT null,
           FontSize in binary_integer DEFAULT null,
           FontStyle in binary_integer DEFAULT null,
           FontColor in binary_integer DEFAULT null,
           BgrColor in binary_integer DEFAULT null,
           Format in varchar2 DEFAULT null,
           Align in xlHAlign DEFAULT null
           ) IS
 BEGIN
  Cell.Extend;
  Cell(Cell.Last).RowNo := CurrentRow;
  Cell(Cell.Last).ColNo := ColNo;
  Cell(Cell.Last).Val := CellValue;
  Cell(Cell.Last).FontName := FontName;
  Cell(Cell.Last).FontSize := FontSize;
  Cell(Cell.Last).FontStyle := FontStyle;
  Cell(Cell.Last).FontColor := FontColor;
  Cell(Cell.Last).BgrColor := BgrColor;
  Cell(Cell.Last).Format := Format;
  Cell(Cell.Last).Align := Align;
 END;

 PROCEDURE run IS
  Application OLE2.OBJ_TYPE;
  Workbooks OLE2.OBJ_TYPE;
  Workbook OLE2.OBJ_TYPE;
  Worksheets OLE2.OBJ_TYPE;
  Worksheet OLE2.OBJ_TYPE;
  WorkCell OLE2.OBJ_TYPE;
  WorkColumn OLE2.OBJ_TYPE;
    WorkFont OLE2.OBJ_TYPE;
    WorkInterior OLE2.OBJ_TYPE;
  ArgList OLE2.LIST_TYPE;
 BEGIN

  Application := OLE2.create_obj('Excel.Application');
  OLE2.set_property(Application, 'Visible', 1);
  Workbooks := OLE2.get_obj_property(Application, 'Workbooks');
    Workbook := OLE2.invoke_obj(WorkBooks, 'Add');
  Worksheets := OLE2.get_obj_property(Workbook, 'Worksheets');
  Worksheet := OLE2.get_obj_property(Application, 'ActiveSheet');

  for i in Cell.First .. Cell.Last
  loop
   if Cell(i).Val is not null then
    ArgList := OLE2.create_arglist;
    OLE2.add_arg(ArgList, Cell(i).RowNo);
    ole2.add_arg(ArgList, Cell(i).ColNo);
    WorkCell := OLE2.get_obj_property(Worksheet, 'Cells', ArgList);
    ole2.destroy_arglist(ArgList);
    ole2.set_property(WorkCell, 'Value', Cell(i).Val);
    ole2.set_property(WorkCell, 'NumberFormat', Cell(i).Format);

    if Cell(i).Align is not null then
     ole2.set_property(WorkCell, 'HorizontalAlignment', Cell(i).Align);
    end if;

    WorkFont := OLE2.get_obj_property(WorkCell, 'Font');
    WorkInterior := ole2.Get_Obj_Property(WorkCell, 'Interior');

    if Cell(i).FontName is not null then
     OLE2.set_property(WorkFont, 'Name', Cell(i).FontName);
    end if;
    if Cell(i).FontSize is not null then
     OLE2.set_property(WorkFont, 'Size', Cell(i).FontSize);
    end if;
    if mod(Cell(i).FontStyle, 2) = 1  then
     OLE2.set_property(WorkFont, 'Bold', 1);
    end if;
    if mod(Cell(i).FontStyle, 4) > 2  then
     OLE2.set_property(WorkFont, 'Italic', 1);
    end if;
    if mod(Cell(i).FontStyle, 8) > 4  then
     OLE2.set_property(WorkFont, 'Underline', 2);
    end if;
    if Cell(i).FontColor is not null then
     OLE2.set_property(WorkFont, 'ColorIndex', Cell(i).FontColor);
    end if;
    if Cell(i).BgrColor is not null then
     OLE2.set_property(WorkInterior, 'ColorIndex', Cell(i).BgrColor);
    end if;

    OLE2.release_obj(WorkInterior);
    OLE2.release_obj(WorkFont);
    OLE2.release_obj(WorkCell);
   end if;
  end loop;

  ArgList := ole2.create_arglist;
  ole2.add_arg(ArgList, 'A:Z');
  WorkColumn := ole2.Get_Obj_Property(WorkSheet, 'Columns', ArgList);
  ole2.destroy_arglist(ArgList);
  ole2.invoke(WorkColumn, 'AutoFit');

  OLE2.release_obj(WorkColumn);
  OLE2.release_obj(Worksheet);
  OLE2.release_obj(Worksheets);
  OLE2.release_obj(Workbook);
  OLE2.release_obj(Workbooks);
  OLE2.release_obj(Application);

 END;

 PROCEDURE release_memory IS
 BEGIN
  Cell := ExcelCells();
  SYS.DBMS_SESSION.free_unused_user_memory;
 END;


END;



Above answer was rated as good by the following members:
bc_sumanamara
November 03, 2006 07:06:41   #1  
paparao03 Member Since: November 2006   Contribution: 3    

RE: How can I acces a field of a existing excel file i...

check the following procedure

PACKAGE RPT2XLS IS
-- Font style constants
BOLD constant binary_integer : 1;
ITALIC constant binary_integer : 2;
UNDERLINE constant binary_integer : 4;

-- Horizontal alignment constants
SUBTYPE xlHAlign IS binary_integer;
CENTER CONSTANT xlHAlign : -4108;
CENTERACROSSSELECTION CONSTANT xlHAlign : 7;
DISTRIBUTED CONSTANT xlHAlign : -4117;
FILL CONSTANT xlHAlign : 5;
GENERAL CONSTANT xlHAlign : 1;
JUSTIFY CONSTANT xlHAlign : -4130;
LEFT CONSTANT xlHAlign : -4131;
RIGHT CONSTANT xlHAlign : -4152;

PROCEDURE put_cell(ColNo binary_integer CellValue in varchar2
FontName in varchar2 DEFAULT null
FontSize in binary_integer DEFAULT null
FontStyle in binary_integer DEFAULT null
FontColor in binary_integer DEFAULT null
BgrColor in binary_integer DEFAULT null
Format in varchar2 DEFAULT null
Align in xlHAlign DEFAULT null
);
PROCEDURE new_line;
PROCEDURE run;
PROCEDURE release_memory;

END;

PACKAGE BODY RPT2XLS IS

TYPE ExcelCell IS RECORD(RowNo binary_integer
ColNo binary_integer
Val varchar2(2000)
FontName varchar2(20)
FontSize binary_integer
FontStyle binary_integer
FontColor binary_integer
BgrColor binary_integer
Format varchar2(60)
Align xlHAlign
);
TYPE ExcelCells IS TABLE OF ExcelCell;
Cell ExcelCells : ExcelCells();

CurrentRow binary_integer : 1;

PROCEDURE new_line IS
BEGIN
CurrentRow : CurrentRow + 1;
END;

PROCEDURE put_cell(ColNo binary_integer CellValue in varchar2
FontName in varchar2 DEFAULT null
FontSize in binary_integer DEFAULT null
FontStyle in binary_integer DEFAULT null
FontColor in binary_integer DEFAULT null
BgrColor in binary_integer DEFAULT null
Format in varchar2 DEFAULT null
Align in xlHAlign DEFAULT null
) IS
BEGIN
Cell.Extend;
Cell(Cell.Last).RowNo : CurrentRow;
Cell(Cell.Last).ColNo : ColNo;
Cell(Cell.Last).Val : CellValue;
Cell(Cell.Last).FontName : FontName;
Cell(Cell.Last).FontSize : FontSize;
Cell(Cell.Last).FontStyle : FontStyle;
Cell(Cell.Last).FontColor : FontColor;
Cell(Cell.Last).BgrColor : BgrColor;
Cell(Cell.Last).Format : Format;
Cell(Cell.Last).Align : Align;
END;

PROCEDURE run IS
Application OLE2.OBJ_TYPE;
Workbooks OLE2.OBJ_TYPE;
Workbook OLE2.OBJ_TYPE;
Worksheets OLE2.OBJ_TYPE;
Worksheet OLE2.OBJ_TYPE;
WorkCell OLE2.OBJ_TYPE;
WorkColumn OLE2.OBJ_TYPE;
WorkFont OLE2.OBJ_TYPE;
WorkInterior OLE2.OBJ_TYPE;
ArgList OLE2.LIST_TYPE;
BEGIN

Application : OLE2.create_obj('Excel.Application');
OLE2.set_property(Application 'Visible' 1);
Workbooks : OLE2.get_obj_property(Application 'Workbooks');
Workbook : OLE2.invoke_obj(WorkBooks 'Add');
Worksheets : OLE2.get_obj_property(Workbook 'Worksheets');
Worksheet : OLE2.get_obj_property(Application 'ActiveSheet');

for i in Cell.First .. Cell.Last
loop
if Cell(i).Val is not null then
ArgList : OLE2.create_arglist;
OLE2.add_arg(ArgList Cell(i).RowNo);
ole2.add_arg(ArgList Cell(i).ColNo);
WorkCell : OLE2.get_obj_property(Worksheet 'Cells' ArgList);
ole2.destroy_arglist(ArgList);
ole2.set_property(WorkCell 'Value' Cell(i).Val);
ole2.set_property(WorkCell 'NumberFormat' Cell(i).Format);

if Cell(i).Align is not null then
ole2.set_property(WorkCell 'HorizontalAlignment' Cell(i).Align);
end if;

WorkFont : OLE2.get_obj_property(WorkCell 'Font');
WorkInterior : ole2.Get_Obj_Property(WorkCell 'Interior');

if Cell(i).FontName is not null then
OLE2.set_property(WorkFont 'Name' Cell(i).FontName);
end if;
if Cell(i).FontSize is not null then
OLE2.set_property(WorkFont 'Size' Cell(i).FontSize);
end if;
if mod(Cell(i).FontStyle 2) 1 then
OLE2.set_property(WorkFont 'Bold' 1);
end if;
if mod(Cell(i).FontStyle 4) > 2 then
OLE2.set_property(WorkFont 'Italic' 1);
end if;
if mod(Cell(i).FontStyle 8) > 4 then
OLE2.set_property(WorkFont 'Underline' 2);
end if;
if Cell(i).FontColor is not null then
OLE2.set_property(WorkFont 'ColorIndex' Cell(i).FontColor);
end if;
if Cell(i).BgrColor is not null then
OLE2.set_property(WorkInterior 'ColorIndex' Cell(i).BgrColor);
end if;

OLE2.release_obj(WorkInterior);
OLE2.release_obj(WorkFont);
OLE2.release_obj(WorkCell);
end if;
end loop;

ArgList : ole2.create_arglist;
ole2.add_arg(ArgList 'A:Z');
WorkColumn : ole2.Get_Obj_Property(WorkSheet 'Columns' ArgList);
ole2.destroy_arglist(ArgList);
ole2.invoke(WorkColumn 'AutoFit');

OLE2.release_obj(WorkColumn);
OLE2.release_obj(Worksheet);
OLE2.release_obj(Worksheets);
OLE2.release_obj(Workbook);
OLE2.release_obj(Workbooks);
OLE2.release_obj(Application);

END;

PROCEDURE release_memory IS
BEGIN
Cell : ExcelCells();
SYS.DBMS_SESSION.free_unused_user_memory;
END;


END;


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

Latest Answer : Steps:---------------1) Download rep2excel.exe from the site:-    http://www.brothersoft.com/downloads/html-to-excel.html 2) the from Oracle report save the file as .html3) From command prompt run    ...

Latest Answer : In properties -> Record -> Distance Between Records (Default value is 0). ...
Read Answers (3) | Asked by : Edwin Peterson

1. what r the virtual paths for icon configuration file path defined in a 9i and 10g appln server.2. what r the diff types of component in 9i and 10g appln server.3. which property is used to load the appln in forms configuration.4. what is lock option in reports 9i5. Howmany composite pk or unique keys are passible for single table in oracle 10g6. howmany columns are passible in single table oracle 10g7.which index is best suitable for low coordinality columns. 8. Explain the b-tree index with
Read Answers (1) | Asked by : Edwin Peterson.A

Latest Answer : In this senario Better to  use record group. Using record group we dump the table data at client system level and check the entered data. To achive this you write functions to find dup record under the Trigger When_new_item_instance at the block level. ...
Read Answers (3) | Asked by : nitin kumat

Latest Answer : host('c:myFile.bat'); ...
Read Answers (1) | Asked by : Manjunath Devang

Latest Answer : Using Text_IO package the form data will store in Excel sheet ...
Read Answers (3) | Asked by : kvvsrinivas

Latest Answer : check the following procedurePACKAGE RPT2XLS IS -- Font style constants BOLD constant binary_integer := 1; ITALIC constant binary_integer := 2; UNDERLINE constant binary_integer := 4; -- Horizontal alignment constants SUBTYPE ...

Latest Answer : by using delimiter ...
Read Answers (1) | Asked by : evrajesh

How to convert the oracle reports to excel sheet from oracle form which is already parametrized on the basis of report's parameters?
Read Answers (1) | Asked by : Sonal

i want to retrieve data from table where apply date field from table which likedate = sysdate,so i not got a data , what i doe.g.select date from abc where date = sysdate;this is right or wrong ,plz give 
Latest Answer : select app_date from application where app_date=sysdate;The above query is right but may not fetch record.sysdate defult format is = 'dd/mm/yyyy hh:mi:ss'app_date might format may be = 'dd/mm/yyyy'so please writeselect app_date from applicationwhere trunc(app_date)=trunc(sysdate) ...


 Sponsored Links

 
Related Articles

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Using Oracle XML DB Repository

Using Oracle XML DB Repository Another variation on accessing and manipulating XML content stored in Oracle database is provided by Oracle XML DB repository which is an essential component of Oracle XML DB mosgoogle NOTE Oracle XML DB repository also known as XML repository is a hierarchically organ
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

XML Processing in PHP and Oracle Applications

Processing XML in PHP Oracle Applications As mentioned there are two alternatives when it comes to performing XML processing in your PHP Oracle application You can perform any required XML processing using either PHP s XML extensions or PEAR XML packages or Oracle s XML features mosgoogle In the fol
 

PHP Oracle Web Development

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax is a good starting b
 

Getting Started with Oracle and ODP.NET

ODP NET Developer’ s Guide by Jagadish Chatarji Pulakhandam Sunitha Paruchuri A practical guide for developers working with the Oracle Data Provider for NET and the Oracle Developer Tools for Visual Studio 2005 Application development with ODP NET Dealing with XML DB using ODP NET Oracle
 

PHP Oracle Web Development Review

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books The author is also an expert in open source technologies and SOA Service Oriented Architecture But besides
 

Step by Step Oracle PL-SQL Tutorial

This introductory tutorial to PL SQL will help you to understand the basic concepts of PL SQL Please review the following tutorials and practice the sample SQL Statements on your local Oracle Database Please note that you must learn these basic things before we actually start getting in to Advanced
 

Working with XML in Oracle

Working with XML in Oracle Introduction to XML Extensive markup language is the language which presents data in a human readable form of text The data can be anything from a purchase order or a stock quote or weather radar or a flight schedule it can be represented using XML XML is very similar to H
 

Using XML with Microsoft Excel

Using XML with Microsoft Excel One of the most useful features for a programmer would be Microsoft Excel s capability to support XML schemas which are user defined Though it is not a very prominent feature which can be obviously noted it still exists and is very functional tool In simple English it
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape