Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 Display Modes
  #1 (permalink)  
Old May 11th, 2008, 05:44 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to onlyshails
Default How to save user input in Excel from web page

Hi,I have added a HTML code below. Please copy pate it in NOTEPAD and sait it with extention as " .HTML ".

**This web page is not uploaded . i AM GOING TO USE IT OFFLINE ***

open the the web page and pleae have a look at it and advise me once we fill up the form , how do we save the user input to a MS excel sheet.


***************************************

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<SCRIPT LANGUAGE=JAVASCRIPT>
var currentDate = new Date();
var date1 = currentDate.getDate();
var mon = currentDate.getMonth()+1;
var year = currentDate.getYear();
var today = date1+"/"+mon+"/"+year;
var filePath = "C:\Users\Izzy\Desktop\123456.xlsx";
function setDate()
{
f1.tDate.value=today;
}

function saveToExcel()
{
var myApp = new ActiveXObject("Excel.Application");
myApp.visible = true;
var xlCellTypeLastCell = 11;

var myWorkbook = myApp.Workbooks.Open(C:\Users\Izzy\Desktop\123456. xlsx);
var myWorksheet = myWorkbook.Worksheets(1);
myWorksheet.Activate;
objRange = myWorksheet.UsedRange;


objRange.SpecialCells(xlCellTypeLastCell).Activate ;
newRow = myApp.ActiveCell.Row + 1;
alert('newRow : '+newRow);
strNewCell = "A" + newRow;
alert('strNewCell : '+ strNewCell);
myApp.Range(strNewCell).Activate;
myWorksheet.Cells(newRow,1).value = f1.tDate.value;
myWorksheet.Cells(newRow,2).value = f1.tCaller.value;
myWorksheet.Cells(newRow,3).value = f1.tProduct.value;
myWorksheet.Cells(newRow,4).value = f1.tNatureOfProblem.value;
myWorksheet.Cells(newRow,5).value = f1.tSolutions.value;
myWorksheet.Cells(newRow,6).value = f1.tStatus.value;
myWorksheet.Cells(newRow,7).value = f1.tRemark.value;
myApp.Workbooks.Close;
myApp.Close;
alert('Data successfully saved');
}


</SCRIPT>
<BODY onLoad='setDate();'>
<form name="f1" method="post">
<h align="center"><b>Daily Report</b></h>

<table border="1" width="1000">
<tr>
<td width="250" height="25"></td>
<td width="200" class="tb_bor" align="center"><b>Date</b></td>
<td width="100" class="tb_bor" align="center"><b>Caller</b></td>
<td width="100" class="tb_bor" align="center"><b>Product</b></td>
<td width="150" class="tb_bor" align="center"><b>Nature Of Problem</b></b></td>
<td width="100" class="tb_bor" align="center"><b>Solutions</b></td>
<td width="100" class="tb_bor" align="center"><b>Status</b></td>
<td width="100" class="tb_bor" align="center"><b>Remark</b></td>
<td width="250"></td>
</tr>
<tr>
<td width="250" height="25"></td>
<td width="200" class="tb_bor" align="center"><input type=text name=tDate ></td>
<td width="100" class="tb_bor" align="center"><input type=text name="tCaller" ></td>
<td width="100" class="tb_bor" align="center"><input type=text name="tProduct" ></td>
<td width="150" class="tb_bor" align="center"><input type=text name="tNOP" ></td>
<td width="100" class="tb_bor" align="center"><input type=text name="tSolutions" ></td>
<td width="100" class="tb_bor" align="center"><input type=text name="tStatus" ></td>
<td width="100" class="tb_bor" align="center"><input type=text name="tRemark" ></td>
<td width="250"></td>
</tr>
</table>
<br>
<table align="center">
<input type="button" name="next" value="Next">
<input type="reset" name="clear" value="Clear">
<input type="button" name=save value="Save" onClick='saveToExcel();'>
</table>
</form>
</BODY>
</HTML>
***************************************

Reply With Quote
  #2 (permalink)  
Old May 11th, 2008, 05:58 AM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I can see three problems
  • Your path:
    Code:
    var filePath = "C:\Users\Izzy\Desktop\123456.xlsx";
    should be
    Code:
    var filePath = "C:\\Users\\Izzy\\Desktop\\123456.xlsx";
    and then you don't use the variable later:
    Code:
    var myWorkbook = myApp.Workbooks.Open(C:\Users\Izzy\Desktop\123456.xlsx);
     
  • You don't specify to save changes:
    Code:
    myWorkbook.Close(true);
  • Security permissions must be altered to allow saving to a local folder. If you are running this file directly from your machine consider renaming it to .HTA and look at HTML Applications on msdn.com.


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old May 11th, 2008, 06:13 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to onlyshails
Default

HI, Thanks for the INSTANT REPLY ..i really appreciate that ..i am not too good with java script ...but good with html ..is there any example that u could post or a link that i can visit that explains how it is done as i am working on this since morning ..and there's NO luck and have to make sure this is done by next day morning ..thanks for the help.

Reply With Quote
  #4 (permalink)  
Old May 11th, 2008, 07:25 AM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Firstly, what did you change, what suggestions did you try?
Try searching this forum, for example: http://p2p.wrox.com/topic.asp?TOPIC_ID=28026

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old May 11th, 2008, 07:42 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to onlyshails
Default

The excel file that i have saved on my machine does not open nor any user input from the web page is tranferred to it.

If u have any altogether different code or a way please advise on it .

About ur suggestions ....

Your path:
var filePath = "C:\Users\Izzy\Desktop\123456.xlsx";

should be
var filePath = "C:\\Users\\Izzy\\Desktop\\123456.xlsx";

*** I have made the above change ***

and then you don't use the variable later:
var myWorkbook = myApp.Workbooks.Open(C:\Users\Izzy\Desktop\123456. xlsx);

***as i informed i am not god with javascript , i am unable to understand the above suggestion ****


You don't specify to save changes:
myWorkbook.Close(true);

***as i informed i am not god with javascript , i am unable to understand the above suggestion ****


Reply With Quote
  #6 (permalink)  
Old May 11th, 2008, 07:54 AM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Okay, but the forum is for people trying to learn, not to do the work for someone because they're under time pressure.

Change:
Code:
var myWorkbook = myApp.Workbooks.Open(C:\Users\Izzy\Desktop\123456.xlsx);
to:
Code:
var myWorkbook = myApp.Workbooks.Open(filePath);
Add:
Code:
myWorkbook.Close(true);
here:
Code:
myWorksheet.Cells(newRow,7).value = f1.tRemark.value;
myWorkbook.Close(true);
myApp.Workbooks.Close;
myApp.Close;
--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools
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
How to convert an excel sheet into a web page ashfaqshariff2007 ASP.NET 2.0 Basics 1 August 22nd, 2008 06:00 PM
How to save an web page content into RTF/text file khatu_jec ASP.NET 2.0 Professional 4 November 27th, 2007 04:52 AM
submit button shows the user input in another page debjanib ASP.NET 1.0 and 1.1 Professional 3 June 30th, 2006 10:40 AM
User controls not showing on web page pdr ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2005 10:02 AM
html page save to excel format mateenmohd Javascript 2 January 17th, 2004 05:48 AM



All times are GMT -4. The time now is 12:31 PM.


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