FW_ExceltoDbf version in FW 2102

FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Thu Mar 25, 2021 11:33 pm

I made a testing program for future use of ExeltoDbf.

Purpose :

Select random exelfiles ex. many files we retrieve from manufacturers for updating pricelist and all of
them are different in form/headers
The headers will be centralised in the dbf for new update files received from manufacturers and the matching dbf fields
we be linked automatic.
Match the headers with the structure of our dbf that contains ALL priceslist for an import/update prcedure

Issues :

1. I'm doing it wrong with the new FW_exeltodbf (no data in dbf). I think the array that i use is wrong made ?
2. If we only use 3 fields can the function only output these 3 fields to dbf (The program select the ones the user want)

Use of the test :

1 select a random exel file
2 a browse will showup with the oRange and headers. Right click and the headers will be put in a central dbf
here we match the headers with the dbf fields (pulldown in browse)
SELECT A GREEN TAG AND THE CORRESPONDING DBF TAG FOR SELECTION TO USE
3 EXIT THE BROWSE AND CONFIRM THE UPDATE
4 FW_Exeltodbf will do his job and the data should be there. (Not at this moment)

The Sample :

Code: Select all  Expand view  RUN

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   SET DATE BRITISH
   SET CENTURY ON
   SET DELETED ON
   RDDSETDEFAULT( "DBFCDX" )

   maketestdata()  // make dbf's for the test
   readdata()      // select random exel file, Xbrowse shows oRange AND RIGHT CLICK TO PROCEDE
   Browsedata()    // browse result
   close all
return nil

//----------------------------------------------------------------------------//

function Browsedata()

   local oDlg, oFont, oBold, oMono, oGet, oBrw

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Test data view on Fw Version : "+FWVERSION

   @  90,20 XBROWSE oBrw SIZE 900,-20 PIXEL OF oDlg ;
      DATASOURCE "data" ;
      COLUMNS "code", "naam", "prijs","Korting","Brand", "RefLev","Link" ;
      HEADERS "code", "naam", "prijs","Kor", "Brand", "RefLev","Link" ;
      COLSIZES 100,300,80,40,100,100,100 ;
      AUTOSORT LINES NOBORDER

   WITH OBJECT oBrw
      :nMarqueeStyle := MARQSTYLE_HIGHLROWRC
      :bChange       := { || oDlg:Update() }
      :lIncrFilter   := .t.

      :CreateFromCode()
   END
   @ 10,20 BUTTON "Update Master file"   size 80,20 pixel OF oDlg //ACTION UpdateMaster font oFont

   @ 20, 10 SAY TRIM( data->naam ) SIZE 860,30 PIXEL OF oDlg CENTER ;
         FONT oBold UPDATE

   @ 60, 20 SAY "Filter containing all words any where" SIZE 300,20 PIXEL OF oDlg

   @ 60,340 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 540,20 PIXEL OF oDlg ;
      COLOR CLR_HRED,CLR_YELLOW

   @  90,1000 SAY "CODE" SIZE 460,30 PIXEL OF oDlg CENTER ;
      COLOR CLR_BLACK, nRGB( 231, 242, 255 )

   @ 120,1000 GET oGet VAR data->memo SIZE 460,540 PIXEL OF oDlg ;
      MEMO READONLY FONT oMono UPDATE

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oMono, oBold

return nil

//----------------------------------------------------------------------------//


function readdata()
  Local cCurFile, oRange, Cp, oBrw
  local aConvert:={}


  cp := HB_SETCODEPAGE( "UTF8" )  // Depends on region ?

  cCurFile := cGetFile( "Exel file| *.xl*| ", "Please select a file" )

  oRange   := GetExcelRange(  cCurfile , "Sheet1" ,  )  // Sheet1 Tab named and used insite the exel file
  msginfo("When the xbrowse shows up, right click to see the headers")

  xbrowser(oRange) TITLE "RIGHT CLICK ON BROWSE TO ACTIVATE THE HEADER UPDATE : Version : "+FWVERSION;
  SETUP (oBrw:bRclicked := { |r,c,f,o| checkheader(o) })

  If MsgYesNo("Add exeldata to dbf")
     xlsfields->(dbgotop()) // the selected headers from dbf are used
     do while !xlsfields->(eof())  // only when xls header exist and the corresponding dbf file is selected
        if xlsfields->xlsselect .and. xlsfields->select
           AADD(aConvert,{xlsfields->dbffield,xlsfields->xlsfield})
        endif
        xlsfields->(dbskip())
     enddo

     xbrowse(aConvert)
     select data

     //aTest:= { { "CODE", "CUSTOMS CODE" }, { "NAAM", "DESCRIPTION" } }
     //xbrowse(aTest)

     if len(aConvert) > 0  // only when there are fields selected
       FW_ExcelToDBF( oRange, aConvert , .t. )
