d e f ....l 1 2 23 4 4 5 total 28 11.......2- copy result at c:\test
LOCAL oExcel,ix,lcCursorName LOCAL ARRAY sheetNames[9] secondCell = DATE()&&second line Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=1; into Cursor crsToExcel1 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=2; into Cursor crsToExcel2 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=3; into Cursor crsToExcel3 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=5 ; into Cursor crsToExcel4 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=6 ; into Cursor crsToExcel5 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=7 ; into Cursor crsToExcel6 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=8 ; into Cursor crsToExcel7 ; nofilter Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=9 ; into Cursor crsToExcel8 ; nofilter ************************* Select *; from ('masd ') WHERE ÑÞã_ÇáãÏíÑ=10 ; into Cursor crsToExcel9 ; nofilter ************************ sheetNames[1] = " ÚãÇä" sheetNames[2] = "ÇáÒÑÞÇÁ" sheetNames[3] = "ÇÑÈÏ" sheetNames[4] = "ÇáßÑß" sheetNames[5] = "ÇáÈáÞÇÁ" sheetNames[6] = "ÇáãÝÑÞ" sheetNames[7] = "ÇáØÝíáÉ" sheetNames[8] = "ãÚÇä" sheetNames[9] = "ãÇÏÈÇ" oExcel = Createobject("Excel.Application") With oExcel .DisplayAlerts = .F. .Workbooks.Add .Visible = .T. With .ActiveWorkBook For ix = 1 To 9 lcCursorName = 'crsToExcel'+Ltrim(Str(m.ix)) firstCell = sheetNames[m.ix] secondCell = DATE()&&second line If .sheets.Count < m.ix .sheets.Add(,.sheets(.sheets.Count)) && Add new sheet ENDIF .WorkSheets(m.ix).Name = sheetNames[m.ix] VFP2Excel(m.lcCursorName, .WorkSheets(m.ix),"A2" ) ENDFOR .WorkSheets(1).Activate ENDWITH Endwith Function VFP2Excel Lparameters tcCursorName, toSheet, tcTargetRange tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName) tcTargetRange = Iif(Empty(m.tcTargetRange),'A1',m.tcTargetRange) Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,; lcTempRs, lcTemp, oExcel 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 toSheet .QueryTables.Add( loRS, .Range(m.tcTargetRange)).Refresh() Endwith loRS.Close Erase (m.lcTempRs)thanks