PDA

View Full Version : Opening Excel using Javascript


ranbo
06-09-2005, 09:29 PM
I'm able to open my excel file correctly, but to do so I need to put the entire path into the open function...even though the excel file and web page are housed in the same directory. I'd like to be able to just put the name of the excel file into my open function. Any help would be much appreciated...my current code is below:

<script>

function OpenExcel() {

//Get Excel file
var excel = new ActiveXObject("Excel.Application");

//This is where my problem is.
//If I put the entire path here then it works...but I'd rather not do that
var excel_file = excel.Workbooks.Open("MyFile.xls");

var excel_sheet = excel.Worksheets("Sheet1");

</script>

martin_narg
06-10-2005, 11:13 AM
<script>

function OpenExcel() {

//Get Excel file
var excel = new ActiveXObject("Excel.Application");

//This is where my problem is.
//If I put the entire path here then it works...but I'd rather not do that
var strPath = document.location.href.substring(0, document.location.href.lastIndexOf("/")+1);
var excel_file = excel.Workbooks.Open(strPath+"MyFile.xls");

var excel_sheet = excel.Worksheets("Sheet1");

</script>


This grabs the full folder path of the html document to be used.

Hope this helps!

m_n