用asp怎么生成word的表格?

谢谢

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

你建一个table ,让其id为data

下面是导出到Word代码:

1<input class="notPrint" name="out_word" onclick="vbscript:buildDoc" type="hidden" value="导出到word"/>
 1<script language="vbscript">   
 2Sub buildDoc   
 3set table = document.all.data   
 4row = table.rows.length   
 5column = table.rows(1).cells.length   
 6  
 7Set objWordDoc = CreateObject("Word.Document")   
 8  
 9'objWordDoc.Application.Documents.Add theTemplate, False   
10objWordDoc.Application.Visible=True   
11  
12Dim theArray(20,10000)   
13for i=0 to row-1   
14for j=0 to column-1   
15theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT   
16next   
17next   
18objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("综合查询结果集") //显示表格标题   
19  
20objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")   
21Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range   
22With rngPara   
23.Bold = True //将标题设为粗体   
24.ParagraphFormat.Alignment = 1 //将标题居中   
25.Font.Name = "隶书" //设定标题字体   
26.Font.Size = 18 //设定标题字体大小   
27End With   
28Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range   
29Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)   
30  
31for i = 1 to column   
32  
33objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)   
34objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1   
35next   
36For i =1 to column   
37For j = 2 to row   
38objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)   
39objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1   
40Next   
41Next   
42  
43End Sub   
44</script>
Published At
Categories with Web编程
comments powered by Disqus