What is HotCell Technology? |
New in V4
*Not all HotCell features are
available in ExcelWriterSE, ExcelWriterLE,
and ExcelWriterFree.
|
With ExcelWriter, there are several ways to
populate an Excel workbook with data from a
database,
including ExcelTemplate,
Cells.GetDataFromRecordset,
and Cells.CopyFromRecordset.
ExcelWriter Version 4 includes HotCell Technology - the ability to update a server-side
data source directly from client-side Excel.
This solution utilizes client-side Excel VBA code to detect when changes have been made to
a worksheet. The address and value of each modified cell is submitted to
the server in order to modify the data source. There are two different upload methods that you
can use to submit the changed cell data back to the server:
- Upload the entire workbook to the server
This method uploads the entire edited workbook back to the server.
When you issue the command to update the data source, ExcelWriter Assistant*
(included in XLWAssis.cab) uploads the
entire workbook back to the server along with information about
which cells have changed. On the server, ExcelWriter opens the
uploaded workbook, reads the values of the changed cells, and
updates the data source.
- POST changed-cell instructions to the server
This method submits cell information in an HTTP POST request.
On the server, the receiving ASP script parses the information
and updates the data source. This solution is far less
network-intensive because it just posts bits of information instead
of the entire workbook. However, the POST method is more
complicated than the upload method and requires more code on
both the client and server.
This package contains two samples for each of the transfer methods mentioned above. For each of the transfer methods, there are sample applications that show you how to use HotCells when you know exactly which cells in your workbook will be editable (such as in a form), and ones that show you how to use HotCells to update large tabular data sheets where the specific cells aren't precisely known.
Depending on your application needs, you can choose which approach to use in order to customize the solution to your own needs. Here are some examples of usage scenarios that may assist you in deciding which techniques to develop:
Top
Simple POST Example: Editing Cells with Known Positions
This sample uses a form to update employee information in the Northwind Traders
database. In Excel, edit the employee's first and last names, save the changes, and click
Update to send the data back to the server. ExcelWriter is used to populate an
Excel workbook with employee information from the database and stream the workbook to the client.
Run the Sample
|
Description |
See the Code |
| Form.asp |
Entry point to the sample |
[View Source]
|
| GetEmployeeDataSheet.asp |
ExcelTemplate workbook generator |
[View Source]
|
| Update.asp | Database update handler |
[View Source]
|
| Template.xls |
Template Excel workbook Note: Go to Tools > Macros > Visual Basic Editor to see the VBA code |
[View Template] |
The sample works as follows:
- Form.asp loads and you can select an Employee ID for the individual whose information you
would like to edit.
- Form.asp submits data to GetEmployeeDataSheet.asp, which uses ExcelWriter's ExcelTemplate
object to populate the form - Template.xls - with the employee's information. Template.xls
contains a VBA subroutine that will fire when the user clicks Update:
Sub btnUpdate_OnClick
'--- Code
End Sub
Note how the two values of the editable cells are read from the
workbook:
employeeID = Range("B8").Value
firstName = Range("B9").Value
lastName = Range("B10").Value
This solution uses Microsoft's XMLHTTP object to perform the HTTP request:
Set oHTTP = CreateObject("Msxml2.XMLHTTP")
- In Excel, you can edit the employee's information. When you click Update, the VBA code reads
the values from the two editable cells and submits it to the server script Update.asp in the form
of standard HTML Form data.
- Update.asp reads the submitted form data, forms a SQL UPDATE statement, and executes the query,
updating the data source. The values submitted from the Excel VBA are handled on the server
as form elements, using ASP's Request.Form:
employeeID = Request.Form("employeeID")
firstName = Request.Form("firstName")
lastName = Request.Form("lastName")
Note how the SQL statement is formed with the values submitted from the client:
strSQL = "UPDATE Employees SET FirstName='" & firstName & _
"', LastName='" & lastName & _
"' WHERE EmployeeID = " & employeeID
Top
Copyright © 2003, SoftArtisans, Inc.