DC_WorkArea2Excel

This forum is for eXpress++ general support.
Message
Author
User avatar
TWolfe
Posts: 60
Joined: Thu Jan 28, 2010 7:34 am

DC_WorkArea2Excel

#1 Post by TWolfe »

I have been trying to get a database to convert to an Excel work sheet using DC_WorkArea2Excel and have not been able to get Character fields to convert properly if they contain strings that look like numbers (ie. 109100004.98 in a dbf field formatted as C 12).

Attached is a small dbf to try. Also the conversion errors out after 20 to 30 records. I am running express version 1.9.254 and X++ version 1.90.355 SL1

Roger, If you could send me the latest version of _dcfunct.prg, perhaps these problems have already been fixed.

Thanks,
Terry
Attachments
TESTDBF.ZIP
A Test File
(2.39 KiB) Downloaded 779 times

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: DC_WorkArea2Excel

#2 Post by Auge_Ohr »

hi,

how does your Field Array Look like ? (5th Parameter of DC_WorkArea2Excel() )

Code: Select all

  cFormat := aFields[i,3]
  IF !Empty(cFormat)
    oSheet:Columns(i):NumberFormat := cFormat
  ENDIF
greetings by OHR
Jimmy

User avatar
TWolfe
Posts: 60
Joined: Thu Jan 28, 2010 7:34 am

Re: DC_WorkArea2Excel

#3 Post by TWolfe »

No field array was used:

DC_WorkArea2Excel('c:\CB.XLS',NIL,.T.,.T.)

Trying to dump the complete .DBF

I also tried it with and without the lAutoFit option. (The documentation states that lAutoFit defaults to .T. however the function actually defaults to .F.)

Terry

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: DC_WorkArea2Excel

#4 Post by Auge_Ohr »

TWolfe wrote:No field array was used:
DC_WorkArea2Excel('c:\CB.XLS',NIL,.T.,.T.)
so try it with Field Array ;)
use 5th Parameter and fill Field Array Element 3 with NIL .

Code: Select all

aFields := { ;
  { 'AREACODE',   'Area Code',     nil}, ;
  { 'EXCHANGE',   'Exchange',      nil}, ;
  { 'NUMBER',     'Number',        nil}, ;
  { 'CITY',       'City',          nil}, ;
  { 'STATE',      'State',         nil}, ;
  { 'COUNTRY',    'Country',       nil}, ;
  { 'TEL_CALLED', 'Number Called', nil}, ;
  { 'DATE',       'Date',          nil}, ;
  { 'TIME',       'Time',          nil} }

cExcelFile := DC_Path(AppName(.t.)) + 'workarea.xls'
DC_WorkArea2Excel(cExcelFile,,,,aFields)
greetings by OHR
Jimmy

User avatar
TWolfe
Posts: 60
Joined: Thu Jan 28, 2010 7:34 am

Re: DC_WorkArea2Excel

#5 Post by TWolfe »

Jimmy,

The fifth parameter of DC_WorkArea2Excel (aFields) is a single-dimension array

{"INDEX_NO",FINE","BANK_DATE"}

I have tried that and it makes no difference.

Terry

User avatar
RDalzell
Posts: 205
Joined: Thu Jan 28, 2010 6:57 am
Location: Alsip, Illinois USA

Re: DC_WorkArea2Excel

#6 Post by RDalzell »

Terry,

I use the attached without issue...

Rick
Attachments
Mvp826.zip
(1.91 KiB) Downloaded 767 times

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DC_WorkArea2Excel

#7 Post by rdonnay »

Terry -

There have been no code changes since 254, but I remember this issue when working with Bobby Drakos, however that was using DC_Excel2WorkArea().
I thought that I had resolved that issue using formatting, but I don't remember. I will look into this.

Roger
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DC_WorkArea2Excel

#8 Post by rdonnay »

When I run the function against your data, I get a runtime error.
This appears to be due to the fact that Excel doesn't like DATE fields in the array.

I made the below change to my code in _DCFUNCT.PRG (DC_WorkArea2Excel()) and it created the XLS file correctly.
I'm going to need to do more research to find out what format is needed for dates.

Code: Select all

nRow += 2
DO WHILE !DC_Eof() .AND. lStatus
  DC_CompleteEvents()
  DC_GetProgress(oProgress,nCount++,nKeyCount)
  FOR i := 1 TO Len(aFields)
    cFieldName := aFields[i,1]
    IF Valtype(&(cFieldName)) == 'D'
      aRow[i] := Dtoc(&(cFieldName))
    ELSE
      aRow[i] := &(cFieldName)
    ENDIF
  NEXT
  AAdd( aData, AClone(aRow) )
  nRow++
  DC_DbSkip(1)
ENDDO
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: DC_WorkArea2Excel

#9 Post by Auge_Ohr »

rdonnay wrote:This appears to be due to the fact that Excel doesn't like DATE fields in the array.
try something like this

Code: Select all

NumberFormat = "d/m/yyyy;@"
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DC_WorkArea2Excel

#10 Post by rdonnay »

Thank you Jimmy.

I will give that a try.
The eXpress train is coming - and it has more cars.

Post Reply