2017-11-20 5 views
0

以下は私のコードです。問題は、Excelワークシートにフィールドを追加していないことです。HTMLからデータを受け取り、Excelに送信するにはどうすればいいですか?

<! DOCTYPE html> 
<Html> 
<Head> 
    <script language="vbscript" type="text/vbscript"> 
    Sub Sample() 
     Dim iRow 
     Set objExcel = CreateObject ("Excel.Application") 
     Set objWorkbook = objExcel.Workbooks.Open ("C:\Users\ARPIT SHAJU\Desktop\Church\Member.xlsx") 
     objExcel.Application.Visible = True 
     ObjWorkbook.Windows (1).Visible = True 
     Set XlSheet =objWorkbook.Sheets (1) 
     XlSheet.Activate 
     iRow = 1 
     With objExcel 
      Do while .Cells (iRow, 1).value <> "" 
       .Cells (iRow, 1).activate 
       iRow = iRow + 1 
      Loop 
      .Cells (iRow, 1).value=Document.GetElementsByName ("fname") (0).Value 
      .Cells (iRow, 2).value=Document.GetElementsByName ("surname") (0).Value 
      .Cells (iRow, 3).value=Document.GetElementsByName ("gender") (0).Value 
      .Cells (iRow, 4).value=Document.GetElementsByName ("mstatus") (0).Value 
      .Cells (iRow, 5).value=Document.GetElementsByName ("dob") (0).Value 
      .Cells (iRow, 6).value=Document.GetElementsByName ("doa") (0).Value 
      .Cells (iRow, 7).value=Document.GetElementsByName ("baptised") (0).Value 
      .Cells (iRow, 8).value=Document.GetElementsByName ("residence") (0).Value 
      .Cells (iRow, 9).value=Document.GetElementsByName ("mnumber") (0).Value 
      MsgBox "Data Added Successfully”, vbinformation 
      Document.GetElementsByName ("fname") (0).Value="" 
      Document.GetElementsByName ("surname") (0).Value="" 
      Document.GetElementsByName ("gender") (0).Value="" 
      Document.GetElementsByName ("mstatus") (0).Value="" 
      Document.GetElementsByName ("dob") (0).Value="" 
      Document.GetElementsByName ("doa") (0).Value="" 
      Document.GetElementsByName ("baptised") (0).Value="" 
      Document.GetElementsByName ("residence") (0).Value="" 
      Document.GetElementsByName ("mnumber") (0).Value="" 


     End With 
     ObjWorkbook. Save 
     ObjWorkbook. Close 
     Set objWorkbook = Nothing 
     Set objExcel = Nothing 
     End Sub 
     </script> 
     <style type="text/css"> 
     fieldset { 
      border: #00cc00 2px solid; 
     padding: 10px; 
     color: green; 
    </style> 
<body 
<form> 
<fieldset> 
    <legend>Csharpcorner</legend> 
    <center> 

    First name:<br> 
    <input type="text" name="fname" Value=""><br> 
    Surname:<br> 
    <input type="text" name="surname" Value=""><br> 
    Gender :<br> 
    <input type="text" name="gender" Value=""><br> 
    Marital Status :<br> 
    <input type="text" name="mstatus" Value=""><br> 
    Date of Birth :<br> 
    <input type="text" name="dob" Value=""><br> 
    <br> 
    Marriage Date :<br> 
    <input type="text" name="doa" Value=""><br> 
    Baptised :<br> 
    <input type="text" name="baptised" Value=""><br> 
    Residence :<br> 
    <input type="text" name="residence" Value=""><br> 
    Mobile Number :<br> 
    <input type="text" name="mnumber" Value=""><br> 
    <input type="button" onclick="Sample()" value="Submit"><br> 
    </center> 
</fieldset> 
<form> 
</body> 
</html> 

私は自分のExcelとメモ帳を同じフォルダに持っています。コードの何が間違っていますか?ワークシートに値を追加するにはどうすればよいですか?私はデータベースやサーバーなしでそれを使用したいと思います。これは人員のためのオフライン形式です。もっと良い解決策は大歓迎です。

+0

あなたは.HTAファイルとしてではなく、 "メモ帳" として、そのコードを保存する必要があります。 – omegastripes

+0

そのHTMLを開いているソフトウェアは何ですか?デベロッパーツールでコンソールに表示されるエラーは何ですか? – Quentin

+0

私は拡張子.htmのメモ帳を保存してインターネットエクスプローラで開いた – Neethu

答えて

1

ウェブサイトからコードをコピーする際には注意が必要です。すべてのブロック引用符“”を二重引用符"に置き換える必要があります。


Code Snippet Image

+0

二重引用符に変更してもまだ動作していません – Neethu

+0

コンテンツを許可し、ブラウザのセキュリティ設定を変更してActiveXを許可する必要がありますオブジェクト。 Chromeがもうサポートしていないと思います。 IEはあなたの最善の策です。 –

+0

代わりにHTAファイルを作成することを検討してください。 [VBSEdit](http://www.vbsedit.com/default.asp?adwords=2&gclid=Cj0KCQiAl8rQBRDrARIsAEW_To__h4a8zBdxmtBkq7-4AW04GtcwQraWpjDTkYaXr43qldcC5j3KcQaAi0JEALw_wcB)には、非常に優れたHTA IDEが付属しています。 –

関連する問題