jsはexcelを導入してwordを導出して、jsは印刷します.
6182 ワード
<html>
<head>
<style media=print mce_bogus="1"> .Noprint{display:none;} .PageNext{page-break-after:always;} </style>
</head>
<script language="javascript" type="text/javascript">
Ext.onReady(function(){
var data=[ [1, 'EasyJWeb', 'EasyJF','rokr.iteye.com'],
[2, 'rokr', 'rokr','rokr.iteye.com'],
[3, 'rokr', 'rokr','rokr.iteye.com'],
[4, 'rokr', 'rokr','rokr.iteye.com'] ];
var sm=new Ext.grid.CheckboxSelectionModel();
var store=new Ext.data.SimpleStore({data:data,fields:["id","name","rokr","rokr"]});
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"rokr.iteye.com",
height:150,
width:600,
columns:[sm,{header:" ",dataIndex:"name"},
{header:" ",dataIndex:"organization"},
{header:" ",dataIndex:"homepage"}],
sm:sm,
store:store,
autoExpandColumn:2
});
});
</script>
<body >
<br />
<div id="hello"></div>
<br/><br>
<div id="newTable" style="font-size:12px;" ></div>
<br><br>
<span class="Noprint">
<input type="button" onClick="javascript:AllAreaExcel();" value=" Excel">
<input type="button" onClick="javascript:OpenWord();" value=" Word">
<input type=button value= onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value= onclick=document.all.WebBrowser.ExecWB(8,1)>
<input name=Button onclick=document.all.WebBrowser.ExecWB(7,1) type="button" value=" ">
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input type="file" name="file" id="file"/>
<input type="button" id="excelimport" name="excelimport" value="Excel " onClick="javascript:readExcel()" />
</span>
</div>
<script language="javascript" type="text/javascript">
function readExcel()
{
if(document.getElementById("file").value.split(".")[1]=="xls"){
var oXL = new ActiveXObject("Excel.Application");
try{
var oWB = oXL.Workbooks.open(document.getElementById("file").value);
}catch(e){
alert(' !');
}
var oSheet = oWB.ActiveSheet;
var table=document.createElement("table");
table.setAttribute("border","1");
table.setAttribute("cellpadding","0");
table.setAttribute("cellspacing","0");
table.setAttribute("border-collapse","collapse");
table.setAttribute("width","60%");
//table.setAttribute("style-fontSize","12");
table.setAttribute("id","mytable");
document.body.appendChild(table);
for(var i=0;i<oSheet.usedrange.rows.count;i++){
var row=table.insertRow(i);
for(var j=0;j<(oSheet.usedrange.cells.count/oSheet.usedrange.rows.count);j++){
//oSheet.Cells(i,j).Font.Size = 10;
//alert(oSheet.Cells(i+1,j+1).value);
if(oSheet.Cells(i+1,j+1).value==null){
row.insertCell(j).appendChild(document.createTextNode(""));
}
else{
row.insertCell(j).appendChild(document.createTextNode(oSheet.Cells(i+1,j+1).value));
}
}
}
var div=document.getElementById("newTable");
div.appendChild(table);
//alert(oSheet.Rows.rows);
// alert(oSheet.Cells(1,1).value);//cell
// alert(oSheet.usedrange.cells.count);//cell
// alert(oSheet.usedrange.rows.count);//
// alert(oWB.Worksheets.count);// sheet
oSheet=null;
oWB.close();
oXL=null;
}else{
if(document.getElementById("file").value==""){
window.alert(" Excel ");
return false;
}else{
window.alert(" Excel ");
return false;
}
}
}
// Excel
function AllAreaExcel()
{
// Excel
var oXL = new ActiveXObject("Excel.Application");
//var oXL = createOXL();
// workbook
var oWB = oXL.Workbooks.Add();
// sheet
var oSheet = oWB.ActiveSheet;
//oSheet.Cells(1,1).Font.Size = 30;
var sel=document.body.createTextRange();
// TextRange
sel.moveToElementText(hello);
// TextRange
sel.select();
// TextRange
sel.execCommand("Copy");
// EXCEL
oSheet.Paste();
// excel
oXL.Visible = true;
//oXL.Quit();
}
// word
function OpenWord(){
var ExcelSheet = new ActiveXObject('word.Application');
// Excel Application 。
ExcelSheet.Application.Visible = true;
var orgNum=ExcelSheet.Documents.Add("",0,1);
var myRange =orgNum.Range(0,1)
var sel=document.body.createTextRange();
var oTblExport =document.getElementById("hello");
if (oTblExport != null) {
sel.moveToElementText(oTblExport);
sel.execCommand('Copy');
document.body.blur();
myRange.Paste();
}
//window.close();
//ExcelSheet.Application.Quit();
}
</script>
</body>
</html>