Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble exporting from HTML to Excel

Status
Not open for further replies.

unclesvenno

Programmer
Sep 12, 2004
33
AU
Hello,

I am trying to export data inserted into an HTML page to an Excel spreadsheet. If I right click on the HTML page I get an option "Export to Microsoft Excel", this works fine, however I wanted to use a button on the page to do it.

I am using the following HTML code :

Code:
      function cmdExport(form)
      {
        var xls = new ActiveXObject ("Excel.Application");

        xls.visible = true;

        var x1FileName = "[URL unfurl="true"]http://intranet/calculator.xls";[/URL]
        var x1Book = xls.Workbooks.Open(x1FileName);

        xls.ActiveSheet.Cells(4,2).value = form.numfiles.value;
        xls.ActiveSheet.Cells(5,2).value = form.numpages.value;
        xls.ActiveSheet.Cells(6,2).value = form.numdocs.value;
        xls.ActiveSheet.Cells(7,2).value = form.numexpages.value;
        xls.ActiveSheet.Cells(8,2).value = form.pagedel.value;
        xls.ActiveSheet.Cells(9,2).value = form.thirdparty.value;
        xls.ActiveSheet.Cells(27,3).value = form.postagecost.value;

        var fname = xls.GetSaveAsFilename("Estimate.xls", "Excel Spreadsheets (*.xls), *.xls");

        if (fname==""){
          fname="C:\\Estimate.xls";
        }

        x1Book.SaveAs(fname);
        x1Book.Close;
        xls.visible = false;
        xls.Quit();
      }

and :

Code:
<input type="submit" value="Export" onClick="cmdExport(this.form)">

When I click the "Export" button the page appears to Refresh and at the bottom of the browser it reads "Done". Can anyone see what I'm doing wrong?

Thanks again,
Uncle Svenno
 
I got it to work if I have the web page and the excel file in the same directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top