当前位置:网站首页>VFPBS上传EXCEL并保存MSSQL到数据库中
VFPBS上传EXCEL并保存MSSQL到数据库中
2022-06-30 05:10:00 【加菲猫的VFP】
开发环境
后端:VFP SP2 7423 +祺佑三层开发框架(猫框)
前端:VUE2.0+Element
思路
- 实现BS上传
- 就是利用猫框的importexcel类将EXCEL文件转换为临时表,
- 将临时表插入到DAL_CA中实现一键保存。
1. 首先来看一下MSSQL数据结构

2. 代码生成器生成DAL_CA类

3. 将生成的DAL_CA类保存到开发框架的DAL目录中
类名同文件名
4. 编写业务逻辑controller类
Define Class ctl_skin_ht as session
*--上传导入文件
Procedure upfile
oResult=GetUpFile() &&返回为集合对象
*--原文件名
cOldFilename=oResult.ofieldcoll.Item("file").filename &&文件名 跟上传name(微信)对应 key (mui) 对应
cExtName=Justext(cOldFilename) &&扩展名
IF !INLIST(UPPER(cExtName),"XLS","XLSX")
ERROR "必须上传EXCEL文件"
ENDIF
cFilename=Ttoc(Datetime(),1)+Right(Transform(Second()*1000),6)
cFilename=cFilename+"."+cExtname
cMydata=oResult.ofieldcoll.Item("file").fielddata &&文件内容
cFilePath=getwwwrootpath("upfile")
If !Directory(cFilePath)
Md &cFilePath &&目前只在调试服务器下执行成功,发布时要预先创建
Endif
If Strtofile(cMydata,cFilePath+cFilename)<=0
Error "写入文件失败,目录是否存在且可读写"
Endif
*--导入EXCEL生成临时表
xx=Newobject("importexcel","importexcel.prg")
xx.cursorstruc="手机型号 c(240),编号 c(50)"
xx.Alias="tmpxxx"
If !xx.Import(Sys(5)+Sys(2003)+"\"+cFilePath+cFilename)
Error xx.msg
Endif
*-- 临时表写入DAL类,实现一键保存
oDAL=Newobject("Dal_skin","Dal_skin.prg")
oDAL.Nodata=.T.
If !oDAL.CursorFill(.T.)
Aerror(laerror)
Error laerror(2)
Endif
cTmpAlias=oDAL.Alias
Insert Into &cTmpAlias(model,skincode,mainmodel,types,Type,Memo,price) Select * From tmpxxx
If !oDAL.Save()
Error oDal.msg
Endif
Return cursortojson(oDAL.alias)
Endproc
ENDDEFINE
5. 前端页面,也可以自己写上传的页面
放下一个上传组件
<el-upload
:on-success="handle_success"
class="upload-demo"
:action="upurl"
multiple
:limit="1"
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传excel文件</div>
</el-upload>
JS代码
export default {
components: {},
data() {
return {
upurl:"ctl_skin_ht.fsp?proc=upfile"
},
methods: {
handle_success(res){
console.log(res);
if(res.errno!=0){
this.$message.warning(res.errmsg);
return;
}
this.$message.warning("上传成功");
},
}
}
运行调试服务器,测试上传,完美成功。但是发布到IIS却出现了:

下篇继续填坑
边栏推荐
- On mask culling of unity
- Some books you should not miss when you are new to the workplace
- Chinese pycharm changed to English pycharm
- Unity call Exe program
- Unity3d realizes Google Digital Earth
- 东塔攻防世界—xss绕过安全狗
- Writing unityshader with sublimetext
- Intellj idea generates jar packages for projects containing external lib to other projects. The method refers to the jar package written by itself
- Operation of JSON file
- pycharm 数据库工具
猜你喜欢

力扣209. 长度最小的子数组

Unity 3D model operation and UI conflict Scrollview

Deeply understand the function calling process of C language

pytorch中常用损失函数总结

【VCS+Verdi聯合仿真】~ 以計數器為例

Unity2019.3.8f1 development environment configuration of hololens2

Force buckle 349 Intersection of two arrays

One command to run rancher

Create transfer generation point

Unity publishing /build settings
随机推荐
003-JS-DOM-Attr-innerText
GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
Unity call Exe program
[vcs+verdi joint simulation] ~ take the counter as an example
LXC 和 LXD 容器总结
Configuration and use of controllers and routes in nestjs
How can the international trading platform for frying US crude oil guarantee capital security?
Leetcode 180 Consecutive numbers (2022.06.29)
GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
Unity3d lookat parameter description
Unity project hosting platform plasticscm (learn to use 1)
Unity realizes rotation and Revolution
Harbor API 2.0 query
Force buckle 349 Intersection of two arrays
How does unity use mapbox to implement real maps in games?
Exploration of unity webgl
Pytorchcnn image recognition and classification model training framework
PWN Introduction (2) stack overflow Foundation
Basic operations of Oracle data
Unity notes_ SQL Function