免費 WebOffice使用


 目前WebOffice使用比較多主要有兩個公司的產品,分別是江西金格和北京點聚。但是點聚的是免費的,雖然有欠缺之處,但是經過個人修改還是比較好用的,關鍵一點是,它免費啊!

      把一個最主要加載頁面,如果讀懂了這個頁面的使用,其他的相當就好理解了。

      (如果需要組件和源碼的給我留言)

     

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DocEdit.aspx.cs" Inherits="DocEdit" %>
<%@ Import Namespace="System.Data.OleDb"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>編輯正文</title>
    <!-- 編輯控件主要集中在此頁面 -->
</head>
<body>
    <form name="myform" action="#" method="post">
      <% //獲取服務器的地址
        string URL = this.Session["URL"].ToString();
        string ID;
        string DocType;
        string DocTitle = "";
        //起草文件,則ID為NULL,否則為記錄的主鍵
        ID = Request.QueryString["ID"];
        if (ID == null || ID == "")
        {
            //獲取新建文件的類型        
            DocType = Request.Form["DocType"];
        }
        else
        {
            //獲取DocTitle
            DocTitle = Request.QueryString["DocTitle"];
            //獲取文件的 類型      
            DocType = Request.QueryString["DocType"];
        }
      
          //默認為word文檔,如果異常進入則按word處理,組織部基本處理的都是word
        if (DocType == null || DocType == "")
        {
            DocType = "doc";
        }
 %> 
     <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
          <TR>
            <TD bgColor=#3366cc><IMG height=1 alt="" width=1></TD>
          </TR>
    </TABLE>

   <table style="width: 100%" border = "0" cellpadding="0" cellspacing="0">
       <tr>
           <td valign="top" bgColor="#e5ecf9" style="height: 21px;"><p align="left"><b><strong>WebOffice演示</strong></b>
    </p></td>
       </tr>
   </table>
   <br /> <br />
    <table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#3366cc">

    <tr bgcolor="#FFFFFF">
        <td bgcolor="#ffffff" rowspan="2">
            <div align="center"><strong>標題</strong></div>
        </td>
        <td rowspan="2">
            <input name="DocTitle" value= "<%if(DocTitle=="" ) {Response.Write("text");} else {Response.Write(DocTitle);} %>" size="14" id="Text1"/></td>
    <td  rowspan="2" >
              &nbsp; &nbsp;<input name="DocFilePath" type="file" size="34" />
       <input type="button" value="打開本地文件" onclick="return docOpen()" id="Button1" style="width: 115px" /></td>
    <td rowspan="2" bgcolor="#FFFFFF" style="width: 344px"><div align="center">
      <input type="button" class="btn" value="顯示最終文稿" onclick="return UnShowRevisions()" />
            <input type="button"  value="從服務器下載"  onclick="return WebOffice1_NotifyCtrlReady()" style="width: 96px"/>
            <input type="button"  value="上傳到服務器"  onclick="return SaveDoc()" style="width: 98px"/>
              <input type="button" style="display:none" value="返回"  onclick="return return_onclick()"/></div></td>
    </tr>

    <tr bgcolor="#FFFFFF">
 </tr>

    <tr bgcolor="#FFFFFF">
   <td valign="top" bgcolor="#FFFFFF" style="height: 560px">
  <!-- -------------------===  Start 嵌套Table ===------------------------------- -->
  <table width="100%"  border="0" cellpadding="0">

          <tr>
            <td  class="maintxt">用戶名:<br />
              <input name="UserName" type="text" value="Test" style="width:74px;" maxlength="10" /><br />
                <input type="button" value="設置用戶"  onclick="return SetUserName()" class="btn" /></td>
    </tr>

          <tr><td class="maintxt">
   <hr  size="1" />保護密碼:<br />
              <input name="docPwd" type="text" value="Password" style="width:74px;" maxlength="10" /><br />
       <input type="button" class="btn" value="保護文檔" onclick="return ProtectFull()" /></td>
    </tr>

          <tr><td><input type="button" class="btn" value="解除保護" onclick="return UnProtect()" /></td></tr>

          <tr><td>
   <hr  size="1" />
     <input  type="button" class="btn" value="修訂文檔" onclick="return ProtectRevision()" /></td>
    </tr>

          <tr><td><input type="button" class="btn" value="顯示修訂" onclick="return ShowRevisions()" /></td></tr>
          <tr><td><input type="button" class="btn" value="隱藏修訂" onclick="return UnShowRevisions()" /></td></tr>
          <tr><td><input type="button" class="btn" value="接受修訂" onclick="return AcceptAllRevisions()" /></td></tr>

          <tr><td>
   <hr size="1" />
             <input  type="button" class="btn" value="設置書簽" onclick="return addBookmark()" /></td>
       </tr>

          <tr>
              <td rowspan="4">
                  <input  type="button" class="btn" value="套加紅頭" onclick="return addRedHead()" /></td>
          </tr>
        </table>
     <!-- -------------------=== End 嵌套Table ===------------------------------- -->
                <select id="Select1" name="select" style="width: 83px">
                    <option selected="selected" value="<%=URL %>/template/tmp1.doc">部模板1</option>
                    <option value="<%=URL %>/template/tmp2.doc">市模板1</option>
                    <option value="<%=URL %>/template/tmp3.doc">縣模板1</option>
                </select>
            </td>

   <td colspan="3" valign="top" style="height: 560px">
  <!-- -----------------------------== 裝載weboffice控件 ==----------------------------------->  
    <script src="LoadWebOffice.js"></script>
        <!-- --------------------------------==  結束裝載控件 ==------------------------------------->
   </td>
    </tr>
  </table>
  <br />  <br />
          <table style="width: 100%" border = "0" cellpadding="0" cellspacing="0">
               <tr>
                   <td valign="top" bgColor="#e5ecf9" ><span style="color: red">服務器地址:<%=this.Session["URL"].ToString() %> </span>
                </td>
               </tr>
           </table>
          <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
          <TR>
            <TD bgColor=#3366cc><IMG height=1 alt="" width=1></TD>
          </TR>
    </TABLE>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
