Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2005, 10:41 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
Reply With Quote
  #2 (permalink)  
Old March 16th, 2005, 11:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

try closing the workbook object before you quit. the close method has an optional Save argument, so something like oWB.Close(false); just before oExcel.Quit() should sort it.

rgds
Phil
Reply With Quote
  #3 (permalink)  
Old March 18th, 2005, 04:52 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nice! That works a treat.

Thanks
interrupt

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling second Excel Save prompt j0hnyager VB How-To 3 November 20th, 2007 09:51 AM
Prompt to Save arholly Access 13 December 18th, 2006 06:32 PM
not able to save data using javascript rok Classic ASP Databases 0 April 21st, 2004 04:31 AM



All times are GMT -4. The time now is 05:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.