//       FW_ExcelToDBF( oRange, aTest , .t. )

     endif
  endif
  oRange:WorkSheet:Parent:Close()  // close  exel link

  data->(dbgotop())

return nil


function checkheader(oBrw)
  local aheaders, I , cZoek
  local oDlgH, oFont, oBold, oMono, oGet,oBrwH
  local aFieldnames

  if msgYesNo("Headers of XLS file will be added to database")
    aHeaders := oBrw:cHeaders // Accessing column data returns an array of values.
    for i = 1 to len(aHeaders)
      cZoek = alltrim(upper(aheaders[i]))
      if !xlsfields->(dbseek(cZoek))
        xlsfields->(dbappend())
        xlsfields->xlsfield = cZoek
        xlsfields->xlsselect = .t.
      else
        xlsfields->xlsselect = .t.  //  Fieldnames present will be tagged to see
      endif
    next
  endif

  //xbrowser "xlsfields" TITLE "Conversion Table.  Match de correct Xls to DBF headers" FASTEDIT
  aFieldNames := data->(ARRAY(FCOUNT()))
  data->(aSort(AFIELDS(aFieldNames)))

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlgH SIZE 600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Conversion table"

   @  50,20 XBROWSE oBrwH SIZE -20,-20 PIXEL OF oDlgH ;
      DATASOURCE "xlsfields" ;
      COLUMNS "Xlsselect","xlsfield", "dbffield", "select" ;
      HEADERS "Found","Xlsfield", "Dbffield", "Selected" ;
      COLSIZES 50,250,100,50 ;
      AUTOSORT LINES NOBORDER FASTEDIT

   WITH OBJECT oBrwH
      :nMarqueeStyle := MARQSTYLE_HIGHLROWRC
      :bChange       := { || oDlgH:Update() }
      :lIncrFilter   := .t.
      oBrwH:SetChecks()
      oBrwH:Found:bClrStd := { || IF( xlsfields->xlsselect , { CLR_BLACK,CLR_HGREEN } , { CLR_HRED,CLR_WHITE } ) }

      WITH OBJECT :dbffield
         :nEditType     := EDIT_LISTBOX
         :aEditListTxt  := aFieldnames
      END
      WITH OBJECT :found
         :nEditType     := EDIT_GET
      END
      WITH OBJECT :selected
         :nEditType     := EDIT_GET
      END

      :CreateFromCode()
   END
   //@ 10,20 BUTTON "Start import"   size 150,30 pixel OF oDlgH ACTION UpdateMaster font oFont
   @ 10, 20 SAY "Green = Headers fund in current exel.  Select also the dbf fields to be used. " SIZE 550,20 PIXEL OF oDlgH

   ACTIVATE DIALOG oDlgH CENTERED
   RELEASE FONT oFont, oMono, oBold

return nil


return NIL

function maketestdata()
   local aStruct
   FIELD xlsfield

   // here we create datafile for testing (data is always blank for testing)
   DBCREATE( "data.DBF", { ;
      { "code",      'C', 30, 0 }, ;
      { "naam",      'C',150, 0 }, ;
      { "prijs",     'N',  9, 2 }, ;
      { "Korting",   'N',  6, 2 }, ;
      { "Brand",     'C', 30, 0 }, ;
      { "RefLev",    'C', 30, 0 }, ;
      { "DATE",      'D',  8, 0 }, ;
      { "LINK",      'C',250, 0 }, ;
      { "memo",      'M', 10, 0 }}, ;
      "DBFCDX", .T., "DB" )
      FW_CdxCreate()
      CLOSE DB

    if !file("xlsfields.dbf") // will contain de headers from the xls files and the corresponding dbf header
      aStruct := {}
      AADD(aStruct, { "xlsSelect", "L", 1, 0 }) // Id
      AADD(aStruct, { "xlsfield", "C", 50, 0 }) // Id
      AADD(aStruct, { "dbffield", "C", 15, 0 }) // Id
      AADD(aStruct, { "select",   "L",  1, 0 }) // Id
      DbCreate( "xlsfields.dbf", aStruct)
      use xlsfields NEW
      index on xlsfield tag xlsfield
      close all
    endif

   use xlsfields NEW
   select xlsfields
   replace xlsselect with .f. all  // put False so only the new headers will be selected in the browse

   xlsfields->(dbsetorder("xlsfield"))

   USE data VIA "DBFCDX" NEW
   data->(dbsetorder("code"))
