Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel's Autopreview in Gids (anybody?)
Message
De
01/06/2003 23:19:58
Wilfred Chan
Bnp Paribas Hong Kong Branch
Hong Kong, Hong Kong
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00794449
Message ID:
00795064
Vues:
14
Marc,

It's not a generic class, but hope it helps you.
1. Read the data in a temp. table
2. Format the grid in column A,B,C.....then
***  Read row by row in an array and put it in a table
nExcelMaxCol= 52			&& default to 52
nMaxDec	= 6			&& default 6 decimal
nMaxEmptyRow= 10			&& default 10 row


DIMENSION aRecord[nExcelMaxCol]

oExcel= CREATEOBJECT("Excel.Application")
oBook= oExcel.workbooks.open(FULLPATH(File))
oSheet	= oBook.worksheets(1)
lComplete	= .F.
lValue	= .F.
nMaxCol	= 0
nMaxRow	= 0
nEmptyRow	= 0
i = 1
j = 1

DO WHILE NOT lComplete
     j = 1
     lValue = .F.

     DO WHILE Not lComplete AND j <= nExcelMaxCol
	** reading all columns
	oCell	= oSheet.Cells(i,j)
	IF TYPE('oCell.Value') <> 'U'
	    oCell	= oCell.value
	    IF NOT (EMPTY(oCell) OR ISNULL(oCell))
		lValue	= .T.
		nMaxCol	= MAX(nMaxCol,j)
		DO CASE
		CASE TYPE('oCell') = 'T'
		    oCell	= DTOC(TTOD(oCell))
		CASE TYPE('oCell') = 'N'
		    oFormat= oSheet.Cells(i,j).NumberFormat
		    IF '%' $ oFormat	&& if format is Percentage
			oCell	= oCell * 100
		    ENDIF
		    oCell	= TRANS_NUMBER(oCell,nMaxDec)
		ENDCASE
	    ELSE
		oCell	= ''
	    ENDIF
	ELSE
	    oCell	= ''
	ENDIF
	aRecord[j]	= oCell
	j = j + 1				&& next column
    ENDDO
    i = i + 1			&& next row
    IF lValue
	** put all the cells into the temp table
	SELECT TMP_EXCEL
	APPEND BLANK IN TMP_EXCEL
	GATHER FROM aRecord
	nEmptyRow	= 0
	nMaxRow		= i
    ELSE
	nEmptyRow	= nEmptyRow + 1
	IF nEmptyRow > nMaxEmptyRow
	    lComplete	= .T.
	ENDIF
    ENDIF
ENDDO
oBook.Close
oExcel.quit

WITH .gridExcel
	.RecordSource	= 'cExcel'
	.ColumnCount	= nMaxCol
	.Readonly		= .T.
	.DeleteMark	= .F.
	.RowHeight	= 22
	.RecordMark	= .F.
	.SetALL('Width',80,'Column')
ENDWITH
DO CUSTOM_EXCEL_HD WITH gridExcel,nMaxCol
****************

*** format grid, CUSTOM_EXCEL_HD.prg
PARAMETER oGrid,nMaxCol
LOCAL i,sHeader

WITH oGrid
    FOR i = 1 TO nMaxCol
        WITH .Columns(i)
	   .RemoveObject('Header1')
	   .AddObject('Header1', 'Excel_Header')
	   sHeader= ''
	   IF INT(i/26) > 0
		sHeader	= CHR( INT(i/26)+64)
	   ENDIF
	   IF (i%26) = 0
		sHeader	= sHeader + CHR(26+64)
	   ELSE
		sHeader	= sHeader + CHR((i%26)+64)
	   ENDIF
	   .Header1.Caption	= 'Column '+sHeader
	   .Header1.Comment	= sHeader
	   .Header1.ForeColor	= RGB(0, 0, 255)
	   .Text1.Alignment	= 0
	ENDWITH
    NEXT i STEP 1
ENDWITH

DEFINE CLASS Excel_Header AS HEADER
	Name = 'Excel_Header'

	PROC Click
		* Create an Index and use it
		THISFORM.sCurColumn	= THIS.Comment
		THISFORM.UPDATE_COLUMN()
	ENDPROC
ENDDEFINE

****
:) Wilfred

>Would it not be nice to have Autopreview functionality in a grid in a generic way?
>
>Anybody up for the challenge.
>
>I would recommend him for a nobel price.
>
>Kind regards,
>
>Marc
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform