CSDN博客

img aspczlover

将浏览器表格导入到word

发表于2004/10/2 5:04:00  522人阅读

分类: asp和应用程序

<input type="button" name="out_word" onclick="vbscript:buildDoc(data)" value="导出到word" class="notPrint">
<%
%>

<SCRIPT LANGUAGE=VBScript>
<!--
Private Sub buildDoc(tbl)
    Dim objWordApp
    Dim objWordDoc
    Dim objParagraph
    Dim objRange
    Dim objTable
    Dim row, col
    Dim i, j

    row = tbl.rows.length
    col = tbl.rows.item(0).cells.length
    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
   
    For i = 1 To row
        For j = 1 To col
            objTable.Cell(i, j).Range.Text = tbl.rows.item(i-1).cells.item(j-1).innerText
        Next
    Next
    Set objTable = Nothing
    Set objWordDoc = Nothing
End Sub
//-->
</SCRIPT>
<table id="data" width="200" border="1">
  <tr>
    <td>11</td>
    <td>11</td>
  </tr>
  <tr>
    <td>22</td>
    <td>22</td>
  </tr>
  <tr>
    <td>33</td>
    <td>33</td>
  </tr>
  <tr>
    <td>44 </td>
    <td>44</td>
  </tr>
</table>

阅读全文
0 0

相关文章推荐

img
取 消
img