return NIL

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sat Mar 27, 2021 10:03 am

Has anyone use the new FW_ExceltoDbf with changing headers ? With the array parameter...

I retry because i think my array is wrong build. Still empty ))
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby nageswaragunupudi » Sat Mar 27, 2021 4:45 pm

I am going to check it
Regards

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

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sat Mar 27, 2021 9:32 pm

This is a update on the sample program that i think is better to use
The result is still that the function returns no data so there is still something wrong with my code

You can use any exel file (there was none in the samples folder) and link any of het headers to the dbf field in the program.
the result should be all exel rows in the dbf with the corrected/linked header

You can get a error if the exel file has more than 1 tab. I did not yet find a solution to select one of the sheets in exel if there are more than 1

Code: Select all  Expand view  RUN

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   SET DATE BRITISH
   SET CENTURY ON
   SET DELETED ON
   RDDSETDEFAULT( "DBFCDX" )

   if msgYesNo("Would you like to convert a xls file")
    maketestdata()  // make dbf's for the test
    readdata()      // select random exel file, Xbrowse shows oRange AND RIGHT CLICK TO PROCEDE
    Browsedata()    // browse result
    close all
   endif

return nil

//----------------------------------------------------------------------------//

function Browsedata()

   local oDlg, oFont, oBold, oMono, oGet, oBrw

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Test data view on Fw Version : "+FWVERSION

   @  50,20 XBROWSE oBrw SIZE -50,-50 PIXEL OF oDlg ;
      DATASOURCE "data" ;
      COLUMNS "code", "naam", "prijs","Korting","Brand", "RefLev","Link" ;
      HEADERS "code", "naam", "prijs","Kor", "Brand", "RefLev","Link" ;
      COLSIZES 100,300,80,40,100,100,100 ;
      AUTOSORT LINES NOBORDER

   WITH OBJECT oBrw
      :nMarqueeStyle := MARQSTYLE_HIGHLROWRC

      :CreateFromCode()
   END
   @ 20, 20 SAY "This is the result of the conversion" SIZE 300,20 PIXEL OF oDlg


   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oMono, oBold

return nil

//----------------------------------------------------------------------------//


