码迷,mamicode.com
首页 > 其他好文 > 详细

导入导出EXEC

时间:2019-11-13 11:04:58      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:edit   try   i++   element   UNC   work   date   sql   book   

function toExcel(){

AllAreaExcela();
//AllAreaExcel(grid7.tab);

}


//指定页面区域内容导入Excel
function AllAreaExcela()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.Worksheets(1); //创建工作表
var sel=document.body.createTextRange();
sel.moveToElementText(grid6.tab);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
var ExcelSheet = oWB.Worksheets(2); //创建工作表
var sela=document.body.createTextRange();
sela.moveToElementText(grid7.tab);
sela.select();
sela.execCommand("Copy");
ExcelSheet.Paste();
oXL.Visible = true;
}

//导出

function ReadExcel(DsSub_Grid1)
{

DsSub1.Delete();
var tempStr = "";

var filePath= document.all.upfile.value;

if(filePath == "")
{
alert("请选择要导入的文件!");
return;
}
alert(filePath);

var oXL = new ActiveXObject("Excel.application");

var oWB = oXL.Workbooks.open(filePath);
//var oWB = oXL.Workbooks.open("d:/TEST.xls");
//alert(oWB);
oWB.worksheets(1).select();
var oSheet = oWB.ActiveSheet;
try
{

var ry= "";
var cpmc= "";
var th= "";
var gx= "";
var dz= "";
var ryid= "";
var je= "";
var bz= "";
var wcsl= "";
var bcpsl= "";
var i =2;
ry= oSheet.Cells(i,2).value;
while(ry!=null)
{
ry= oSheet.Cells(i,2).value;
cpmc= oSheet.Cells(i,3).value;
th= oSheet.Cells(i,4).value;
gx= oSheet.Cells(i,5).value;
dz= oSheet.Cells(i,6).value;
//ryid= oSheet.Cells(i,8).value;
wcsl= oSheet.Cells(i,7).value;
bcpsl= oSheet.Cells(i,8).value;
je= oSheet.Cells(i,9).value;
bz= oSheet.Cells(i,10).value;

var sql="select userid from vw_users where username=‘"+ry+"‘";
ryid=SqlToField(sql);
DsSub1.Append();
DsSub1.Fields.Field[‘ry‘].Value = (ry) ? ry: "";
DsSub1.Fields.Field[‘cpmc‘].Value = (cpmc) ? cpmc: "";
DsSub1.Fields.Field[‘th‘].Value = (th) ? th: "";
DsSub1.Fields.Field[‘gx‘].Value = (gx) ? gx: "";
DsSub1.Fields.Field[‘dz‘].Value = (dz) ? dz: "";
DsSub1.Fields.Field[‘ryid‘].Value = (ryid) ? ryid: "";
DsSub1.Fields.Field[‘je‘].Value = (je) ? je: "";
DsSub1.Fields.Field[‘bz‘].Value = (bz) ? bz: "";
DsSub1.Fields.Field[‘wcsl‘].Value = (wcsl) ? wcsl: "";
DsSub1.Fields.Field[‘bcpsl‘].Value = (bcpsl) ? bcpsl: "";
DsSub1.bEdit = true;
DsSub1.Update(‘不检查‘);
DsToGrid(DsSub_Grid1,‘否‘);
i++;

}
oXL.Quit();
DsSub1.Delete();

alert("导入完成!");
}
catch(e)
{
alert("导入失败!"+e);
}

}

 

 

导入导出EXEC

标签:edit   try   i++   element   UNC   work   date   sql   book   

原文地址:https://www.cnblogs.com/lydg/p/11846949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!