开发excle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;

#region Microsoft Excel幫助類
/// <summary>
/// Microsoft Excel幫助類
/// </summary>
public class ExcelHelper
{
    string strMessage = "";
    /// <summary>
    /// 構造函數
    /// </summary>
    public ExcelHelper()
    {

    }
    /// <summary>
    /// 信息屬性
    /// </summary>
    public string Message
    {
        set { strMessage = value; }
        get { return strMessage; }
    }
    /// <summary>
    /// 返回一張表,默認為Sheet1
    /// </summary>
    /// <param name="strFileFullName"></param>
    /// <returns></returns>
    public DataTable GetTableByExcel2003(string strFileFullName)
    {
        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFileFullName + ";Extended Properties=Excel 8.0;";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();

        string Sql = "select * from [Sheet1$]";
        OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, conn);
        DataSet ds = new DataSet();
        mycommand.Fill(ds, "[Sheet1$]");

        mycommand.Dispose();
        conn.Close();
        conn.Dispose();

        return ds.Tables[0];
    }
    /// <summary>
    /// 返回一張表,默認為Sheet1
    /// </summary>
    /// <param name="strFileFullName"></param>
    /// <returns></returns>
    public DataTable GetTableByExcel2007(string strFileFullName)
    {
        //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFileFullName + ";Extended Properties=Excel 8.0;";
        string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strFileFullName + ";" + "Extended ProPerties= \"Excel 12.0;HDR=Yes;\"";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();

        string Sql = "select * from [Sheet1$]";
        OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, conn);
        DataSet ds = new DataSet();
        mycommand.Fill(ds, "[Sheet1$]");

        mycommand.Dispose();
        conn.Close();
        conn.Dispose();

        return ds.Tables[0];
    }
    /// <summary>
    /// 根据Excel驱动类型来读取EXcel文件
    /// </summary>
    /// <param name="strDrive">例如 Microsoft.ACE.OLEDB.12.0 </param>
    /// <param name="strFileFullName">文件全路径,包括文件名</param>
    /// <returns></returns>
    public DataTable GetTableByExcel(string strDrive, string strFileFullName)
    {
        //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFileFullName + ";Extended Properties=Excel 8.0;";
        string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strFileFullName + ";" + "Extended ProPerties= \"Excel 12.0;HDR=Yes;\"";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();

        string Sql = "select * from [Sheet1$]";
        OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, conn);
        DataSet ds = new DataSet();
        mycommand.Fill(ds, "[Sheet1$]");

        mycommand.Dispose();
        conn.Close();
        conn.Dispose();

        return ds.Tables[0];
    }
}

#endregion

================================================================================================

時間截轉化

=(((((B2+28800000)/60)/60)/1000)/24)+DATE(1970,1,1)

B2 = 時間欄位

再把Excel欄位格式改成"日期"

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值