日期:2014-05-16  浏览次数:20347 次

js导入txt文件
function  readShopCardNoFile(strPath,txtValue)  
{
if(strPath!=null&&strPath.length>0)
{
try {
var  fso,ts,tempValue;
var count=0;
        var   ForReading   =   1;  
        fso = new ActiveXObject("Scripting.FileSystemObject");
        if(fso.GetFile(strPath).size>50000)
        {        
        alert( "对不起!您导入的文件太大!请减少文件内容后再导入!");
        return false;
        }
        myfile = fso.OpenTextFile(strPath,ForReading);
        while(!myfile.AtEndOfStream) { 
        tempValue = myfile.ReadLine();
        txtValue += tempValue;
        }
        myfile.Close();
return true;
}
   catch(e)
   {
alert( "对不起!您目前无法导入文本文件!\n\n\r成功导入文本文件的前提:\n\r"+
       "1、必须使用IE浏览器;\n\r2、必须对IE开启ActiveX。\n\n\r开启ActiveX步骤:\n\r"+
       "IE浏览器:工具->Internet选项->安全->“Internet”和“本地Intranet”->自定义级别:ActiveX控件和插件->对没有标记为安全的ActiveX控件进行初始化和脚本运行:设置为“启用”。"+
       "(或者将ActiveX控件和插件->所有与ActiveX相关的参数都设置为“启用”。)\n\n以上设置确定后,再重新登录abc.com,即可导入文本文件。");
       return false;
   }
}else{
alert("请您导入文件。");
return false;
}
}