Topic
  • 8 replies
  • Latest Post - ‏2012-10-24T07:19:13Z by adevicq
izzo
izzo
50 Posts

Pinned topic Read data from excel sheet

‏2011-03-24T12:52:07Z |
Hello DOORS users

#include <utils/ole.inc>

Anyone can tell me why I got this error ?

Thank you

#include <utils/ole.inc>

// Open a file in Excel
OleAutoObj openExcelFile(string sFileName, bool bVisible)
{
OleAutoObj oleWorkbooks = null
OleAutoObj oleExcel = null
OleAutoArgs autoArgs = create

oleExcel = oleGetAutoObject("Excel.Application")
if (null oleExcel)
{
oleExcel = oleCreateAutoObject("Excel.Application")
if(null oleExcel)
{
errorBox("Unable to open excel application")
}
olePut (oleExcel, "Visible", bVisible)

// Get workbooks and open file
clear autoArgs
oleGet(oleExcel,"Workbooks", oleWorkbooks)
put(autoArgs,"Filename", sFileName)
oleMethod(oleWorkbooks,"Open",autoArgs)
}
delete autoArgs
return oleExcel
}

//Get the worksheets
OleAutoObj excelGetWorksheet(OleAutoObj oleExcel, int iSheetNumber)
{
OleAutoObj objExcelSheet = null
string sSheetNumber = "Sheet" iSheetNumber ""
OleAutoArgs autoArgs = create
put(autoArgs ,sSheetNumber)
oleGet(oleExcel,"WorkSheets",autoArgs ,objExcelSheet)
delete autoArgs
return objExcelSheet
}

string getCellValue(OleAutoObj objExcelSheet, int iRow, int iCol)
{
string sValue = null
OleAutoObj objCell = null
OleAutoArgs autoArgs = create

put(autoArgs,iRow)
put(autoArgs,iCol)
oleGet(objExcelSheet,"Cells",autoArgs,objCell)//error here
if (!null objCell)
{
// Get the value
oleGet(objCell,"Value",sValue)
}

delete autoArgs
return sValue
}

//close excel
void excelQuit(OleAutoObj oleExcel)
{
oleMethod(oleExcel, "Quit")
oleCloseAutoObject(oleExcel)
}

// Main

string path="C:/User/E376407/SPHUILE.xls"

OleAutoObj oleExcel = openExcelFile(path,true)
OleAutoObj objExcelSheet = excelGetWorksheet(oleExcel,1)

string s = null
s = getCellValue(objExcelSheet,3, 3)
print s "Row 1, Column 1: " s "\n"

//s = getCellValue(objExcelSheet, 2, 3)
print s "Row 2, Column 3: " s "\n"

excelQuit(oleExcel)