// ---------------------== 關閉頁面時調用此函數,關閉文檔--------------------- //
function window_onunload() {
 document.all.WebOffice1.Close();
}
 
// ---------------------------== 解除文檔保護 ==---------------------------------- //
function UnProtect() {
 document.all.WebOffice1.ProtectDoc(0,1, myform.docPwd.value);
}

// ---------------------------== 設置文檔保護 ==---------------------------------- //
function ProtectFull() {
 document.all.WebOffice1.ProtectDoc(1,1, myform.docPwd.value);
}
// -----------------------------== 修訂文檔 ==------------------------------------ //
function ProtectRevision() {
 document.all.WebOffice1.SetTrackRevisions(1)
}

// -----------------------------== 隱藏修訂 ==------------------------------------ //
function UnShowRevisions() {
 document.all.WebOffice1.ShowRevisions(0);
}

// --------------------------== 顯示當前修訂 ==---------------------------------- //
function ShowRevisions() {
 document.all.WebOffice1.ShowRevisions(1);

}

// -------------------------== 接受當前所有修訂 ------------------------------ //
function AcceptAllRevisions() {
  document.all.WebOffice1.SetTrackRevisions(4);
}

// ---------------------------== 設置當前操作用戶 ==------------------------------- //
function SetUserName() {
 if(myform.UserName.value ==""){
  alert("用戶名不能為空");
  myform.UserName.focus();
  return false;
 }
  document.all.WebOffice1.SetCurrUserName(myform.UserName.value);
}

// -------------------------=== 設置書簽套加紅頭 ===------------------------------ //
function addBookmark() {
 document.all.WebOffice1.SetFieldValue("mark_1", "安徽省委組織部紅頭文件::ADDMARK::");     
}

// -------------------------=== 設置書簽套加紅頭 ===------------------------------ //
function addRedHead() {
    if(document.getElementById("Select1").value == "")//判斷是否選擇模板
    {
    alert("請選擇模板!")
    return false;
    }
   
    document.all.WebOffice1.SetFieldValue("mark_1", "", "::ADDMARK::");   // 添加書簽
 document.all.WebOffice1.SetFieldValue("mark_1", document.getElementById("Select1").value, "::FILE::");
}

// -----------------------------== 返回首頁 ==------------------------------------ //
function return_onclick() {
 document.all.WebOffice1.Close();
 window.location.href  = "Default.aspx"
}
// 打開本地文件
function docOpen() {
    //alert(myform.DocFilePath.value)
 if(myform.DocFilePath.value == "") {
  alert("文件路徑不可以為空");
  myform.DocFilePath.focus();
  return false;
 }
 var flag;
 //LoadOriginalFile接口裝載文件

 flag = document.all.WebOffice1.LoadOriginalFile(myform.DocFilePath.value,"<%=DocType%>");
 if( 0 == flag){
  alert("文件打開失敗,請檢查路徑是否正確");
  myform.DocFilePath.focus();
  return false;
 } 
}
 
