承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

Excel Services 的 web Services 接口应用




  笔记:
     使用 Excel Services 的 web Services 接口应用,当时首先需要在工程里面引用这个excel这个web services ,然后在工程里面添加

这个Excel Services 的 web Services 可以直接在服务器的本地查找就可以!

直接通过 Excel Services 的 web Services 接口 直接访问文档库里面的excel,并传递传送,或者数据还回结果.大家问我们为什么要使用这个Excel Services 的 web Services 接口?,因为有时候我们在实际的应用中,有些excel不想公布全部数据,有些数据是保密的,所以通过Excel Services 的 web Services 接口 可以很好的控制权限.通过Excel Services 的 web Services 接口来操作,可以通过我们webApp程序来操作,可以做出更人性化的程序.

测试代码如下:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ExcelDemo
{
    public partial class ExcelUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSum_Click(object sender, EventArgs e)
        {
            localhost.Status[] status;
          

            string SessionId = null;

            localhost.ExcelService es = new ExcelDemo.localhost.ExcelService();


            //设置验证信息
            es.Credentials = System.Net.CredentialCache.DefaultCredentials;
            //开始访问一个session
            try
            {
                SessionId = es.OpenWorkbook("http://wh/sites/report/ExcelDocument/sheet.xlsx", string.Empty, string.Empty,out status);
            }
            catch
            {
                SessionId = null;
            }

            //设置参数
            if (SessionId != null)
            {
                es.SetCellA1(SessionId, "sheet2", "employee", tbEmployee.Text.Trim());
                es.SetCellA1(SessionId,"sheet2","saler",tbSaler.Text.Trim());

            }
            //取回结果
            object payment = es.GetCellA1(SessionId, "sheet2", "B3", true,out status);

            if (payment != null)
            {
                lbSUM.Text = Convert.ToString(payment);
            }

            status = es.CloseWorkbook(SessionId);

 

        }
    }
}


简单demo下载:/Files/wanghao-3/ExcelDemo.rar
代码不是最后,只是本人学习用!

posted on 2007-12-16 19:44  A A  阅读(642)  评论(1编辑  收藏  举报