retrieve excel headers

retrieve excel headers

Postby ukservice » Mon Feb 20, 2012 10:25 am

Hello,

I am reading an Excel Sheet as follows:

oRange := GetExcelRange( ExePath() + "test.xls" )


@ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ;
DATASOURCE oRange CELL LINES FOOTERS ;
SIZES 80, 80, 80, 80


How can I get Excel´s header names?.

Thanks.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: retrieve excel headers

Postby nageswaragunupudi » Wed Feb 22, 2012 4:15 am

If you know the first row of the range contains headers, you can extract them
oHead := oRange:Rows( 1 )
oHead is a single row object representing the first row of oRange.
May I know what is your exact requirement?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: retrieve excel headers

Postby ukservice » Wed Feb 22, 2012 3:24 pm

Mr. Rao,

Thanks for reply.

I want to xBrowse an Excel and I want to set Excel headers in xBrowse.

This is my code:

Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

function Main()

   local oWnd, oBrw, oBar, oFont, n
   local oRange,  u
   local oSheet
   local nRow, nCol, nRows, nCols, xValue

   local cHeaders := { "A", "B", "C" }
   local nSizes   := { 140, 140, 140, 140, 140, 140, 140, 140, 140, 140 }



   SET DATE ITALIAN
   SET CENTURY ON

   //fwNumFormat( 'E', .t. )



   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12

   DEFINE WINDOW oWnd TITLE "XBrowse Excel Sheet"
   oWnd:SetFont( oFont )

   DEFINE BUTTONBAR oBar OF oWnd 2007
   SET MESSAGE OF oWnd TO '' 2007




   oRange   := GetExcelRange( ExePath() + "test.xls" )


 
      oSheet := oRange:WorkSheet
      nRows := oSheet:UsedRange:Rows:Count()
      nCols := oSheet:UsedRange:Columns:Count()


      For nRow := 1 TO nRows
         FOR nCol := 1 TO nCols
           xValue := oSheet:Cells(nRow,nCol):Value
           if xValue = nil
              oSheet:Cells(nRow,nCol):Value := (" ")  // replace nil with space
           endif
         Next
      Next I






   @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ;
      DATASOURCE oRange CELL LINES FOOTERS ;
      HEADERS cHeaders ;
      SIZES nSizes


   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw





   ACTIVATE WINDOW oWnd MAXIMIZED
   RELEASE FONT oFont
   oRange:WorkSheet:Parent:Close(.F.)   // Not save changes






return nil

function ExePath()
return cFilePath( GetModuleFileName() )
 
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 80 guests