function readdata()
  Local cCurFile, oRange, Cp, oBrw,oDlg
  local aheaders, I , cZoek, oBrw_xls,oBrw_dbf
  local oDlgH, oFont, oBold, oMono, oGet,oBrwH
  local aFieldnames

  aFieldNames := data->(ARRAY(FCOUNT()))
  aadd(aFieldnames,"")
  data->(aSort(AFIELDS(aFieldNames)))


   cp := HB_SETCODEPAGE( "UTF8" )  // Depends on region ?

   cCurFile := cGetFile( "Exel file| *.xl*| ", "Please select a file" )

   oRange   := GetExcelRange(  cCurfile , NIL ,  )  // Sheet1 Tab named and used insite the exel file

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Conversion table: Select the exel headers to match the dbf headers"

   @  60,20 XBROWSE oBrw_xls SIZE 900,-50 PIXEL OF oDlg ;
      DATASOURCE oRange ;
      AUTOCOLS LINES NOBORDER

      WITH OBJECT oBrw_xls
         :nMarqueeStyle := MARQSTYLE_HIGHLROWRC
         :CreateFromCode()
      END

   @  60,950 XBROWSE oBrw_dbf SIZE -50,-50 PIXEL OF oDlg ;
      DATASOURCE "Xlsfields" ;
      COLUMNS "Xlsselect","xlsfield", "dbffield", "select" ;
      HEADERS "Found","Xlsfield", "Dbffield", "Selected" ;
      COLSIZES 50,250,100,50 ;
      LINES NOBORDER FASTEDIT

      WITH OBJECT oBrw_dbf
         :nMarqueeStyle := MARQSTYLE_HIGHLROWRC

         oBrw_dbf:Found:bClrStd := { || IF( xlsfields->xlsselect , { CLR_BLACK,CLR_HGREEN } , { CLR_HRED,CLR_WHITE } ) }
         oBrw_dbf:SetChecks()

         WITH OBJECT :dbffield
            :nEditType     := EDIT_LISTBOX
            :aEditListTxt  := aFieldnames
         END
         WITH OBJECT :found
            :nEditType     := EDIT_GET
         END
         WITH OBJECT :selected
            :nEditType     := EDIT_GET
         END

         :CreateFromCode()
      END


   @ 20, 20 SAY "This Browse shows the data of the exel file" SIZE 600,30 PIXEL OF oDlg
   @ 20, 950 SAY "Select the dbf fields to match to xls fields en tag the checkbox" SIZE 500,30 PIXEL OF oDlg


   //@ 15,960 BUTTON "Test for the oRange Xbrowse"   size 250,30 pixel OF oDlg ACTION Showexel(oBrw_dbf) font oFont
   @ 15,1400 BUTTON "Add Xls data to dbf"   size 150,30 pixel OF oDlg ACTION (add_data(oRange),oDlg:end()) font oFont

   ACTIVATE DIALOG oDlg CENTERED on init (checkheaders(oBrw_xls),oBrw_xls:refresh(),oBrw_dbf:refresh())
   RELEASE FONT oFont, oMono, oBold

  oRange:WorkSheet:Parent:Close()  // close  exel link

  data->(dbgotop())

return nil

function checkheaders(oBrw)
  local aheaders, I , cZoek
   FIELD xlsselect
   aHeaders := oBrw:cHeaders // Accessing column data returns an array of values.
   for i = 1 to len(aHeaders)
     cZoek = alltrim(upper(aheaders[i]))
     if !xlsfields->(dbseek(cZoek))
       xlsfields->(dbappend())
       xlsfields->xlsfield = cZoek
       xlsfields->xlsselect = .t.
     else
       xlsfields->xlsselect = .t.  //  Fieldnames present will be tagged to see
     endif
   next
   select xlsfields
   xlsfields->(dbsetorder(0))
   set filter to xlsselect = .t.
return nil



return NIL

function maketestdata()
   local aStruct
   FIELD xlsfield,xlsselect

   // here we create datafile for testing (data is always blank for testing)
   DBCREATE( "data.DBF", { ;
      { "code",      'C', 30, 0 }, ;
      { "naam",      'C',150, 0 }, ;
      { "prijs",     'N',  9, 2 }, ;
      { "Korting",   'N',  6, 2 }, ;
      { "Brand",     'C', 30, 0 }, ;
      { "RefLev",    'C', 30, 0 }, ;
      { "DATE",      'D',  8, 0 }, ;
      { "LINK",      'C',250, 0 }, ;
      { "memo",      'M', 10, 0 }}, ;
      "DBFCDX", .T., "DB" )
      FW_CdxCreate()
      CLOSE DB

    if !file("xlsfields.dbf") // will contain de headers from the xls files and the corresponding dbf header
      aStruct := {}
      AADD(aStruct, { "xlsSelect", "L", 1, 0 }) // Id
      AADD(aStruct, { "xlsfield", "C", 50, 0 }) // Id
      AADD(aStruct, { "dbffield", "C", 15, 0 }) // Id
      AADD(aStruct, { "select",   "L",  1, 0 }) // Id
      DbCreate( "xlsfields.dbf", aStruct)
      use xlsfields NEW
      index on xlsfield tag xlsfield FOR xlsselect = .t.
      close all
    endif

   use xlsfields NEW
   select xlsfields
   replace xlsselect with .f. all  // put False so only the new headers will be selected in the browse

   xlsfields->(dbsetorder("xlsfield"))

   USE data VIA "DBFCDX" NEW
   data->(dbsetorder("code"))
return NIL

