交互式爱情
语法本身没有错误,可能还是运行环境的原因。很多网上下载的office,导入导出的时候就是会出现问题。可以选择使用其他的导出方式,比如用uo或者自定义输出函数!f_saveasexcel(dw_1,ls_err) 。函数代码:integer li_rtn,ii,li_ascstring ls_name,ls_pathnameboolean lb_existlong numcols,c,rint retstring ls_colname,ls_text,ls_modistr,ls_colstring ls_s,ls_temp[]long ll_bupper,ll_blower,ll_jOLEObject lx_excelif datawin.RowCount() < 1 thenerr = "请先检索数据再导出至Excel!"return false//errorend ifli_rtn = GetFileSaveName("保存文件",ls_pathname,ls_name,"xls","Excel文件(*.xls),*.xls")if li_rtn = 1 thenlb_exist = FileExists(ls_pathname)IF lb_exist THENli_rtn = MessageBox("保存", ls_pathname+"已经存在,是否覆盖?",Exclamation!, YesNo!)end ifif li_rtn = 1 then//当文件存在用户选择覆盖,或是文件本就不存在时。注意变量li_rtnli_rtn = datawin.SaveAsAscii(ls_pathname)if li_rtn <> 1 thenerr = "导出数据失败!"return false//errorend ifelseerr = "请选择要导出的路径!"return false//errorend ifelseerr = "已取消输出!"return falseend if//通过ole直接操作excellx_excel = CREATE OLEObject//连接excelIF lx_excel.ConnectToNewObject("excel.application") <> 0 THENerr = "OLE连接Excel错误!"return falseEND IF//打开导出Excel文件lx_excel.workbooks.open(ls_pathname)//设置表格框lx_excel.Worksheets(1).UsedRange.Borders.LineStyle = 1//首行粗体lx_excel.Worksheets(1).rows(1).Font.Bold = True//首行单元格水平居中lx_excel.Worksheets(1).rows(1).HorizontalAlignment = -4108//首行单元格垂直居中lx_excel.Worksheets(1).rows(1).VerticalAlignment = -4108//调整Excel行高,列宽lx_excel.Worksheets(1).Cells.EntireColumn.AutoFitlx_excel.Worksheets(1).Cells.EntireRow.AutoFit//所有列设置成文件格式显示 12-07lx_excel.Worksheets(1).Range("A1:W8992").NumberFormatLocal = "@"//不进行提示lx_excel.DisplayAlerts = false//保存表格lx_excel.ActiveWorkbook.saveas(ls_pathname,-4143)//关闭打开的Excellx_excel.ActiveWorkbook.close//退出lx_excel.quiterr = "导出数据成功!"return true//success