Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date formats in Excel
Message
De
25/09/2007 10:26:42
 
 
À
25/09/2007 09:16:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01256582
Message ID:
01256654
Vues:
26
>>>Hi
>>>
>>>I am trying to write a copy/paste routine of data in a cursor to Excel. I am using Excel automation to do this; open an instance of Excel, create a new worksheet, copy my cursor to the clipbaord using _VFP.DataToClip(), paste into Excel. Everything is fine but the dates seem to be all messed up with the year appearing first sometimes, then at the end, and other combinations. It would appear that Excel does not recognize the date format being pasted.
>>>
>>>How can I copy to clipbaord and paste into Excel and ensure my dates format correctly in YYYYMMDD format (or other of my choosing)?
>>>
>>>Thanks
>>
>>
>>Jos,
>>
>>To get around the date troubles, convert the dates so that excel will be receiving a function as a field/cell
>>
>>
>>
>>	create cursor ppp (aa c(20), bb c(30), cc i)
>>	insert into ppp values('=date(2007,10,10)', 'jos', 1)
>>	insert into ppp values('=date(2007,11,11)', 'jos', 2)
>>	go top
>>	?_vfp.datatoclip(,,3)
>>         && now paste into excel
>>
>
>Thanks Gregory. This works for me.

Jos,

You're welcome. That's what I use to fill a cell through automation

Before you ask what about DateTime, below a function I use
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' + ')'
		&& FormatMask = '[$€ ]#,###.00' + '_);[Red]([$€ ]' + '#,###.00' + ')'
		&& 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
		with m.CellReference
				.Value = m.x
			
			if( !empty(m.FormatMask) )
				.NumberFormat = m.FormatMask
			endif
		endwith
	endcase
	
	return m.Success
endfunc
*--------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform