CRM2011 简单的Excel导入

Posted hushzhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CRM2011 简单的Excel导入相关的知识,希望对你有一定的参考价值。

技术分享导入的前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="new_hosiptalmsysuser_importData.aspx.cs" Inherits="Saleto_new_hosiptalmsysuser_importData" %>

<!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>
        <asp:Literal ID="lblTitle" Text="医院对应代表关联数据导入" runat="server"></asp:Literal></title>
      <base target="_self" />
    <link id="Link1" rel="stylesheet" href="../css/jquery-ui-all.css.aspx" />
    <link id="Link2" rel="stylesheet" href="../css/global.css.aspx" />
    <script type="text/javascript" src="../js/common/common.js.aspx"></script>
    <script type="text/javascript" src="../js/common/jquery-ui-all.js.aspx"></script>
</head>
<body>
    <form id="form1" runat="server">
    <input id="hidMainId" runat="server" type="hidden" />
    <div>
        <table align="center" width="98%" class="query">
             <tr>
                <td class="dialog-header" colspan="2">
                    <asp:Label ID="lblQueryName" runat="server" Text="医院对应代表关联数据导入"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="选择导入文件路径:" CssClass="label" ForeColor="Black"></asp:Label>
                </td>
                <td style="width: 480px;">
                    <asp:FileUpload ID="FileUpload1" runat="server" CssClass="file" Width="100%" />
                </td>
            </tr>
            <tr>
                <td style="text-align: right; margin-right: 2.5%" colspan="2">
                    <asp:Button ID="btnImport" runat="server" Text="导 入 " CssClass="button" OnClick="btnImport_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="height: 18px; border-top-width: thin; border-left-width: thin;
                    border-left-color: black; border-bottom-width: thin; border-bottom-color: black;
                    border-top-color: black; border-right-width: thin; border-right-color: black;">
                    <img id="progress" alt="progress" src="/rektecweb/_imgs/uploading.gif" width="0px" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="height: 320px; text-align: left;">
                    <div style="width: 100%; height: 320px; overflow: scroll; border: 1px solid; background-color: White;">
                        <asp:Label ID="lblResult" runat="server" Height="100%" Width="100%"></asp:Label>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

技术分享导入的后天代码
using RekTec.Crm.Biz.Saleto;
using RekTec.Crm.Common;
using RekTec.Crm.Common.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Saleto_new_hosiptalmsysuser_importData : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //做导入动作时,将界面的按钮变灰
        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
        ButtonOnClientClick(this.btnImport);
        // hidMainId.Value = Request["id"].ToString();
    }
    void _log(string msg)
    {
        if (msg.StartsWith("[Error]"))
            this.lblResult.Text += "<font color=‘red‘>" + msg + "</font><br>";
        else
            this.lblResult.Text += msg + "<br>";
    }

    /// <summary>
    /// 导入事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnImport_Click(object sender, EventArgs e)
    {
        try
        {

            if (this.FileUpload1.HasFile)
            {
                string filename = Server.MapPath("../../../rektecweb/upload/") + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + FileUpload1.FileName;

                //获取文件后缀名
                string type = filename.Substring(filename.LastIndexOf(".") + 1);
                if (type.ToLower() != "xls" && System.IO.Path.GetExtension(filename).ToLower() != ".xlsx")
                {
                    this.ShowMessage("上传的文件格式不正确");
                    return;
                }
                FileUpload1.SaveAs(filename);
                Logging log = new Logging();
                log.LogUI += new Logging.LogUIEvent(_log);
                new_hosiptalmsysuser_importCommand cmd = new new_hosiptalmsysuser_importCommand();
                cmd.ImportIn(filename, log);
            }
            else
            {
                this.ShowMessage("请选择要上传的文件");
            }
        }
        catch (Exception ex)
        {
        }
    }
}

技术分享导入所使用的类

技术分享

这种导入方式不需要在DataMapping.xml中进行配置

以上是关于CRM2011 简单的Excel导入的主要内容,如果未能解决你的问题,请参考以下文章

CRM 2011 导入托管解决方案会覆盖系统视图更改

如何在Dynamic CRM 2011中使用自定义Workflow

如何用java导入Excel数据到数据库?

Dynamics CRM 修改Excel 最大导出记录限制及 最大上传文件限制

如何对 CRM 2011 进行身份验证?

从 Excel 导入 - 标题不在第 1 行