javascript中直接引用Microsoft的COM生成Word
更新時間:2014年01月20日 16:44:31 作者:
直接引用Microsoft的COM是可以生成Word的,下面為大家介紹下實現(xiàn)的javascript代碼
復制代碼 代碼如下:
<html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<title>Build Document by Script</TITLE>
<SCRIPT LANGUAGE="text/javascript">
function word_onclick()
{
var myDocApp=null;
myDocApp =new ActiveXObject("word.Application");
myDocApp.Application.Visible = true;
var myDoc = myDocApp.Documents.Add();
myDocApp.Selection.ParagraphFormat.Alignment=1
myDocApp.Selection.Range.Bold=true;
myDocApp.Selection.Font.Size=22;
myDocApp.Selection.Text="請假申請單"
myDocApp.Selection.insertAfter("\n");
myDocApp.Selection.MoveRight(2,10);
myDocApp.Selection.TypeParagraph();
myDocApp.Selection.Font.Bold=false;
myDocApp.Selection.Font.Size=12;
var myTable0=myDoc.Tables.Add(myDocApp.Selection.Range,3,4);
myTable0.cell(1,1).Range.Text="請假人";
myTable0.cell(1,2).Range.Text="張三";
myTable0.cell(1,3).Range.Text="請假時間";
myTable0.cell(1,4).Range.Text="2006-2-10";
myTable0.cell(2,1).Range.Text="工號";
myTable0.cell(2,2).Range.Text="32412";
myTable0.cell(2,3).Range.Text="填表時間";
myTable0.cell(2,4).Range.Text="2006-2-9";
myTable0.cell(3,1).Range.Text="請假原因";
myTable0.cell(3,2).Range.Text="感冒";
myTable0.cell(3,3).Range.Text="處理方式";
myTable0.cell(3,4).Range.Text="病假";
var range=myDocApp.ActiveDocument.Content;
range.Collapse(0);
range.insertAfter("\n");
range=myDocApp.ActiveDocument.Content;
range.Collapse(0);
var myTable2=myDoc.Tables.Add(range,1,2);
myTable2.Columns(1).SetWidth(320,2);
myTable2.cell(1,1).Range.Text="申請人簽名" //空格勿刪
myTable2.cell(1,2).Range.Text="申請人的簽名";
try{
myDocApp.ActiveDocument.SaveAs("e:\\JaveToWord.doc");
}catch(exception){
alert("瀏覽器安全設置過高,保存文件到本地失敗");
myDocApp.Documents.close();
myDocApp.Application.quit();
myDocApp=null;
window.close();
}
}
</SCRIPT>
</HEAD>
<BODY>
<p><a href="javascript:word_onclick()">生成WORD</a></p>
</BODY>
</HTML>
您可能感興趣的文章:
相關文章
javascript的trim,ltrim,rtrim自定義函數(shù)
今天用到javascript去掉一個文本框中字符串兩端的空格,開始還以為有trim,ltrim,rtrim函數(shù)(asp中有這三個函數(shù),弄混了),結果找半天,沒有找到。最后找到用正則實現(xiàn)這樣功能的自定義函數(shù)。2008-09-09javascript數(shù)字格式化通用類 accounting.js使用
accounting.js 是一個非常小的JavaScript方法庫用于對數(shù)字,金額和貨幣進行格式化。并提供可選的Excel風格列渲染。它沒有依賴任何JS框架。貨幣符號等可以按需求進行定制2012-08-08Flutter 超實用簡單菜單彈出框 PopupMenuButton功能
這篇文章主要介紹了Flutter 超實用簡單菜單彈出框 PopupMenuButton功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08微信小程序 bindtap 事件多參數(shù)傳遞的代碼示例
在微信小程序中,我們無法直接通過 bindtap="handleClick(1,2,3)" 的方式傳遞參數(shù),而是通過自定義屬性data- 的方式傳遞,并在事件回調(diào)函數(shù)中通過event.currentTarget.dataset獲取這些參數(shù),本文給大家介紹小程序 bindtap 事件多參數(shù)傳遞的實例代碼,感興趣的朋友一起看看吧2023-12-12