zoukankan      html  css  js  c++  java
  • excel导入导出

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using FS.Extend;
    using System.Data;
    using System.Data.OleDb;
    namespace Tag.Logic
    {
        public static class UploadFileLogic
        {
            /// <summary>
            /// 获取链接字符串
            /// </summary>
            /// <param name="filePath">文件路径</param>
            /// <returns></returns>
            private static string GetConectionString(string filePath)
            {
                var strSuffix = "";
                if (filePath.IsNullOrEmpty()) { return ""; }
                strSuffix = filePath.Substring(filePath.LastIndexOf("."));
                var strConectionString = "";
                switch (strSuffix)
                {
                    case ".xls":
                        {
                            strConectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties="Excel 8.0"";
                            break;
                        }
                    case ".xlsx":
                        {
                            strConectionString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties="Excel 12.0"";
                            break;
                        }
                }
                return strConectionString;
            }
            /// <summary>
            /// 获取表数据
            /// </summary>
            /// <param name="filePath">文件路径</param>
            /// <param name="sheetName">名称</param>
            /// <returns></returns>
            public static DataTable GetDataTable(string filePath, string sheetName)
            {
                string strConn = GetConectionString(filePath);
                string strSql = "select * from [" + sheetName + "$]";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                DataTable dt = new DataTable();
                OleDbDataAdapter ole = new OleDbDataAdapter(strSql, conn);
                ole.Fill(dt);
                return dt;
            }
        }
    }

     var licenseDT = new DataTable();

    licenseDT = UploadFileLogic.GetDataTable(pathfile, "证书信息");

  • 相关阅读:
    MySql 语言分类
    grep正则 以.o结尾的文件
    demo板 apt-get install stress
    ltp-ddt qspi_mtd_dd_rw error can't read superblock on /dev/mtdblock0
    linux 系统中的 /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin 目录的区别
    setenv和dos2unix碰到的问题
    bootz to be continued
    runltp出现问题 [
    demo board boot mode
    excel条件格式 满足包含xx的整行高亮
  • 原文地址:https://www.cnblogs.com/sll-fuling/p/5033383.html
Copyright © 2011-2022 走看看