Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to copy a cursor to a spreadsheet
Message
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01175581
Message ID:
01203578
Views:
21
>>
>>Done that yesterday <g> BTW, another little catch here - CHR(13)+CHR(10) in Memo fields should be replaced with CHR(10) to be properly shown in Excel.
>>
>
>I applied your suggestion of changing CHR(13)+CHR(10) to CHR(10) as following:
>
>
>replace MYMEMO with STRTRAN(MYMEMO,CHR(13)+CHR(10),CHR(10))
>
>
>but I still see the square brackets when looking at the data in the spreadsheet. Do you see anything wrong in my use above?
>
>Thank you.

Here we use a special function, which is supposed to do the same:
LPARAMETERS tmMemo
local laLines[1], lnLines, i, lcString

lnLines = ALINES(laLines, m.tmMemo, .t.)
DO CASE 
	CASE lnLines = 0
		lcString = ''
	CASE lnLines = 1
		lcString = laLines[1]
	OTHERWISE 
		lcString = ''
		for i = 1 TO lnLines - 1
			IF NOT EMPTY(laLines[i])
				lcString = lcString + laLines[i] + CHR(10)
			endif	
		ENDFOR 	
		* Add the last line with no line feed.
		lcString = lcString + laLines[lnLines]
ENDCASE

return lcString
Are you sure you're using Memo fields and not char fields? The code bellow works fine for me (I don't see square boxes - Excel 2003):
#DEFINE xlTop -4160
TRY
	oExcel = CREATEOBJECT("Excel.Application")
	WITH oExcel
		.DisplayAlerts = .F.
		.Workbooks.ADD
		WITH .ActiveWorkBook
			.WorkSheets(1).NAME = "Contract Purchase Order"
			VFP2Excel("curSheet", .WorkSheets(1), m.lcFieldNames)
			.WorkSheets(1).UsedRange.SELECT
			oExcel.SELECTION.VerticalAlignment = xlTop
           .WorkSheets(1).Range("A1:A1").Select && to de-select
* .WorkSheets(1).Activate
		ENDWITH
		.ActiveWorkBook.SAVEAS(m.lcExcel)

		.VISIBLE = .T.
	ENDWITH

CATCH TO loError
	lcError =  [Error: ] + TRANSFORM(m.loError.errorno) + CRLF + ;
		[LineNo: ] + TRANSFORM(m.loError.LINENO) + CRLF +  ;
		[Message: ] + m.loError.MESSAGE  + CRLF +  ;
		[Procedure: ] + m.loError.PROCEDURE + CRLF +  ;
		[Details: ] + m.loError.details  + CRLF + ;
		[StackLevel: ] + TRANSFORM(m.loError.stacklevel) + ;
		IIF(_VFP.STARTMODE = 0, CRLF + [LineContents: ] + m.loError.linecontents, '')
	=MESSAGEBOX(m.lcError, MB_ICONEXCLAMATION, "Problem with Excel")
	IF NOT ISNULL(m.oExcel)
		oExcel.VISIBLE = .F.
		oExcel.QUIT
		oExcel = NULL
	ENDIF
ENDTRY
where VFP2Excel is (slight modifications of Cetin's code):
**********************************************************************
* Program....: VFP2EXCEL.PRG
* Version....:
* Author.....: Cetin Basoz
**********************************************************************
FUNCTION VFP2Excel
LPARAMETERS tcCursorName, toSheet, tcFieldNames
tcCursorName = IIF(EMPTY(m.tcCursorName),ALIAS(),m.tcCursorName)
LOCAL loConn AS AdoDB.CONNECTION, loRS AS AdoDB.Recordset, ;
	lcTempRs, lcTemp, oExcel
LOCAL lnFields AS INTEGER, ix AS INTEGER
LOCAL ARRAY laFields[1]
lcTemp = FORCEPATH(SYS(2015)+'.dbf',SYS(2023))
lcTempRs = FORCEPATH(SYS(2015)+'.rst',SYS(2023))
SELECT (m.tcCursorName)
COPY TO (m.lcTemp)
loConn = CREATEOBJECT("Adodb.connection")
loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+SYS(2023)
loConn.OPEN()
loRS = loConn.Execute("select * from " + m.lcTemp)
loRS.SAVE(m.lcTempRs)
loRS.CLOSE
loConn.CLOSE
ERASE (m.lcTemp)
loRS.OPEN(m.lcTempRs)

WITH m.toSheet
	IF NOT EMPTY(m.tcFieldNames)

		lnFields =  ALINES(laFields,m.tcFieldNames,.T.,"|")
		FOR ix = 1 TO m.lnFields
			.Cells(1,m.ix).VALUE = laFields[m.ix]
		NEXT
	ELSE
		FOR ix=1 TO loRS.FIELDS.COUNT
			.Cells(1,m.ix).VALUE = PROPER(loRS.FIELDS(m.ix-1).NAME)
		ENDFOR
	ENDIF

	.RANGE('A2').CopyFromRecordSet(loRS )
	.UsedRange.ROWS(1).FONT.Bold = .T.
	.UsedRange.COLUMNS.AUTOFIT()
ENDWITH
loRS.CLOSE
*loConn.CLOSE

ENDFUNC
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform