Page 1 of 1

retrieve excel headers

Posted: Mon Feb 20, 2012 10:25 am
by ukservice
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.

Re: retrieve excel headers

Posted: Wed Feb 22, 2012 4:15 am
by nageswaragunupudi
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?

Re: retrieve excel headers

Posted: Wed Feb 22, 2012 3:24 pm
by ukservice
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

#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() )