-R-E- DXL: <Line:50> null OleAutoObj parameter was passed into argument position 1
Backtrace:
<Line:76>
-I- DXL: execution halted
Updated on 2012-10-24T07:19:13Z at 2012-10-24T07:19:13Z by adevicq
  • adevicq
    adevicq
    154 Posts

    Re: Read data from excel sheet

    ‏2011-03-24T13:15:04Z  

    Hi,

    I have this method to get a pointer to a sheet:
     

    const string cExcelPropertySheets              = "Sheets"
     
    OleAutoObj excelGetSheetOLE( OleAutoObj objExcelWorkbook, int sheetNumber ) {
       OleAutoObj objExcelSheet
       clear( objArgBlock )
       put( objArgBlock, sheetNumber )
       oleResult( oleGet( objExcelWorkbook, cExcelPropertySheets, objArgBlock, objExcelSheet ) )
       return objExcelSheet
    }
    

     


    Regards,
    Alain

     

    Updated on 2014-01-02T18:12:41Z at 2014-01-02T18:12:41Z by iron-man
  • izzo
    izzo
    50 Posts

    Re: Read data from excel sheet

    ‏2011-03-24T13:43:06Z  
    • adevicq
    • ‏2011-03-24T13:15:04Z

    Hi,

    I have this method to get a pointer to a sheet:
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">const string cExcelPropertySheets = "Sheets" OleAutoObj excelGetSheetOLE( OleAutoObj objExcelWorkbook, int sheetNumber ) { OleAutoObj objExcelSheet clear( objArgBlock ) put( objArgBlock, sheetNumber ) oleResult( oleGet( objExcelWorkbook, cExcelPropertySheets, objArgBlock, objExcelSheet ) ) return objExcelSheet } </pre>

     


    Regards,
    Alain

     

    OK Great it works
    The problem was getting the sheet,

    I just got a little question for you :

    oleResult Where oleResult got from, I do no have it in ole.inc
  • adevicq
    adevicq
    154 Posts

    Re: Read data from excel sheet

    ‏2011-03-24T14:02:24Z  
    • izzo
    • ‏2011-03-24T13:43:06Z
    OK Great it works
    The problem was getting the sheet,

    I just got a little question for you :

    oleResult Where oleResult got from, I do no have it in ole.inc

    it seems to be equivalent to

    "checkRes"
    

    in

    utils\ole.inc
    

     


    Alain

     

    Updated on 2014-01-06T22:31:19Z at 2014-01-06T22:31:19Z by iron-man
  • izzo
    izzo
    50 Posts

    Re: Read data from excel sheet

    ‏2011-03-25T13:39:41Z  
    Yup I found it

    Thanks
  • muthurani
    muthurani
    31 Posts

    Re: Read data from excel sheet

    ‏2012-10-22T14:39:14Z  
    • izzo
    • ‏2011-03-25T13:39:41Z
    Yup I found it

    Thanks
    Hello,

    Can you please help me how you include the "excelGetSheetOLE" method in your existing code.

    thanks,

    Regards,
    Rani
  • adevicq
    adevicq
    154 Posts

    Re: Read data from excel sheet

    ‏2012-10-23T07:26:39Z  
    • muthurani
    • ‏2012-10-22T14:39:14Z
    Hello,

    Can you please help me how you include the "excelGetSheetOLE" method in your existing code.

    thanks,

    Regards,
    Rani

    Hi,

    I don't exactly see your point. Here is an example:

    OleAutoObj objSheet
    int nSheet = 3
     
    // Get active workbook
    oleResult( oleGet( objExcelApplication, 
                       cExcelPropertyActiveWorkbook, 
                       objExcelWorkbook ) )
    // Get a opinter to the sheet
    objSheet = excelGetSheetOLE( objExcelWorkbook, nSheet )
     
    if (objSheet == null) {
     
    }
    // etc...
    

     


    Does it answer your question?

    Regards

     

    Updated on 2014-01-02T18:13:54Z at 2014-01-02T18:13:54Z by iron-man
  • muthurani
    muthurani
    31 Posts

    Re: Read data from excel sheet

    ‏2012-10-23T07:53:59Z  
    • adevicq
    • ‏2012-10-23T07:26:39Z

    Hi,

    I don't exactly see your point. Here is an example:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">OleAutoObj objSheet int nSheet = 3 // Get active workbook oleResult( oleGet( objExcelApplication, cExcelPropertyActiveWorkbook, objExcelWorkbook ) ) // Get a opinter to the sheet objSheet = excelGetSheetOLE( objExcelWorkbook, nSheet ) if (objSheet == null) { } // etc... </pre>

     


    Does it answer your question?

    Regards

     

    Hi,

    I am new to DXL. i am having the same requirement for read data from excel. I tried your code and couldnt know how to correct the error which you have mentioned in the thread. Can you please help me. It would be helpful if i get the code.

    Thanks in advance,
    Rani
  • adevicq
    adevicq
    154 Posts

    Re: Read data from excel sheet

    ‏2012-10-24T07:19:13Z  
    • muthurani
    • ‏2012-10-23T07:53:59Z
    Hi,

    I am new to DXL. i am having the same requirement for read data from excel. I tried your code and couldnt know how to correct the error which you have mentioned in the thread. Can you please help me. It would be helpful if i get the code.

    Thanks in advance,
    Rani
    Hi,
    Can you tell me what exactly is your objective and what are the problems you mention?
    Regards,
    Alain