〈%
For intCount = 0 to frmData.fieldCount.value
strOkay = "Y"
strSearch = frmData.elements(intCount).name 'load the field name
strValue = frmData.elements(intCount).value 'load the field value
strPosition = Instr(1,strSearch,"_") 'get pos val of "_"
intStringLen=strPosition-1
If intStrLen > 0 Then
strLeft = Left(strSearch,intStringLen)
strRight = Right(strSearch,(Len(strSearch)-Len(strLeft)-1))
Select Case strLeft
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
%>
现在开始创建文件。对于激活的文件,用变量rngCurrent设置Microsoft Word文件对象RANGE(为了防止用户打开另一个文件),通过指定表格的位置( rngCurrent)以及行、列的数目来确定其大小。
〈%
Set rngCurrent = objWordDoc.Application.ActiveDocument.Content
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add
rngCurrent,intNumrows,4)
%>
创建了有表格的文件之后,我们开始往表格中装入数据。首先指到第一行row(tabRow=1 ), 然后进行逐行循环。在每行结尾处插入回车[Chr(10)],以便产生行间空行,最后增加行计数器,用“FormatCurrency” 输出美圆值以保证使用$符号、逗号、小数点的位置。通过在
“ParagraphAlignment=2”处设置栏数来实现美圆数量的正确调整。用VBA容易一些,不象用VBScript那样难。
〈%
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
%>
<SCRIPT LANGUAGE="JavaScript">
<!--
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var table = document.all.data;
var hang = table.rows.length;
var lie = table.rows(0).cells.length;
// Add table headers going cell by cell.
for (i=0;i<hang;i++)
{
for (j=0;j<lie;j++)
{
oSheet.Cells(i+1,j+1).Value = table.rows(i).cells(j).innerText;
}
Dim theArray(20,10000)
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("综合查询结果集") //显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
With rngPara
.Bold = True //将标题设为粗体
.ParagraphFormat.Alignment = 1 //将标题居中
.Font.Name = "隶书" //设定标题字体
.Font.Size = 18 //设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
'declare all variables
Dim objWord
Dim oDoc
Dim objFso
Dim colFiles
Dim curFile
Dim curFileName
Dim folderToScanExists
Dim folderToSaveExists
Dim objFolderToScan
'set some of the variables
folderToScanExists = False
folderToSaveExists = False
Const wdSaveFormat = 10 'for Filtered HTML output
'********************************************
'change the following to fit your system
Const folderToScan = "C:\Word\documentation\"
Const folderToSave = "C:\Inetpub\wwwroot\word\"
'********************************************
'Use FSO to see if the folders to read from
'and write to both exist.
'If they do, then set both flags to TRUE,
'and proceed with the function
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(folderToScan) Then
folderToScanExists = True
Else
MsgBox "Folder to scan from does not exist!", 48, "File System Error"
End If
If objFso.FolderExists(folderToSave) Then
folderToSaveExists = True
Else
MsgBox "Folder to copy to does not exist!", 48, "File System Error"
End If
If (folderToScanExists And folderToSaveExists) Then
'get your folder to scan
Set objFolderToScan = objFso.GetFolder(folderToScan)
'put al the files under it in a collection
Set colFiles = objFolderToScan.Files
'create an instance of Word
Set objWord = CreateObject("Word.Application")
If objWord Is Nothing Then
MsgBox "Couldn't start Word.", 48, "Application Start Error"
Else
'for each file
For Each curFile in colFiles
'only if the file is of type DOC
If (objFso.GetExtensionName(curFile) = "doc") Then
'get the filename without extension
curFileName = curFile.Name
curFileName = Mid(curFileName, 1, InStrRev(curFileName, ".") - 1)
'open the file inside Word
objWord.Documents.Open objFso.GetAbsolutePathName(curFile)
'do all this in the background
objWord.Visible = False
'create a new document and save it as Filtered HTML
Set oDoc = objWord.ActiveDocument
oDoc.SaveAs folderToSave & curFileName & ".htm", wdSaveFormat
oDoc.Close
Set oDoc = Nothing
End If
Next
End If
'close Word
objWord.Quit
'set all objects and collections to nothing
Set objWord = Nothing
Set colFiles = Nothing
Set objFolderToScan = Nothing
End If
<%Set objWordApp = CreateObject("Word.Application")
Set objWordDoc = objWordApp.Documents.Add
objWordApp.Visible = True
Set objWordApp = Nothing
Set objParagraph = objWordDoc.Paragraphs.Add
Set objRange = objParagraph.Range
With objRange
.InsertBefore "哈哈哈"
.ParagraphFormat.Alignment = 1
.Bold = True
.Font.Name = "隶书" //设定标题字体
.Font.Size = 15
End With
Set objRange = Nothing
Set objParagraph = Nothing
Set objParagraph = objWordDoc.Paragraphs.Add
Set objRange = objParagraph.Range
objRange.InsertBefore ("")
Set objTable = objWordDoc.Tables.Add(objRange, row, col)
Set objRange = Nothing
Set objParagraph = Nothing
%>