Excel Save Prompt in javascript
Hi all,
When I am using javascript to access Excel cell data, at the excel.Quit() point, a save prompt comes up asking me if I would like to save changes to the workbook. All I am doing is reading from, not writing to the workbook. Is there any code to stop this? Or a workaround?
Here's the code used (thanks to Joe for this, and pgtips for the Decimal Point solution)
function getExcelData(){
var whichmonth2 = document.form1.themonth.value.toLowerCase();
var whichmonth = document.form1.themonth.value.toLowerCase();//value from a textbox
var whichweek = document.form1.theweek.value.toLowerCase();//value from a textbox
var theperiod = document.form1.periods.selectedIndex;//From a select box
if (theperiod ==0){
period ="2004 - 2005"//the year (in the folder name)
period2 = "2004" (for the file within the folder)
}
if (theperiod ==1){
period ="2005 - 2006"
period2 ="2005"
}
var oExcel = new ActiveXObject("Excel.Application");
var oWB = oExcel.workbooks.open("\\\\KPISERVE\\common$\\Home Delivery\\_KPI's\\"+ period +"\\" + whichmonth +" " + period2 + "\\" + period2 + "-kpi-" + whichmonth + whichweek + ".xls");
var oWS = oWB.worksheets("Regional Summary");//the worksheet where the data is contained
var range1 = oWS.Range("AF67").value;
if (isNaN(range1)){//Some of the worksheets have the data I need stored in different cells
range1 = oWS.Range("Y72").value
}
var range2 = oWS.Range("AH67").value;
if (isNaN(range2)){//this is where the data is instead if it isn't found above
range1 = oWS.Range("AA72").value
}
var range3 = oWS.Range("AJ67").value;
if (isNaN(range3)){
range1 = oWS.Range("AC72").value
}
var range4 = oWS.Range("AF10").value; //setweekly
var range5 = oWS.Range("AH10").value;//setmonthly
var range6 = oWS.Range("AJ10").value; //setyearly
var range7 = oWS.Range("AF11").value; //complete weekly
var range8 = oWS.Range("AH11").value; //complete monthly
var range9 = oWS.Range("AJ11").value; //complete yearly
document.getElementById("divOutputA").innerText = Math.round(10000 * range1) / 100.0 + "%";//percentage workaround, thanks pgtips
document.getElementById("divOutputB").innerText = Math.round(10000 * range2) /100.0 + "%";
document.getElementById("divOutputC").innerText = Math.round(10000 * range3) /100.0 + "%";
document.getElementById("setweekly").innerText = range4;
document.getElementById("setmonthly").innerText = range5;
document.getElementById("setyearly").innerText = range6;
document.getElementById("compweekly").innerText = range7;
document.getElementById("compmonthly").innerText = range8;
document.getElementById("compyearly").innerText = range9;
oExcel.quit();//when I get to here I am prompted to save changes to the excel file.
}
</script>
Also, is there a way to kill the process used for this? It seems when I go to open the same workbook again, Office tells me I am modifying it even though the file is no longer 'open'. I look in the task list though and it is still running.
TIA
interrupt
__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
|