javascript 작업 Word 와 Excel 의 실현 코드

***********************************************************************************************************************************************************************************************************************************************************************************************
 
<HTML>
<HEAD>
<title>
</title>
</HEAD>
<body>
<form id="form">
<table id = "PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" >
<TR style="text-align : center;">
<TD> 1</TD>
<TD> 2</TD>
<TD> 3</TD>
<TD> 4</TD>
</TR>
<TR>
<TD colSpan=4 style="text-align : center;"><font color="red" face="Verdana"> </FONT></TD>
</TR>
</TABLE>
<BR>
<table id = "Test" width="100%">
<tr>
<td><font color="red">test</FONT></td>
</tr>
</table>
</form>
<input type="button" onclick="javascript:MakeWord();" value=" Word">
<SCRIPT LANGUAGE="javascript">
function MakeWord()
{
var word = new ActiveXObject("Word.Application");
// var doc = word .documents.open("c:\test.doc"); //
var doc = word .Documents.Add("",0,1);//
var Range=doc.Range();

var sel = document.body.createTextRange();
sel.moveToElementText(form);// form form id
sel.select();
sel.execCommand("Copy");
Range.Paste();
word .Application.Visible = true;
alert("s");
word.Application.Selection.InlineShapes.AddPicture("c:\\m20.gif");
alert("n");
doc .saveAs("c:\\ba.doc"); // “\\”
}
</SCRIPT>
</body>
</html>
2、**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
 

<script>
function wordcontorl(){
alert("1111")
var WordApp=new ActiveXObject("Word.Application");

var wdCharacter=1
var wdOrientLandscape = 1
WordApp.Application.Visible=true;
var myDoc=WordApp.Documents.Add();

WordApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape

WordApp. Selection.ParagraphFormat.Alignment=1 //1 ,0
WordApp. Selection.Font.Bold=true
WordApp. Selection.Font.Size=20

WordApp. Selection.TypeText(" ");
WordApp. Selection.MoveRight(wdCharacter);    //
WordApp.Selection.TypeParagraph()         //
WordApp. Selection.Font.Size=12
WordApp. Selection.TypeText(" "); //
WordApp.Selection.TypeParagraph()         //



var myTable=myDoc.Tables.Add (WordApp.Selection.Range, 8,7) //8 7
//myTable.Style=" "
var aa = " "

var TableRange; //
for (i= 0;i<7;i++)
{
with (myTable.Cell(1,i+1).Range)
{
font.Size = 12;
InsertAfter(aa);
ColumnWidth =4
}
}

for (i =0;i<7;i++)
{
for (n =0;n<7 ;n++)
{

with (myTable.Cell(i+2,n+1).Range)
{font.Size = 12;
InsertAfter("bbbb");
}
}
}
row_count = 0;
col_count = 0
myDoc.Protect(1)
}
wordcontorl()
</script>

좋은 웹페이지 즐겨찾기