Excel批量导入发起泛微e-cology流程C#实例

上次写了篇文章是外部用C#发起泛微e-cology流程的,泛微e-cology接口之外部发起流程C#实例_泛微oawebservices c#调用-CSDN博客

后面项目中用到Excel导入批量发起泛微e-cology流程(一次导入发起500多个流程),这里给一下思路。

假设导入的excel的流程的字段为监督单位、重点监督任务、监督对象、监督检查内容、监督检查方式 、监督频次、监督员。这里需要注意的是监督单位、监督员,数据库里需要找到对应的ID进行转换,监督频次需要根据选择框的文本和值进行转换。

前端,一个预览、一个导入、一个文件上传、一个预览表格:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Excel_Input.aspx.cs" Inherits="App.jdpt.Excel_Input" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button3" runat="server" Text="预览" OnClick="Button3_Click" Height="18px" Width="64px" />
        &nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button2" runat="server" Text="导入" OnClick="Button2_Click" Height="22px" Visible="False" Width="64px" />
        &nbsp;&nbsp;&nbsp;&nbsp;
             <br />
    </div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <asp:Label ID="Label2" runat="server"></asp:Label>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </form>
</body>
</html>

后端:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.ServiceReference1;
using System.Data;
using System.Data.OleDb;
using System.IO;
using Common;
using System.Data.SqlClient;
using Microsoft.Office.Interop.Excel;
namespace App.jdpt
{
    public partial class Excel_Input : System.Web.UI.Page
    {
        public static readonly string LocalSqlServer = "Data Source=*****;Initial Catalog=ecology;Persist Security Info=True;User ID=****;Password=*****";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region   问题:未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序
        //  解决访问Excel数据源时出现 未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序
        //  1、确保安装了Microsoft.ACE.OLEDB.12.0驱动
        //  http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/AccessDatabaseEngine.exe
        //  2、在vs中右击项目--》属性--》生成 下的 目标平台 改为x86
        //  如果以上两个方法还是不行的话,用第三个方法
        //  3、在对应的 IIS 应用程序池中,“设置应用程序池默认属性”右击/“高级设置”/"启用32位应用程序",设置为 true。
        #endregion

        public System.Data.DataTable GetExcelDatatable(string fileUrl)
        {
            //支持.xls和.xlsx,即包括office2010等版本的   HDR=Yes代表第一行是标题,不是数据;
            string cmdText = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
            System.Data.DataTable dt = null;
            //建立连接
            OleDbConnection conn = new OleDbConnection(string.Format(cmdText, fileUrl));
            try
            {
                //打开连接
                if (conn.State == ConnectionState.Broken || conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                string strSql = "select * from [Sheet1$A:D]";
                OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
                DataSet ds = new DataSet();
                da.Fill(ds);
                dt = ds.Tables[0];
                return dt;
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }
        ///<summary>
        /// 获取指定文件的指定单元格内容
        ///</s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值