Function add_data(oRange)
  local aConvert:={}, cString

  If MsgYesNo("Add exeldata to dbf")
     xlsfields->(dbgotop()) // the selected headers from dbf are used
     do while !xlsfields->(eof())  // only when xls header exist and the corresponding dbf file is selected
        if xlsfields->xlsselect .and. xlsfields->select
           AADD(aConvert,{alltrim(xlsfields->dbffield),alltrim(xlsfields->xlsfield)})
        endif
        xlsfields->(dbskip())
     enddo
     xlsfields->(dbgotop()) // the selected headers from dbf are used

     xbrowser(aConvert) TITLE "DEBUG : These should become the fields we get from the exel file"
     cString = FW_ValtoExp(aConvert)
     msginfo("DEBUG : Is the array correct 2 dim " +cString)
     select data

     if len(aConvert) > 0  // only when there are fields selected
       FW_ExcelToDBF( oRange, aConvert , .t. )
//       FW_ExcelToDBF( oRange, aTest , .t. )

     endif
  endif
return NIL


function showexel(oBrw)
  local aTest
  oBrw:gotop()
  xbrowser(oBrw)
  do while !oBrw:eof()
    //? oBrw:xlsselect:value
    aadd(aTest,oBrw:xlsfield:value)
    oBrw:godown()
  enddo
  xbrowser(aTest)

return NIL

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sat Mar 27, 2021 11:35 pm

I noticed this :

is working : aConvert = { { "code", "A" }, { "naam", "B" } }
is working : aConvert = { { "code", 1 }, { "naam", 2 } }
is Not working : aConvert = { { "code", "id" }, { "naam", "description" } }

if len(aConvert) > 0 // only when there are fields selected
FW_ExcelToDBF( oRange, aConvert , .t. )
endif

Is Working : if I put in the test program the fieldcolumn in front of the fieldname (the exel file headers)

Exel headers used
1 code
2 description
3 naam

and i create a array with the dbf and only the number of the field from xls, IT WORKS

array used ("dbf-field",position xls)

"code",1
"naam",2
"reflev",3

than it works

This adapted sample works (a workaround to get it working)

Code: Select all  Expand view  RUN

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   SET DATE BRITISH
   SET CENTURY ON
   SET DELETED ON
   RDDSETDEFAULT( "DBFCDX" )

   if msgYesNo("Would you like to convert a xls file")
    maketestdata()  // make dbf's for the test
    readdata()      // select random exel file, Xbrowse shows oRange AND RIGHT CLICK TO PROCEDE
    Browsedata()    // browse result
    close all
   endif

return nil

//----------------------------------------------------------------------------//

function Browsedata()

   local oDlg, oFont, oBold, oMono, oGet, oBrw

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Test data view on Fw Version : "+FWVERSION

   @  50,20 XBROWSE oBrw SIZE -50,-50 PIXEL OF oDlg ;
      DATASOURCE "data" ;
      COLUMNS "code", "naam", "prijs","Korting","Brand", "RefLev","Link" ;
      HEADERS "code", "naam", "prijs","Kor", "Brand", "RefLev","Link" ;
      COLSIZES 100,300,80,40,100,100,100 ;
      AUTOSORT LINES NOBORDER

   WITH OBJECT oBrw
      :nMarqueeStyle := MARQSTYLE_HIGHLROWRC

      :CreateFromCode()
   END
   @ 20, 20 SAY "This is the result of the conversion" SIZE 300,20 PIXEL OF oDlg


   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oMono, oBold

return nil

//----------------------------------------------------------------------------//


