Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel VBA PEM to get/set column FORMAT
Message
From
03/12/2005 06:00:56
 
 
To
02/12/2005 18:16:21
General information
Forum:
Visual FoxPro
Category:
Third party products
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01074459
Message ID:
01074550
Views:
19
This message has been marked as a message which has helped to the initial question of the thread.
>I've scoured as best I can the Help (and I complain about VFP's Help!!) and simply can't find what PEM is used for this.
>
>Any help much appreciated.
>cheers

Jim,

Let me add some bits and pieces.

(1) based on afields, I set up a Display Mask for excl
        DisplayMaskExcel = ''
	do case
	case inlist(m.Fieldtype, T_CHARACTER)
	
	case inlist(m.Fieldtype, T_NUMERIC, T_DOUBLE)
		DisplayMaskExcel = '#,###.00' + '_);[Red](' + '#,###.00' + ')'
	
	case inlist(m.Fieldtype, T_DATE)
		DisplayMaskExcel = 'dd/mm/yyyy'
	
	case inlist(m.Fieldtype, T_DATETIME)
		DisplayMaskExcel = 'dd/mm/yyyy hh:mm:ss'
	
	case inlist(m.Fieldtype, T_MEMO)
	
	case inlist(m.Fieldtype, T_LOGICAL)
	
	case inlist(m.Fieldtype, T_CURRENCY)
		DisplayMaskExcel = '#,###.00' + '_);[Red](' + '#,###.00' + ')'
	
	case inlist(m.Fieldtype, 'I')
		DisplayMaskExcel = '#,###' + '_);[Red](' + '#,###' + ')'
	
	endcase
(2) I then go through the columns and set the column properties
                nRow = 1
		for i=1 to ncols
			xlSheet.Cells[nRow,i].Value = ['] + h[i,2] && this is the field caption, eg 'Name
			if( !empty(h[i,5]) )
				xlsheet.Columns(i).NumberFormat = h[i,5] && ie DisplayMaskExcel from above
			endif				

			if( !empty(h[i,6]) )  && if you have a char type you want to align right
				xlsheet.Columns(i).HorizontalAlignment = h[i,6] && -4152 && 'xlRight'
			endif
		endfor

		xlSheet.PageSetup.PrintTitleRows = "$1:$1"
(3) to fill the sheet
=afields(af)
scan all while !m.Escaped 
	nRow = m.nRow + 1
		
	for i = 1 to m.ncols
               x = eval(af(i, 1))
		=VariableToExcel(m.x, af[i, 2], m.xlSheet.Cells[m.nRow,m.i])  && below
	endfor
endscan
(4) Finally, you may want to autofit the columns
for i = 1 to ncols
	xlSheet.Columns(i).EntireColumn.AutoFit
endfor
&& VariableToExcel
function VariableToExcel(Content, FieldType, CellReference)
	
	local Success
	Success = TRUE

	local x, FormatMask
	
	FieldType =  iif(empty(m.FieldType), vartype(m.Content), m.FieldType)
	x = null
	
	do case
	case isnull(m.Content)
		
	case inlist(m.FieldType, T_CHARACTER, T_MEMO)
		x = ['] + rtrim(m.Content)
	
	case inlist(m.FieldType, T_DATE)
		x = iif(empty(m.Content), '', '=date(' + transform(dtos(m.Content), '@R 9999,99,99') +  ')')
		FormatMask = 'dd/mm/yyyy'
		
	case inlist(m.FieldType, T_DATETIME)
		x =	;
			iif(empty(m.Content), ;
			'', ;
			 '=date(' + transform(dtos(m.Content), '@R 9999,99,99') +  ')' ;
			+ '+time(' + transform(right(ttoc(m.Content,1),6), '@R 99,99,99') +  ')'  ;
			)
		FormatMask = 'dd/mm/yyyy hh:mm:ss'
		
	case inlist(m.FieldType, T_CURRENCY)
		x = m.Content
		FormatMask = '#,###.00' + '_);[Red](' + '#,###.00' + ')'
	
	case inlist(m.FieldType, 'I')
		x = m.Content
		FormatMask = '#,###' + '_);[Red](' + '#,###' + ')'
	
	case inlist(m.FieldType, T_NUMERIC, T_DOUBLE)
		x = m.Content
		FormatMask = '#,###.00' + '_);[Red](' + '#,###.00' + ')'
	
	case inlist(m.FieldType, T_LOGICAL)
		x = iif(m.Content, 'TRUE', 'FALSE')
	
	endcase
	
	do case
	case (vartype(m.CellReference) <> T_OBJECT)
		Success = FALSE
		
	case isnull(m.x)
		x = ''
	
	otherwise
		CellReference.Value = m.x
		
		if( !empty(m.FormatMask) )
			CellReference.NumberFormat = m.FormatMask
		endif
		
	endcase
	
	return m.Success
endfunc
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform