首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

Grid显示数据或导出EXECL有关问题

2012-08-13 
Grid显示数据或导出EXECL问题GRID直接在一列中直接显示查询数据为Memo,我就将Textbox换成Editbox,然后把此

Grid显示数据或导出EXECL问题
GRID直接在一列中直接显示查询数据为Memo,我就将Textbox换成Editbox,然后把此列Column的Sparse设为 .F.,成功显示了查询数据,但是导出保存到EXECL时,则无此列数据

现在求如何能成功的显示出查询数据和导出保存

查询代码如下:

SQL code
lnHandle=SQLConnect(lcODBCName,lcDBUser,lcDBPasswd)If lnHandle>0 &&连接成功**从库里获得数据)    lnReturn=SQLExec(lnHandle,"SELECT A.GZ_BH,GZ_MC,STUFF(STUFF(G_ZHH, CHARINDEX(DQDM, G_ZHH, 5), 0, '-'),CHARINDEX(DQDM, G_ZHH, 5) + LEN(DQDM) + 1, 0, '-') G_ZHH,G_DZKH,G_YUS,G_DJSJ,G_ZT,GZ_DZ,GZ_DH FROM GP_G_XXB A LEFT JOIN GP_GZ_XXB B ON A.gz_bh=B.gz_bh ORDER BY a.gz_bh,G_ZHH","CursorC")    If lnReturn>0 &&运行成功        *显示        thisform.grid1.recordsource=null        thisform.grid1.recordsource='CursorC'        thisform.grid1.refresh    Else &&失败        &&出错处理    EndIfElse &&连接失败    MessageBox("连接SQL SERVER失败",16,"BUFFER")EndIf

STUFF(STUFF(G_ZHH, CHARINDEX(DQDM, G_ZHH, 5), 0, '-'),CHARINDEX(DQDM, G_ZHH, 5) + LEN(DQDM) + 1, 0, '-') G_ZHH为问题的数据


导出EXECL代码如下:不能导出保存上面代码部分的数据
SQL code
*设置EXCEL文件路径与文件名sc=putfile("文件名:","查询结果","xls")If !empty(allt(sc))    *将查询结果拷贝到EXCEL    Copy to allt(sc) TYPE XL5    oExcel=CREATEOBJECT("Excel.Application")    *显示该EXCEL文件    oExcel.WorkBooks.Open(allt(sc))    oExcel.Visible=.T.Endif


主程序文件代码:
SQL code
Set Date YMDSET CENTURY ON  && 显示的日期格式中,用四位数字表示年。SET HOURS TO 24 && 显示24小时时间格式。SET DATE ANSI   && 指定日期表达式和日期时间表达式的显示格式。SET MARK TO "-" && 指定显示日期表达式时所使用的分隔符。.........................*打开连接表单set   talk   off DO FORM mainform.scxREAD EVENTS*——结束事件循环后退出Visual FoxProQUIT



[解决办法]
Memo应该为备注内容吧。用 Copy to allt(sc) TYPE XL5 复制的内容不包括备注内容

[解决办法]
SQL code
*---该代码来源于网络CLOSE DATABASES ALLSET DATE YMDSET CENTURY ONcDbfFile = GETFILE("dbf")IF EMPTY(cDbfFile)   RETURNENDIFUSE (cDbfFile) ALIAS FoxTable IN 0IF NOT USED("FoxTable")   =MESSAGEBOX("打开表失败,程序将中止!", 16, "Error")   RETURNENDIFcExcelFile = PUTFILE("保存为(&N):",JUSTSTEM(cDbfFile)+".xls","xls")IF EMPTY(cExcelFile)   CLOSE DATABASES ALL   RETURNENDIFSELECT FoxTableoExcelSheet = GETOBJECT("","Excel.Sheet") && 产生Excel对象IF NOT TYPE("oExcelSheet") = "O"   =MESSAGEBOX("Excel对象创建失败,程序将中止!", 16, "Error")   RETURNENDIFoExcelApp = oExcelSheet.ApplicationoExcelApp.Workbooks.Add()oExcelApp.ActiveWindow.WindowState=2oSheet = oExcelApp.ActiveSheetnFldCount = AFIELDS(aFldList, "FoxTable")FOR i = 1 TO nFldCount    oSheet.Cells(1,i).Value = aFldList[i, 1]ENDFORcRecc = STR(RECCOUNT("FoxTable"))SCAN   WAIT WINDOW ALLTRIM(STR(RECNO())) + "/" + cRecc NOWAIT   FOR i = 1 TO nFldCount       vValue = .NULL.       IF AT(aFldList[i, 2], "CDLMNFIBYT") = 0          LOOP       ENDIF       cFldName = aFldList[i, 1]       vValue = EVALUATE(cFldName)       DO CASE          CASE aFldList[i, 2] = "C" && 字符/字符串               vValue = TRIM(vValue)          CASE aFldList[i, 2] = "D" && 日期               vValue = DTOC(vValue)          CASE aFldList[i, 2] = "T" && 日期时间               vValue = TTOC(vValue)          CASE INLIST(aFldList[i, 2], "N", "F", "I", "B", "Y") && 数值          CASE aFldList[i, 2] = "L" && 逻辑          CASE aFldList[i, 2] = "M" && 备注型          OTHERWISE          vValue = .NULL.       ENDCASE       IF VARTYPE(vValue) = "C" AND EMPTY(vValue)          LOOP       ENDIF       IF NOT ISNULL(vValue)          oSheet.Cells(RECNO("FoxTable")+1, i).Value = vValue       ENDIF   ENDFORENDSCANcChrStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"FOR i = 1 TO nFldCount    cColumn = SUBSTR(cChrStr, INT((i-1)/26), 1) + SUBSTR(cChrStr, IIF(MOD(i, 26)= 0, 26, MOD(i, 26)) , 1)    oSheet.Columns(cColumn + ":" + cColumn).ColumnWidth = 12    IF aFldList[i, 2] = "M"       oSheet.Columns(cColumn + ":" + cColumn).WrapText = .F.    ENDIFENDFORoExcelApp.ActiveWorkbook.SaveAs(cExcelFile)oExcelApp.ActiveWorkbook.Close(.F.)oExcelApp.ActiveWorkbook.Close(.F.)oExcelApp.QuitoExcelSheet = .NULL.oExcelApp = .NULL.WAIT CLEAR=MESSAGEBOX("转换完毕!", 64, "OK")CLOSE DATABASES ALL 

热点排行