function readdata()
  Local cCurFile, oRange, Cp, oBrw,oDlg
  local aheaders, I , cZoek, oBrw_xls,oBrw_dbf
  local oDlgH, oFont, oBold, oMono, oGet,oBrwH
  local aFieldnames

  aFieldNames := data->(ARRAY(FCOUNT()))
  aadd(aFieldnames,"")
  data->(aSort(AFIELDS(aFieldNames)))


   cp := HB_SETCODEPAGE( "UTF8" )  // Depends on region ?

   cCurFile := cGetFile( "Exel file| *.xl*| ", "Please select a file" )

   oRange   := GetExcelRange(  cCurfile , NIL ,  )  // Sheet1 Tab named and used insite the exel file

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
   DEFINE FONT oMono NAME "Lucida Console" SIZE 0,-12

   DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "Conversion table: Select the exel headers to match the dbf headers"

   @  60,20 XBROWSE oBrw_xls SIZE 900,-50 PIXEL OF oDlg ;
      DATASOURCE oRange ;
      AUTOCOLS LINES NOBORDER

      WITH OBJECT oBrw_xls
         :nMarqueeStyle := MARQSTYLE_HIGHLROWRC
         :CreateFromCode()
      END

   @  60,950 XBROWSE oBrw_dbf SIZE -50,-50 PIXEL OF oDlg ;
      DATASOURCE "Xlsfields" ;
      COLUMNS "Xlsselect","xlsfield", "dbffield", "select" ;
      HEADERS "Found","Xlsfield", "Dbffield", "Selected" ;
      COLSIZES 50,250,100,50 ;
      LINES NOBORDER FASTEDIT

      WITH OBJECT oBrw_dbf
         :nMarqueeStyle := MARQSTYLE_HIGHLROWRC

         oBrw_dbf:Found:bClrStd := { || IF( xlsfields->xlsselect , { CLR_BLACK,CLR_HGREEN } , { CLR_HRED,CLR_WHITE } ) }
         oBrw_dbf:SetChecks()

         WITH OBJECT :dbffield
            :nEditType     := EDIT_LISTBOX
            :aEditListTxt  := aFieldnames
         END
         WITH OBJECT :found
            :nEditType     := EDIT_GET
         END
         WITH OBJECT :selected
            :nEditType     := EDIT_GET
         END

         :CreateFromCode()
      END


   @ 20, 20 SAY "This Browse shows the data of the exel file" SIZE 600,30 PIXEL OF oDlg
   @ 20, 950 SAY "Select the dbf fields to match to xls fields en tag the checkbox" SIZE 800,30 PIXEL OF oDlg


   //@ 15,960 BUTTON "Test for the oRange Xbrowse"   size 250,30 pixel OF oDlg ACTION Showexel(oBrw_dbf) font oFont
   @ 15,1400 BUTTON "Add Xls data to dbf"   size 150,30 pixel OF oDlg ACTION (add_data(oRange),oDlg:end()) font oFont

   ACTIVATE DIALOG oDlg CENTERED on init (checkheaders(oBrw_xls),oBrw_xls:refresh(),oBrw_dbf:refresh())
   RELEASE FONT oFont, oMono, oBold

  oRange:WorkSheet:Parent:Close()  // close  exel link

  data->(dbgotop())

return nil

function checkheaders(oBrw)
  local aheaders, I , cZoek
   FIELD xlsselect
   aHeaders := oBrw:cHeaders // Accessing column data returns an array of values.
   for i = 1 to len(aHeaders)
     cZoek = alltrim(upper(aheaders[i]))
     if !xlsfields->(dbseek(cZoek))
       xlsfields->(dbappend())
       xlsfields->xlsfield = padr(str(i,2),2)+" "+cZoek
       xlsfields->xlsselect = .t.
     else
       xlsfields->xlsselect = .t.  //  Fieldnames present will be tagged to see
     endif
   next
   select xlsfields
   xlsfields->(dbsetorder(0))
   set filter to xlsselect = .t.
return nil



return NIL

function maketestdata()
   local aStruct
   FIELD xlsfield,xlsselect

   // here we create datafile for testing (data is always blank for testing)
   DBCREATE( "data.DBF", { ;
      { "code",      'C', 30, 0 }, ;
      { "naam",      'C',150, 0 }, ;
      { "prijs",     'N',  9, 2 }, ;
      { "Korting",   'N',  6, 2 }, ;
      { "Brand",     'C', 30, 0 }, ;
      { "RefLev",    'C', 30, 0 }, ;
      { "DATE",      'D',  8, 0 }, ;
      { "LINK",      'C',250, 0 }, ;
      { "memo",      'M', 10, 0 }}, ;
      "DBFCDX", .T., "DB" )
      FW_CdxCreate()
      CLOSE DB

    if !file("xlsfields.dbf") // will contain de headers from the xls files and the corresponding dbf header
      aStruct := {}
      AADD(aStruct, { "xlsSelect", "L", 1, 0 }) // Id
      AADD(aStruct, { "xlsfield", "C", 50, 0 }) // Id
      AADD(aStruct, { "dbffield", "C", 15, 0 }) // Id
      AADD(aStruct, { "select",   "L",  1, 0 }) // Id
      DbCreate( "xlsfields.dbf", aStruct)
      use xlsfields NEW
      index on xlsfield tag xlsfield FOR xlsselect = .t.
      close all
    endif

   use xlsfields NEW
   select xlsfields
   replace xlsselect with .f. all  // put False so only the new headers will be selected in the browse

   xlsfields->(dbsetorder("xlsfield"))

   USE data VIA "DBFCDX" NEW
   data->(dbsetorder("code"))