// -----------------------------== 保存文檔 ==------------------------------------ //
function SaveDoc() {
  if(myform.DocTitle.value ==""){
  alert("標題不可為空")
  myform.DocTitle.focus();
  return false;
 }
 //恢復被屏蔽的菜單項和快捷鍵
    document.all.WebOffice1.SetToolBarButton2("Standard",1,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",2,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",3,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",6,3);          
    <%if (DocType   == "doc") {%>
        //恢復文件菜單項
        document.all.WebOffice1.SetToolBarButton2("Menu Bar",1,4);
        //恢復 保存快捷鍵(Ctrl+S)
        document.all.WebOffice1.SetKeyCtrl(595,0,0);
        //恢復 打印快捷鍵(Ctrl+P)
        document.all.WebOffice1.SetKeyCtrl(592,0,0);
    <%}else if(DocType   == "xls") {%>
        //恢復文件菜單項
        document.all.WebOffice1.SetToolBarButton2("Worksheet Menu Bar",1,4);        
    <%} %>
//初始化Http引擎
 document.all.WebOffice1.HttpInit();   
//添加相應的Post元素
 <%
 if(ID != ""){         
 %>
 document.all.WebOffice1.SetTrackRevisions(0);
 document.all.WebOffice1.ShowRevisions(0);
 document.all.WebOffice1.HttpAddPostString("ID","<%=ID%>");
  <%
  }
  %> 
 document.all.WebOffice1.HttpAddPostString("DocTitle", myform.DocTitle.value);
 document.all.WebOffice1.HttpAddPostString("DocType","<%=DocType%>");
 //把當前文檔添加到Post元素列表中,文件的標識符䶿DocContent
 document.all.WebOffice1.HttpAddPostCurrFile("DocContent","");  // 涓婁紶鏂囦歡
 var vtRet;
    //HttpPost執行上傳的動仿WebOffice支持Http的直接上傳,在upload.aspx的頁面中,解析Post過去的數慿
    //拆分出Post元素和文件數據,可以有選擇性的保存到數據庫中,或保存在服務器的文件中⾿
 //HttpPost的返回值,根據upload.aspx中的設置,返回upload.aspx中Response.Write回來的數據
 vtRet = document.all.WebOffice1.HttpPost("<%=URL %>/upload.aspx");

  //alert(vtRet.Trim());
  if(vtRet.Trim() == "succeed"){
  alert("文件上傳成功"); 
 }else{
  alert("文件上傳失敗");
 }
 //return_onclick();
}
//-->
</script>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
    //實現Trim,LTrim和RTrim的功能
    String.prototype.Trim = function()
    {
    return this.replace(/(^\s*)|(\s*$)/g, "");
    }

    String.prototype.LTrim = function()
    {
    return this.replace(/(^\s*)/g, "");
    }

    String.prototype.RTrim = function()
    {
    return this.replace(/(\s*$)/g, "");
    }

function WebOffice1_NotifyCtrlReady() {
 //LoadOriginalFile接口裝載文件,
 //如果是編輯已有文件,則文件路徑傳給LoadOriginalFile的第一個參數
 alert("終於執行這里了!");
 <%
     if (ID == null || ID==""){
    %>
        document.all.WebOffice1.LoadOriginalFile("","<%=DocType%>");
 <%}
 else
 {%>       
       // document.all.WebOffice1.LoadOriginalFile("<%=URL %>/GetDoc.aspx?ID=<%=ID%>","<%=DocType%>");
       //alert("<%=URL %>/GetDoc.aspx?ID=yangweili1");
        document.all.WebOffice1.LoadOriginalFile("<%=URL %>/GetDoc.aspx?ID=yangweili1","doc");
       alert("加載成功了!");
      document.all.WebOffice1.SetTrackRevisions(1);
        document.all.WebOffice1.ShowRevisions(1);   
    <%}%>        
 

    //屏蔽標准工具欄的前幾個按鈕
    document.all.WebOffice1.SetToolBarButton2("Standard",1,1);
    document.all.WebOffice1.SetToolBarButton2("Standard",2,1);
    document.all.WebOffice1.SetToolBarButton2("Standard",3,1);
    document.all.WebOffice1.SetToolBarButton2("Standard",6,1);   
          
   <%if (DocType   == "doc") {%>
        //屏蔽文件菜單項
        document.all.WebOffice1.SetToolBarButton2("Menu Bar",1,1);
        //屏蔽 保存快捷鍵(Ctrl+S)
        document.all.WebOffice1.SetKeyCtrl(595,-1,0);
        //屏蔽 打印快捷鍵(Ctrl+P)
        document.all.WebOffice1.SetKeyCtrl(592,-1,0);
    <%}else if(DocType   == "xls") {%>
        //屏蔽文件菜單項
        document.all.WebOffice1.SetToolBarButton2("Worksheet Menu Bar",1,1);        
    <%} %>
}

//-->
</SCRIPT>
<!-- --------------------===  Weboffice初始化完成事件--------------------- -->

<SCRIPT LANGUAGE=javascript FOR=WebOffice1 EVENT=NotifyCtrlReady>
<!--
 WebOffice1_NotifyCtrlReady() // 在裝載完Weboffice(執行<object>...</object>)控件后自動執行WebOffice1_NotifyCtrlReady方法
//-->
</SCRIPT>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM