请教如何将字符串中所有"\"替换为"\\" filePath = filePath.replace("\","\\");我想将所有"\"替换为"\\",谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sUrl = sUrl.replace("@","%40");sUrl = sUrl.replace("#","%23");sUrl = sUrl.replace("(","%28");sUrl = sUrl.replace(")","%29");sUrl = sUrl.replace("=","%3D");sUrl = sUrl.replace(";","%3B");sUrl = sUrl.replace("'","%27");楼主你查一下编码 filePath = filePath.replace(/\\/g,"\\\\") function readExcel() { var filePath = document.form1.upfile.value; filePath = filePath.replace(/\\/g,"\\\\");var excelApp = new ActiveXObject("Excel.application"); try{ var oWB = excelApp.Workbooks.open(filePath); }catch(e){ alert('打开文件失败!'); } var oSheet = oWB.Worksheets(1); alert(oSheet.Cells(1,1).value); alert(oSheet.UsedRange.rows.count); alert(oWB.Worksheets.count); oSheet=null; oWB.close(); excelApp=null; }<input type="file" name="upfile"/><input type="button" onclick="readExcel();" value="读取">js读取excel,用了2楼的方法依然读取不到excel表,为什么呢? filePath = filePath.replace(/\\/g,"\\\\") 自己找到办法了。 function readExcel(id) { var oXL = new ActiveXObject("Excel.Application"); var ip = document.getElementById(id);ip.select();var filePath = document.selection.createRange().text;var oWB = oXL.Workbooks.open(filePath);var oSheet = oWB.ActiveSheet; alert(oSheet.Cells(2,1).value);}<input type="file" id="attachFile" name="attachFile"/><input type="button" onclick="readExcel('attachFile')" value="读取"/>因为在较新版本的浏览器 ( Firefox3, IE8, IE7(IE8模拟) ) 中无法获取file input的完整value,需要使用到selection.createRange()来解决。 关于java的学习 高分求JS解密 完后加分 求助,不知道为什么? 帮帮忙!! javascript中的数值计算 可以通过这个途径更好的解决大家的问题(JS初级和中级人士请进) 我在子窗口中关闭父窗口时,父窗口总是弹出提示是否关闭窗口的对话框,如果才能不让父窗口弹出是否关闭的对话框呢? 关闭浏览器的同时是否可以修改数据库字段? ≡★≡一个疑难问题!忘高手相助≡★≡ js结合ajax实现类似百度搜索的自动补全 好想知道这插入源代码的东西是怎么做的 哪位大哥有源码吗 对于一个小段标题,如何弹出一个层,把详细的信息显示出来,
sUrl = sUrl.replace("#","%23");
sUrl = sUrl.replace("(","%28");
sUrl = sUrl.replace(")","%29");
sUrl = sUrl.replace("=","%3D");
sUrl = sUrl.replace(";","%3B");
sUrl = sUrl.replace("'","%27");
楼主你查一下编码
function readExcel()
{
var filePath = document.form1.upfile.value;
filePath = filePath.replace(/\\/g,"\\\\");
var excelApp = new ActiveXObject("Excel.application");
try{
var oWB = excelApp.Workbooks.open(filePath);
}catch(e){
alert('打开文件失败!');
} var oSheet = oWB.Worksheets(1);
alert(oSheet.Cells(1,1).value);
alert(oSheet.UsedRange.rows.count);
alert(oWB.Worksheets.count);
oSheet=null;
oWB.close();
excelApp=null;
}<input type="file" name="upfile"/><input type="button" onclick="readExcel();" value="读取">
js读取excel,用了2楼的方法依然读取不到excel表,为什么呢?
function readExcel(id)
{
var oXL = new ActiveXObject("Excel.Application");
var ip = document.getElementById(id);
ip.select();
var filePath = document.selection.createRange().text;
var oWB = oXL.Workbooks.open(filePath);
var oSheet = oWB.ActiveSheet;
alert(oSheet.Cells(2,1).value);
}
<input type="file" id="attachFile" name="attachFile"/><input type="button" onclick="readExcel('attachFile')" value="读取"/>因为在较新版本的浏览器 ( Firefox3, IE8, IE7(IE8模拟) ) 中无法获取file input的完整value,需要使用到selection.createRange()来解决。