return NIL

Function add_data(oRange)
  local aConvert:={}, cString

  If MsgYesNo("Add exeldata to dbf")
     xlsfields->(dbgotop()) // the selected headers from dbf are used
     do while !xlsfields->(eof())  // only when xls header exist and the corresponding dbf file is selected
        if xlsfields->xlsselect .and. xlsfields->select
//           AADD(aConvert,{alltrim(xlsfields->dbffield),alltrim(xlsfields->xlsfield)})
           AADD(aConvert,{alltrim(xlsfields->dbffield),val(left(xlsfields->xlsfield,2))})
        endif
        xlsfields->(dbskip())
     enddo
     xlsfields->(dbgotop()) // the selected headers from dbf are used

     xbrowser(aConvert) TITLE "DEBUG : These should become the fields we get from the exel file"
     cString = FW_ValtoExp(aConvert)
     msginfo("DEBUG : Is the array correct 2 dim " +cString)
     select data

     //aConvert = { { "code", "A" }, { "naam", "B" } }
     //aConvert = { { "code", 1 }, { "naam", 2 } }
     //aConvert = { { "code", "Code" }, { "naam", "naam" } }

     if len(aConvert) > 0  // only when there are fields selected
       FW_ExcelToDBF( oRange, aConvert , .t. )
     endif
  endif
return NIL


function showexel(oBrw)
  local aTest
  oBrw:gotop()
  xbrowser(oBrw)
  do while !oBrw:eof()
    //? oBrw:xlsselect:value
    aadd(aTest,oBrw:xlsfield:value)
    oBrw:godown()
  enddo
  xbrowser(aTest)

return NIL


 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby nageswaragunupudi » Sun Mar 28, 2021 4:14 am

is working : aConvert = { { "code", "A" }, { "naam", "B" } }
is working : aConvert = { { "code", 1 }, { "naam", 2 } }


Good.

is Not working : aConvert = { { "code", "id" }, { "naam", "description" } }


This is also working.

Test program:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   USE CUSTOMER NEW VIA "DBFCDX"

   FW_DbfToExcel( "ID,CITY,STATE,TRIM(FIRST) + ' ' + LAST AS Description",,{ || RECNO() < 11 } )

   CLOSE CUSTOMER

   DBCREATE( "XL2DBF", { { "CODE", "N", 5, 0 }, { "NAAM", "C", 30, 0 } }, ;
             "DBFCDX", .T., "DST" )

   FW_ExcelToDBF( GetExcelRange(), ;
                  { { "code", "id" }, { "naam",   "Description" } }, .T. )

   XBROWSER

return nil
 


Image

The function is working as documented.
Now you need to check your program, why are you not able to get the results in your program.
Regards

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

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sun Mar 28, 2021 2:44 pm

Here i have no data in de name.. no succes

I only changed this in your program

request ....
And a title with the FW version number

Maybe your version is more uptodate than the released one ? Just guessing...

Code: Select all  Expand view  RUN

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   USE CUSTOMER NEW VIA "DBFCDX"

   FW_DbfToExcel( "ID,CITY,STATE,TRIM(FIRST) + ' ' + LAST AS Description",,{ || RECNO() < 11 } )

   CLOSE CUSTOMER

   DBCREATE( "XL2DBF", { { "CODE", "N", 5, 0 }, { "NAAM", "C", 30, 0 } }, ;
             "DBFCDX", .T., "DST" )

   FW_ExcelToDBF( GetExcelRange(), ;
                  { { "code", "id" }, { "naam",   "Description" } }, .T. )

   XBROWSER TITLE FWVERSION

