<html>
<body>
<h1>JavaScript 生成表格</h1>
<h2>行:<input id=mrow type=number/>
列:<input id=mcolumn type=number/>
<input type="button" value="生成表格" onclick="gettable()" /></h2>
<hr/>
<p id="demo"></p>
<script type="text/javascript">
function gettable()
{
mrow=document.getElementById("mrow").value
mcolumn=document.getElementById("mcolumn").value
mytable="<table border=1>"
for (i = 0i <mrowi++) {
mytable += "<tr>"
for(j=0j<mcolumnj++){
mytable+="<td>"+"第"+(i+1)+"行 第"+(j+1)+"列"+"</td>"
}
mytable += "</tr>"
}
mytable+="</table>"
document.getElementById("demo").innerHTML=mytable
}
</script>
</body>
</html>
GetDataFromExcelPagevar idTmr = ""
function InertDataFromExcelToDataBase()
{
var vsFilePath=document.all("InputExcel").value
if( vsFilePath == undefined || vsFilePath == null || vsFilePath == "undefined"
|| vsFilePath == "" || vsFilePath.toUpperCase().indexOf('.XLS') == -1)
{
alert("please choose the excel file !")
return false
}
//创建Excel程序对象
var vsExcel = ""
try
{
vsExcel = new ActiveXObject("Excel.Application")
}
catch(err)
{
alert(err.description)
return false
}
//打开
var vsBook = vsExcel.Workbooks.Open(vsFilePath)
//Excel的第一张表格
var vsSheet = vsBook.Worksheets(1)
vsSheet.Select()
//6行
for(var i=1i<7i++)
{
//2列
for(var j=1j<3j++)
{
//单元格取值
alert(vsSheet.Cells(i,j).value)
}
}
/*可以如下写法,但是Excel默认的行和列都很大的,好几万呢:)
for(var i=1i
{
for(var j=1j
{
alert(vsSheet.Cells(i,j).value)
}
}
*/
vsSheet=null
vsBook=null
//退出
vsExcel.Quit()
vsExcel = null
//GarbageCollection
idTmr = window.setInterval("Cleanup()",1)
return false
}
function InsertDataFromWordToDataBase()
{
var vsFilePath=document.all("InputWord").value
if( vsFilePath == undefined || vsFilePath == null
|| vsFilePath == "undefined" || vsFilePath == "" || vsFilePath.toUpperCase().indexOf('.DOC') == -1)
{
alert("please choose the word file !")
return false
}
//创建Word对象
try
{
var vsWordApp = new ActiveXObject("Word.Application")
}
catch(err)
{
alert(err.description)
return false
}
//打开Word文档
var wordInfo = vsWordApp.Documents.Open(vsFilePath)
/* 其他的一些属性
word (index)
Range对象
characters (index)
Range对象
sentences (index)
Range对象
paragraphs (index)
Paragraph对象
sections (index)
Section对象
*/
//不可见
vsWordApp.Visible = false
//需要关闭其他word文档,防止出现读取其他文档情况
/*
//逐个字符读取整个文档
var characters = vsWordApp.documents(1).characters
for(var i=1i
{
alert(characters(i).text)
//alert(vsWordApp.Application.Selection)
//移动一个单元,宽度为1(无论是汉字还是英文字母)
//vsWordApp.Application.Selection.MoveRight(Unit=1,Count=1)
}
//逐个字读取整个文档
var words = vsWordApp.documents(1).words
for(var i=1i<=words.counti++)
{
alert(words(i).text)
}
*/
//逐个段落读取整个文档
var paragraphs = vsWordApp.documents(1).paragraphs
for(var i=1i<=paragraphs.counti++)
{
alert(paragraphs(i).range.text)
}
vsWordApp = null
//关闭
wordInfo.Close()
wordInfo = null
//GarbageCollection
idTmr = window.setInterval("Cleanup()",1)
return false
}
function InsertDataFromXMLToDataBase()
{
var vsFilePath=document.all("InputXML").value
if( vsFilePath == undefined || vsFilePath == null
|| vsFilePath == "undefined" || vsFilePath == "" || vsFilePath.toUpperCase().indexOf('.XML') == -1)
{
alert("please choose the xml file !")
return false
}
var vsXMLApp = ""
//创建XML对象
try
{
vsXMLApp = new ActiveXObject("Microsoft.XMLDOM")
}
catch(err)
{
alert(err.description)
return false
}
vsXMLApp.async = true
vsXMLApp.resolveExternals = false
//打开
vsXMLApp.load(vsFilePath)
//取得跟节点下面所有子节点集合
var nodes = vsXMLApp.documentElement.childNodes
for( var i = 0i <nodes.length i++ )
{
//对每个子节点取得标记集合
var nodeInfo = nodes[i].getElementsByTagName_r("RecordsetInfo").context.attributes
for(var j=0j
{
//每个标记的值
alert(nodeInfo[j].nodeValue)
}
}
//vsXMLApp.Close()
vsXMLApp = null
//GarbageCollection
idTmr = window.setInterval("Cleanup()",1)
return false
}
function Cleanup()
{
window.clearInterval(idTmr)
CollectGarbage()
}