???? ??? ??????? ????? ??????? ActiveX ?????? ?????? ??????? ?? Word ?? ???? ??? ???? ??? ??????? ?? Internet Explorer. ???? ??? ????? ??????? ???? ActiveX ?? ???? ??? ????? ?? ?????? ??? ???? ?? ???? ??? ????:
- ??? ??? ???? ?????? ????????? ???????? ?? Visual Basic ???? ???? Microsoft Word ????? ????? ??????? ???????? ???????? ?????? ?? ?? ???????? ?? ???? ????? ????? Visual Basic ??? EXE ActiveX ?? DLL ActiveX.
- ?? ??? Word ??? ????? ??? ???????. ???????? ??? ??????? ?????? ?? Internet Explorer ?? ?? ??? ????? ????????? ???????? ??????? Word ?? ???????? ????? ?? ?? ??? ?????? ???????? ?? ????? ????. ????????? ?? ??? ????? ActiveX ??????? ?????, ???? ?? ??? ??? ????? ??? ??????? ????? ????? ?????? ???.
- ????? Visual Basic ?????? ?? ??????? ???? ?? ???????? ?? ???????? ????? ?? ???? ???. ??? ???? ??????? ???? ?????? ???? ???? Visual Basic ???? ??? ??? ???????? ????? ???? ??? ??? ?????? ??? ??????? ????? ????? ????????? "Windows" (API).
??????? ???? ????? ?????? ?????????? ?? ????? ???? ??? ?????? ????? Word ???????? ?????? ?? ???? ????? ?? ???? ???. ??? ????? ?? ??? ????? ??????? ????? Word ?? ???? ?????? ?????? ??????? ? ????? ??? ???? ??? ??????, ???? ?????? ?? ???? ??????? ????? ?? ???? ?????? ????? ??????? Word. ?????? ????? ??????? ?? ?????? ??????? ? Word ???? ????? ???? ????? ???? ???? ??? ?????? ????? ??????? ??? ???? ???.
???????? ??? ?????? ActiveX ?????? ????? ??????? ??? ?????? ????? ??? ??????? Word ??????? ???? ???? ?????? ?? ???? ???. ??? ?? ???? ???? ?????? ????? ActiveX ????? ?????? ?? ??? ???????. ??? ????? ?? ?? ???? ?????? ????? ??????? Word ?? ??? ????? ??????? ??? ?????? Microsoft Office ?????? ?????????? ??? Microsoft Excel.
????? ?? ?????
AutoWord.exe ????? ??? ????? Visual Basic ActiveX DLL Word ????????? ?????? ??? ???? ?? ????? ?? ??? ???????.
????? ????? ?????? ??????? ?? "???? ??????? ?? Microsoft":
Autoword.exe
(http://download.microsoft.com/download/word2002/sample/1.0/win98mexp/en-us/autoword.exe)
????? ???????:, 17 ????? 2001
?????? ??? ??????? ?????? ??? ????? ????? ????? ??? Microsoft "? ???? ??? ??? ??????? ?????? ?????? ??" ????? ??????? ?? Microsoft:
119591
(http://support.microsoft.com/kb/119591/EN-US/
)
????? ?????? ??? ????? ??? Microsoft ?? ??????? ??? ????????
???? Microsoft ???? ??? ????? ????? ?? ?????????. ??????? Microsoft ???? ?? ?????? ??? ??????? ??????? ??? ??????? ???? ?? ??? ?????. ??? ????? ????? ??? ?????? ????? ?????? ???? ????? ??? ??? ????? ??? ??????? ??? ???? ??? ??? ?????.
????? ?? ?????
??? ????? Autoword.exe ???? ??? ??????? ?????? ???????:
- ????? ???? ???? "??????" ?? ?????? ????? ??????? ????? ???. (?????? ????? ??????? ????????? ?? C:\Inetpub\Wwwroot.)
- ??????? ??????? ?? Autoword.exe ?????? ??????.
- ???? Autoword1.htm ?? ???? ?? ???? HTML ???????? ????? YourWebServer ?? ???? URL ?? ??? ???? ???. ???????? ??????? YourSQLServer ?? ????? ??????? ?? ??? ???? SQL Server ???? ????? ??? ????? ?????? ????? Northwind.
??????: ??? ?? ??? ???? ???????? SQL Server ?? Northwind ????? ????? ?????? ? ????? ????? ????? ??????? ???????? ????? ????? ?????? Microsoft Access Northwind ????? ?? ???. ????? ??? Northwind Access ????? ?????? ????? ??? ???: sConn
sConn = "provider=microsoft.jet.oledb.4.0; data source=" & _
"C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb"
- ???? Autoword2.htm ?? ???? ?? ???? HTML ???????? ????? YourWebServer ?? ???? URL ?? ??? ???? ???.
- ??? ????? Internet Explorer. ????? ??????? http://YourWebServer/invoice/AutoWord1.htm ? http://YourWebServer/invoice/AutoWord2.htm ?????? ???????? ?????. ????? ???? ????? ?????? ?? ?? ??? ??????? ? ??? ??????? ?????? ?? ActiveX ??????.
??? ??? ????? ActiveX Visual Basic ????? ????????? ????? ???????? ?? ??????? ???????.
???? ActiveX Visual Basic
????? ActiveX Visual Basic ?? ??? ?????? ?????? ?? ???????? ????? ???? ??? ?????? ????? ?????? ????? ?? ??? ????????. ?? ???? ????? ??? ??? ?????? ActiveX ?????? ??? ??????? ????? ????? ????? ????? ?? ?? ?????? ????? ??? ???? ??????? ????? ?? XML ???????? ??? ???? ActiveX ??????. ?? ???? ????????? ??? ???? ?????? ??? ??????? ????? ???? ???? ????? Word ????? ????? ???????? ?????? ????.
????? ActiveX (
AutomateWord) ????? ??? ??? ????? ???
?????? ???? ???? ???? ???:
- ?????? ????? GetData ?????? ?????? ActiveX (ADO) ???????? ??????? ??? ????? ?? ????? ????? ?????? Northwind. ??? ????? ??????? ????? ?? ????? ??? ??? m_Data. ???? ??????? ??????? GetData ?????? ??????? ???????? ???? ??????.
- ?????? ????? SendData Microsoft XML (MSXML) ?????? ????? ??? ??? m_Data ?? ??????? ????? ???? ?? ??????? ?? ??? ??????. ????? SendData ????? ????? ???? ???? ???? DOMDocument ?????? ??? ??????? ?????. ???? ??????? ??????? SendData ?????? ??????? ????? ?? ???? ??? ??? ??????. ???? ??????? ASP ?? ??? ??????? ??????? ?????? ???????? ?? ?????? ?????? ???????? ?? ????? ?????? XML ???? ???? ????????? ?? ??? ????? ???????.
- ?????? ????? MakeInvoice ??????? Word ?????? ????? ????? ??? ??????? ????? ?? ????? ??? ??? m_Data. ????? ???? ??? ??? ??? ??????? ???? ????? ????????. ?? ????? ?????? ???? ????? Word ???????? ???? ???????? ?? ??? ??????? ???????? ??? ??? ?????????? ??????.
Invoice.cls
Option Explicit
Private Type InvoiceData
OrderID As String
OrderDate As Date
CustID As String
CustInfo As String
ProdInfo As Variant
End Type
Private m_Data As InvoiceData
Public Sub GetData(sOrderID As Variant, sConn As Variant)
Dim oConn As Object, oRS As Object
'Connect to the Northwind database.
Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConn
'Obtain the Customer ID and Order Date.
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open "Select [OrderDate], [CustomerID] from Orders where " & _
"[OrderID]=" & sOrderID, oConn, 3 'adOpenStatic=3
m_Data.OrderID = sOrderID
m_Data.OrderDate = CDate(oRS.Fields("OrderDate").Value)
m_Data.CustID = oRS.Fields("CustomerID").Value
oRS.Close
'Obtain Customer information.
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open "Select * from Customers Where CustomerID='" & _
m_Data.CustID & "'", oConn, 3 'adOpenStatic=3
m_Data.CustInfo = oRS.Fields("CompanyName").Value & vbCrLf & _
oRS.Fields("City") & " "
If Not (IsNull(oRS.Fields("Region"))) Then
m_Data.CustInfo = m_Data.CustInfo & oRS.Fields("Region").Value & " "
End If
m_Data.CustInfo = m_Data.CustInfo & oRS.Fields("PostalCode").Value & _
vbCrLf & oRS.Fields("Country").Value
oRS.Close
'Obtain Product information.
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open "Select ProductName, Quantity, [Order Details].UnitPrice," & _
"Discount from Products Inner Join [Order Details] on " & _
"Products.ProductID = [Order Details].ProductID " & _
"Where OrderID = " & sOrderID, oConn, 3 'adOpenStatic=3
m_Data.ProdInfo = oRS.GetRows
oRS.Close
'Close the connection to the database.
oConn.Close
End Sub
Public Sub SendData(oXML As Variant)
'Extract the information from the DOMDocument object oXML and store
'it in the private member variable m_Data.
m_Data.OrderID = oXML.getElementsByTagName("OrderID").Item(0).Text
m_Data.OrderDate = oXML.getElementsByTagName("OrderDate").Item(0).Text
m_Data.CustID = oXML.getElementsByTagName("CustID").Item(0).Text
m_Data.CustInfo = oXML.getElementsByTagName("CustInfo").Item(0).Text
Dim oItems As Object, oItem As Object
Set oItems = oXML.getElementsByTagName("Items").Item(0)
ReDim vArray(0 To 3, 0 To oItems.childNodes.Length - 1) As Variant
Dim i As Integer
For i = 0 To UBound(vArray, 2)
Set oItem = oItems.childNodes(i)
vArray(0, i) = oItem.getAttribute("Desc")
vArray(1, i) = oItem.getAttribute("Qty")
vArray(2, i) = oItem.getAttribute("Price")
vArray(3, i) = oItem.getAttribute("Disc")
Next
m_Data.ProdInfo = vArray
End Sub
Public Sub MakeInvoice(sTemplate As Variant, Optional bSave As Variant)
Dim oWord As Object
Dim oDoc As Object
Dim oTable As Object
If IsMissing(bSave) Then bSave = False
'Open the document as read-only.
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open(sTemplate, , True)
'Fill in the bookmarks.
oDoc.Bookmarks("Customer_Info").Range.Text = m_Data.CustInfo
oDoc.Bookmarks("Customer_ID").Range.Text = m_Data.CustID
oDoc.Bookmarks("Order_ID").Range.Text = m_Data.OrderID
oDoc.Bookmarks("Order_Date").Range.Text = m_Data.OrderDate
'Fill in the table with the product information.
'** Note that the table starts out with three rows -- the first row
' contains headers for the table, the second row is for
' the first set of product data, and the third row contains a total.
' New rows are added for additional products before the "total row".
Set oTable = oDoc.Tables(1)
Dim r As Integer, c As Integer
For r = 1 To UBound(m_Data.ProdInfo, 2) + 1
If r > 1 Then oTable.Rows.Add (oTable.Rows(oTable.Rows.Count))
For c = 1 To 4
oTable.Cell(r + 1, c).Range.Text = _
m_Data.ProdInfo(c - 1, r - 1)
Next
oTable.Cell(r + 1, 5).Formula _
"=(B" & r + 1 & "*C" & r + 1 & ")*(1-D" & r + 1 & ")", _
"#,##0.00"
Next
'Update the field for the grand total and protect the document.
oTable.Cell(oTable.Rows.Count, 5).Range.Fields.Update
oDoc.Protect 1 'wdAllowOnlyComments=1
If bSave Then
'Save the document as "c:\invoice.doc" and quit Word.
Dim nResult As Long
nResult = MsgBox("Are you sure you wish to create the document" & _
" ""c:\invoice.doc""? If this document already exists, " & _
"it will be replaced", vbYesNo, "AutomateWord")
If nResult = vbYes Then oDoc.SaveAs "c:\invoice.doc"
oDoc.Close False
oWord.Quit
Else
'Make Word visible.
oWord.Visible = True
End If
End Sub
???????? ?????? ActiveX ?? ???? ???
???? Autoword1.htm ??? ????? ??????? ???????
GetData ?????? ????? ActiveX ??????? ???? ?????? ???????? ????? ??? ????? ???????.
Autoword1.htm
<HTML>
<HEAD>
<OBJECT ID="AutoWord"
CLASSID="CLSID:32646EBA-0919-4C2F-94D6-599F46DC34F2"
CODEBASE="http://YourWebServer/invoice/package/AutomateWord.CAB#version=1,0,0,0">
</OBJECT>
</HEAD>
<BODY>
Enter an order id between 10248 and 11077 and click the button to view the invoice for the order:
<P/><INPUT TYPE="text" VALUE="10500" ID="OrderID">
<P/><BUTTON ID="InvoiceButton">Create Invoice</BUTTON>
</BODY>
<SCRIPT Language="VBScript">
Function InvoiceButton_OnClick()
Dim sConn
sConn = "Provider=sqloledb;Data Source=YourSQLServer;Initial Catalog=Northwind;UID=sa;"
AutoWord.GetData OrderID.Value, sConn
AutoWord.MakeInvoice "http://YourWebServer/invoice/invoice.doc"
End Function
</SCRIPT>
</HTML>
?????? ???????? ????? ?? Autoword1.htm ????? ActiveX ???? ??????? ???????? ???? ????????. ????? ????? ?????? ??? ??????? ???????? ?????? ?? ????????; ??? ???? ?????? ???? ????? ?? ??? ??? ????? Word ??? ???. ???? ?????? ??? ??????? ?? C:\Invoice.doc ??? ???? ??????? ?????? ??????. ???? ??? ????? ActiveX ??? ??????? ??? ?????? ?????? ????? ?????.
??? ??? ???? ?? ??? ??????? ???????? ?? ???????? ?????? ???????
MakeInvoice ?? Autoword1.htm ??????: Autoword2.htm
AutoWord.MakeInvoice "http://YourWebServer/invoice/invoice.doc", True
window.navigate "c:\invoice.doc"
???? ??? ????? ??????? ???????
SendData ?????? ???????? ????? ?????
DOMDocument ??? ???? ActiveX ?????? ??????? ????????. ?? ?????
DOMDocument ?? ????? ?????? XML ????? ??? ???? ???. ???? ActiveX ???? ???? ?????? ??????? ????? ???? ?? ??????? ?? ??? ?????? XML ??? ?? ???? ??? ??????? ????? ???? ?????? ???? ????? ??????? ?????.
Autoword2.htm
<HTML>
<HEAD>
<OBJECT ID="AutoWord"
CLASSID="CLSID:32646EBA-0919-4C2F-94D6-599F46DC34F2"
CODEBASE="http://YourWebServer/invoice/package/AutomateWord.CAB#version=1,0,0,0">
</OBJECT>
</HEAD>
<BODY>
<BUTTON ID="InvoiceButton">Create Invoice</BUTTON>
<XML ID="DataXML">
<Order>
<OrderID>10700</OrderID>
<OrderDate>10/10/2000</OrderDate>
<CustID>SAVEA</CustID>
<CustInfo>Save-a-lot
Markets Boise ID 83720
USA</CustInfo>
<Items>
<Product Desc="Chai" Qty="5" Price="18" Disc="0.2"/>
<Product Desc="Sasquatch Ale" Qty="12" Price="14" Disc="0.2"/>
<Product Desc="Scottish Longbreads" Qty="40" Price="12.5" Disc="0.2"/>
<Product Desc="Flotemysost" Qty="60" Price="21.5" Disc="0.2"/>
</Items>
</Order>
</XML>
</BODY>
<SCRIPT Language="VBScript">
Function InvoiceButton_OnClick()
AutoWord.SendData DataXML.XMLDocument
AutoWord.MakeInvoice "http://YourWebServer/invoice/invoice.doc"
End Function
</SCRIPT>
</HTML>
?? ?? Autoword1.htm "?" Autoword2.htm "? ??? ?????? ????? ???? ????? ActiveX ?????? ?????? ?? ?????? <object>????? ??????
CreateObject. ????? ?? ??????? ??????? <object>?? ????? ??????? ???????? ????? ActiveX ?????????? ???? ?? ????? ?????? ????? ????. ??? ??? ??? ?????????? ?????? ???? ??? ??????? ?? ??? ????? ?????? ??? ????? ?????? ?? ??? ??????? (CAB) ??? URL ?????? ???? ?????
??????? ??????? ????????. ???????? ??? ??????? ?????? ???????? ?? Internet Explorer? ?? ????? ???? ?????? ?????? ???????.
??????: ?? ????? ??? CAB ??????? ?? Autoword.exe ???????? "????" ? "????? ????? Visual Basic. ????? ActiveX ?? ?????? ?? ??? ????? ??? ??? ??????? ???????? ???? ?? ??? ??????? ??????.
?????? ??? ???? ?? ????????? ??? ????? ????????? ???? ?????? ??????? ?????? ???? ?????? ??? ??? ??????? ? ???????? ???? ????? ???? ????? Microsoft (MSDN) ?????? ??? ?????:
?????? ??? ??????? ??????? ???? ??? ????? ???????? ??????? ?????? ?? "????? ??????? ?? Microsoft:
257757
(http://support.microsoft.com/kb/257757/
)
INFO: ?? ??????? Office ??? ????? ??? ??????? ??? ?????? ?? ????????
270906
(http://support.microsoft.com/kb/270906/EN-US/
)
????? ??????? ASP ??? ????? ????? ????? (RTF) ?? ???? ??? ??? ??? Microsoft Word
(c) ??? ???? Microsoft ???? ???? ?????. ????????? ??? Lori B. Turner ? Microsoft Corporation.
???? ???????: 286023 - ????? ??? ??????: 30/???? ??????/1428 - ??????: 11.3
????? ???
- Microsoft Office Word 2007
- Microsoft Office Word 2003
- Microsoft Word 2002 Standard Edition
- Microsoft Word 2000 Standard Edition
- Visual Basic, Scripting Edition 5.0
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Internet Explorer 5.0
- Microsoft Internet Explorer 5.01
- Microsoft Internet Explorer 5.5
| kbmt kbdownload kbautomation kbhowto KB286023 KbMtar |
????? ???????: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????
286023
(http://support.microsoft.com/kb/286023/en-us/
)