return nil

 


Image
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sun Mar 28, 2021 2:54 pm

I will look now if i have done wrong with the update
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sun Mar 28, 2021 3:00 pm

Second PC it works !! SO i will need todo the install again... Sorry
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby nageswaragunupudi » Sun Mar 28, 2021 3:00 pm

I have just copied the above sample to my fwh folder.
This is not a development version, but what I downloaded from fwh website like all of you and installed on my PC here.
This is my result here.
Image

I am surprised to see why are you getting a different result.

Can you post a screenshot of your excel sheet also?
Regards

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

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Sun Mar 28, 2021 3:16 pm

It is also correct working on my desktop (the same install 21.02)

On my laptop it is not.

I have a issue with the buildh.bat and the location of the dir's. Something on my side !! I keep you posted
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Mon Mar 29, 2021 7:10 am

On my desktop where the program works i have a HARBOUR version

Compiling...
Harbour 3.2.0dev (r1506171039)
Copyright (c) 1999-2015, http://harbour-project.org/
Compiling 'rao.prg' and generating preprocessed output to 'rao.ppo'...
Lines 4997, Functions/Procedures 1
Generating C source output to 'rao.c'... Done.
Embarcadero C++ 7.00 for Win32 Copyright (c) 1993-2015 Embarcadero Technologies, Inc.
rao.c:
Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
* Application successfully built *

On my laptop I have :

Harbour 3.2.0dev (r2008190002)

so a more recent update.

When I copy the older version to the laptop (copy the intire harbour folder) than it works (the name = filled)
and when I copy the newer version to my desktop, it is not complete working (the name = empty)

I do have to update harbour when a newer version of FW comes out ? I think it was a version of Harbour that is included in the FTD-licence

Can anyone confirm this behavior ?
Last edited by Marc Venken on Mon Mar 29, 2021 7:31 am, edited 1 time in total.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby Marc Venken » Mon Mar 29, 2021 7:30 am

Only as a information : (I know that the newest version of harbour will be needed)


When i compile my program (also posted here) with the newer harbour it is working (exept for the blank name issue I started the post for)

With the older version i get compile errors, most likely because we need the newer version for the future upgrades of FWH

Compiling...
Harbour 3.2.0dev (r1506171039)
Copyright (c) 1999-2015, http://harbour-project.org/
Compiling 'tester.prg' and generating preprocessed output to 'tester.ppo'...
6 errors

No code generated.
tester.prg(65) Error E0019 #error 'Invalid instance variable name <->(aSort(AFIELDS(aFieldNames)))>'
tester.prg(65) Error E0030 Syntax error "syntax error at '->'"
tester.prg(65) Warning W0001 Ambiguous reference 'OCLASS'
tester.prg(65) Warning W0001 Ambiguous reference 'NSCOPE'
tester.prg(130) Error E0019 #error 'Invalid instance variable name <->(dbgotop())>'
tester.prg(130) Error E0030 Syntax error "syntax error at '->'"
tester.prg(130) Warning W0001 Ambiguous reference 'OCLASS'
tester.prg(130) Warning W0001 Ambiguous reference 'NSCOPE'
tester.prg(197) Error E0019 #error 'Invalid instance variable name <->(dbsetorder("code"))>'
tester.prg(197) Error E0030 Syntax error "syntax error at '->'"
tester.prg(197) Warning W0001 Ambiguous reference 'OCLASS'
tester.prg(197) Warning W0001 Ambiguous reference 'NSCOPE'
* Compile errors *
Press any key to continue . . .
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1439
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FW_ExceltoDbf version in FW 2102

Postby nageswaragunupudi » Mon Mar 29, 2021 7:47 am

Thanks for the information.
I will also install the new version of Harbour and test.
I will get back with my observations in a day or two.
As of now, it is working with xHarbour also.
Regards

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

Re: FW_ExceltoDbf version in FW 2102

Postby nageswaragunupudi » Mon Mar 29, 2021 12:21 pm

We confirm the issue with new harbour.
It appears they again changed the way ole data is converted into arrays.
We need to carefully study the changes and their effect on ole and ado and then make suitable changes in fwh which work for older and newer versions of harbour and also xharbour.
This may take a few days.
Till then, please stick to the older version of harbour.
Regards

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests