当前位置:首页 >> 互联网 >>

怎样把网页中的表格转换为Word文档?

怎样把网页中的表格转换为 Word 文档?

用下面的办法转换即可: <Table id="myData" border=1 align=center> <Tr align=center> <Td>表格转换</Td> <Td>表格转换</Td> <Td>表格转换</Td> <Td>表格转换</Td> </Tr> <Tr align=center> <Td>表格转换</Td> <Td>表格转换</Td> <Td align=right>表格转换</Td> <Td>表格转换</Td> </Tr> <Tr align=center> <Td>表格转换</Td> <Td>表格转换</Td> <Td align=right>表格转换</Td> <Td>表格转换</Td> </Tr> <Tr align=center> <Td>表格转换</Td> <Td>表格转换</Td> <Td align=right>表格转换</Td> <Td>表格转换</Td> </Tr> </Table> <center><input type=button onclick="vbscript:buildDoc '',4" value="转换成 Word 文档"><script language="vbscript"> Sub buildDoc(theTemplate,intTableRows) Dim Table1 set Table1 = document.all.myData row = Table1.rows.length Set objWordDoc = CreateObject("Word.Document") ObjWordDoc.Application.Visible=True Dim theArray(4,4) 'Redim Preserve theArray(4,row) colnum = Table1.rows(1).cells.length for i=0 to row-1 for j=0 to colnum-1

theArray(j+1,i+1) = Table1.rows(i).cells(j).innerHTML next next intNumrows = 4 objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore(" 转换后的表格") 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 = "Arial" .Font.Size = 12 End With Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,intNumrows,4) for i = 1 to colnum objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.Inse rtAfter theArray(i,1) objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.Par agraphFormat.alignment=1 next tabRow = 2 For j = 2 to intNumrows 'ObjWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Borders.En able=False objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Ran ge.InsertAfter theArray(1,j) objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Ran ge.ParagraphFormat.alignment=1 objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(2).Ran ge.InsertAfter theArray(2,j) objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(2).Ran ge.ParagraphFormat.alignment=1

objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).Ran ge.InsertAfter FormatCurrency(theArray(3,j)) objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(3).Ran ge.ParagraphFormat.alignment=2 objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Ran ge.InsertAfter theArray(4,j) objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Ran ge.InsertAfter Chr(10) objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Ran ge.ParagraphFormat.alignment=1 tabRow = tabRow + 1 Next objWordDoc.Application.ActiveDocument.SaveAs "tempSample.doc", 0,False,"",True,"",False,False,False, False,False objWordDoc.Application.printout()

End Sub </script>