Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with columns with long info in Excel
Message
From
08/09/2006 03:38:09
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01152063
Message ID:
01152179
Views:
26
>However, I'm having trouble with dates. This file is created at work, then send to the third party and then additional data is imported. The fields I've created came up correctly in D format or numeric format. But the fields which were filled by the third party are converted wrongly. Date fields have 9 or 7 characters, which is obviously not enough. Is there a way to make sure the fields are created as dates? These dates may be empty for all cells.
>
>Thanks in advance.

Nadya,

You have to format the dates. Since I found I was filling excel sheets from different places, I ended up with one function to put the contents of a field into an excel cell. I call that function for each cell I want to fill

Function is below. You'll have to change the date format to american

You can further enhance it, eg find out the number of decimal places from afields you create a better mask for numeric/double
&& Code like
=afields[FieldArray)

nRow = 2 && after the header
scan all for ...
    nRow = nRow + 1
    for i = 1 to nCols
       =VariableToExcel(eval(FieldArray[m.i, 1]), FieldArray[m.i, 2]), m.xlSheet.Cells[m.nRow,m.i])
    endfor
endscan

*---------------------------------------------------------------------------
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
		with m.CellReference
			.Value = m.x
			
			if( !empty(m.FormatMask) )
				.NumberFormat = m.FormatMask
			endif
		endwith
	endcase
	
	return m.Success
endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform