zoukankan      html  css  js  c++  java
  • 解析excel表格为DataSet

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;
    using System.Linq;
    using System.Text;
    using Log;
    namespace Common
    {
    public class ExcelInputHelper
    {
    public static ExcelInputHelper Self = new ExcelInputHelper();

    public static DataSet ExecleDataSet(string filePath)
    {
    string OleDbConnection = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filePath + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
    OleDbConnection conn = new OleDbConnection(OleDbConnection);
    try
    {
    conn.Open();
    }
    catch (Exception ee)
    {
    if (ee.Message.Contains("外部表不是预期的格式"))
    {
    OleDbConnection = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + filePath + ";Extended Properties='Excel 12.0; HDR=YES; IMEX=1'";
    conn.ConnectionString = OleDbConnection;
    conn.Open();
    }
    else
    {
    Log.Log4NetUtility.Error(Self, "无法打开文件");
    return null;
    }
    }

    DataSet ds = new DataSet();
    OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet1$]", conn);
    odda.Fill(ds);
    conn.Close();
    return ds;
    }
    }
    }

  • 相关阅读:
    Linux服务器查看日志命令总结
    nginx高可用(5)
    nginx动静分离(4)
    nginx负载均衡(3)
    nginx反向代理(2)
    nginx安装及使用(1)
    Nginx 简易教程
    uiautomator2中文文档
    TKinter之输入框
    nginx解决反向代理session丢失问题
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/5773595.html
Copyright © 2011-2022 走看看