欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何創(chuàng)建Word文件?

 更新時(shí)間:2006年11月16日 00:00:00   作者:  

creatdoc.asp

<!DOCTYPE html PUBLIC "-//W3C/Dtd html 3.2 Final//EN">
<head>
<title>
星河影動(dòng)之創(chuàng)建Word文件</title>
<META HTTP-EQUIV="Refresh" CONTENT="30;URL='orderForm.asp'">
</head>
<%
    dotLocation="'servernamedirectory    heTemplate.dot'"
    intRowCount = Request.Form("rowCount") 

' 初始化行計(jì)數(shù).
%>
<body Language="VBScript" onLoad="creatdoc document.theForm,
<%=dotLocation%>,intRowCount>
<FORM NAME="theForm">

-----------------------------------------------------------------------------------------------------------------------------------

body標(biāo)記中對(duì)onLoad調(diào)用,調(diào)用creatdoc VB腳本子程序,向它傳遞3個(gè)參數(shù):頁(yè)面中表單的內(nèi)容(所有的隱含域)、Word模板文件的位置、從輸入表單中收到的行數(shù).讀所有的輸入表單域,然后當(dāng)頁(yè)面裝載后調(diào)用creatdoc子程序
<%
    itemCount = 0                           

' 設(shè)置域計(jì)數(shù)器為0.
    For Each Item in Request.Form           

' 總計(jì)表格域.
    itemCount = itemCount + 1           

' 使用For..Next 循環(huán).

%>
    <INPUT TYPE="hidden" NAME="<%=Item%>" VALUE="<%=Request(Item)%>">
<% Next %>
    <INPUT TYPE="hidden" NAME="numbRows"  VALUE="<%=intRowCount%>">
    <INPUT TYPE="hidden" NAME="fieldCount" VALUE="<%=itemCount%>">
</FORM>
</body></html>
-------------------------------------------------------------------------------------------------------------------------------------
  

開(kāi)始創(chuàng)建一個(gè)Word 文件對(duì)象. Internet Explorer 4以上版本中,要將瀏覽器的安全性設(shè)置為Low Custom
<%
Set objWordDoc = CreateObject("Word.Document")
ObjWordDoc.Application.Documents.Add theTemplate, False
ObjWordDoc.Application.Visible=True
%>
-------------------------------------------------------------------------------------------------------------------------------------

調(diào)整數(shù)組的維數(shù)使它與網(wǎng)頁(yè)表單所包含的行數(shù)相同.Y軸設(shè)為4個(gè)常量,這是輸出文件中所需要的欄數(shù),X軸包含從表單中接收的行數(shù)
<% Redim Preserve theArray(4,intTableRows) %>
-------------------------------------------------------------------------------------------------------------------------------------

開(kāi)始檢查所有的表單行.在所有輸入的網(wǎng)頁(yè)表單域中循環(huán),收集每個(gè)表單域名及其相應(yīng)的值.逐個(gè)檢查并將其放入相應(yīng)的數(shù)列元素內(nèi).在此,我們使用了不確定編碼的CASE選擇
<%
For intCount = 0 to frmData.fieldCount.value
  strOkay = "Y"
  strSearch = frmData.elements(intCount).name 

' 裝入表單域名.
  strValue = frmData.elements(intCount).value 

' 裝入表單域值.
  strPosition = Instr(1,strSearch,"_")         

intStringLen=strPosition-1
  If intStrLen > 0 Then
      strLeft = Left(strSearch,intStringLen)
      strRight = Right(strSearch,(Len(strSearch)-Len(strLeft)-1))
      Select Case strLeft

' Select Case命令決定表單域?qū)儆谀囊涣?/SPAN>.
        Case "SKU"                       intArrayY=0
        Case "description"                 intArrayY=1
        Case "price"                       intArrayY=2
        Case "quantity"                    intArrayY=3
      End Select
      IntArrayX = strRight
      If strOkay <> "N" Then
        TheArray(intArrayY, intArrayX) = strValue
      End If
  End If
Next
%>

-------------------------------------------------------------------------------------------------------------------------------------

開(kāi)始創(chuàng)建文件
<%
    Set rngCurrent = objWordDoc.Application.ActiveDocument.Content

' 對(duì)于激活的文件,用變量rngCurrent設(shè)置Word文件對(duì)象RANGE,這是為了防止用戶打開(kāi)另一個(gè)文件.
    Set tabCurrent =  ObjWordDoc.Application.ActiveDocument.Tables.Add
    rngCurrent,intNumrows,4)

   ' 通過(guò)指定表格的位置( rngCurrent)以及行、列的數(shù)目來(lái)確定其大小.

%>

------------------------------------------------------------------------------------------------------------------------------------  
向往表格里裝入數(shù)據(jù).

<%
For j = 1 to intTableRows
 '
首先指到第一行row(tabRow=1), 逐行循環(huán).在每行結(jié)尾處插入回車[Chr(10)],以產(chǎn)生行間空行,使行計(jì)數(shù)器增加.
ObjWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Borders.Enable=False

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Range.InsertAfter
    theArray(1,j)

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(2).Range.InsertAfter
    theArray(2,j)

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).Range.InsertAfter
    FormatCurrency(theArray(3,j))
    '
FormatCurrency 輸出美圓值以保證使用$符號(hào),逗號(hào),小數(shù)點(diǎn)的位置.

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range.InsertAfter
    theArray(4,j)

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range.InsertAfter
    Chr(10)

objWordDoc.Applicatoin.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).
    Range.ParagraphFormat.alignment=2
    ' 
ParagraphFormat. alignment=2處設(shè)置欄數(shù)來(lái)實(shí)現(xiàn)美圓數(shù)量的正確調(diào)整.

tabRow = tabRow + 1

Next
%>

------------------------------------------------------------------------------------------------------------------------------------
指定模板位置,結(jié)束子程序
<%
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.
    InsertAfter("Thank you for shopping at Acme Co., and please come again!")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter(" ")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter(" ")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter("Regards,")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter(" ")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.
  InsertAfter("Daryl B. Morticum")
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.
  InsertAfter("Sales Associate")
End Sub
%>

------------------------------------------------------------------------------------------------------------------------------------

 

 

 

相關(guān)文章

最新評(píng)論