• 大小: 1.15M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-14
  • 语言: C#
  • 标签: Excel  数据库  数据  导入  C#  

资源简介

代码为dll类库,使用方法:引入命名空间:using OFFEBASE;调用方法DataTable Mtable = EXCellToDatabase.ReadAsTable(xlsx文件路径,表的sheet名);然后 Mtable.ToSqlserver(SqlConnection)就可以了,目前只写了Sqlserver,其他数据库操作一样(备注:有可能需要安装VFPOLEDBSetup.msi,为了方便大家,我已经打包了)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OFFEbase
{
    public static class EXCellToDatabase
    {
        private static   string SheetName { get; set; }
        public static DataTable ReadAsTable(string xlsxFile string sheetName)
        {
            //strConn = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=“ + filePath + “;Extended Properties=‘Excel 8.0;HDR=False;IMEX=1‘“;
            SheetName = sheetName;
            string Olecon = string.Format(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\“Excel 12.0;HDR=Yes;IMEX=1\““ xlsxFile);//需要安装环境VFPOLEDBSetup.msi
            try
       

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7168  2020-04-05 00:55  OFFEbase\OFFEbase\bin\Debug\OFFEbase.dll

     文件      13824  2020-04-05 00:55  OFFEbase\OFFEbase\bin\Debug\OFFEbase.pdb

     文件       4623  2020-04-05 00:54  OFFEbase\OFFEbase\Class1.cs

     文件       6521  2020-04-04 22:32  OFFEbase\OFFEbase\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        292  2020-04-05 00:55  OFFEbase\OFFEbase\obj\Debug\OFFEbase.csproj.FileListAbsolute.txt

     文件       7168  2020-04-05 00:55  OFFEbase\OFFEbase\obj\Debug\OFFEbase.dll

     文件      13824  2020-04-05 00:55  OFFEbase\OFFEbase\obj\Debug\OFFEbase.pdb

     文件          0  2020-04-04 22:32  OFFEbase\OFFEbase\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2020-04-04 22:32  OFFEbase\OFFEbase\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2020-04-04 22:32  OFFEbase\OFFEbase\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       2404  2020-04-04 22:32  OFFEbase\OFFEbase\OFFEbase.csproj

     文件       1336  2020-04-04 22:32  OFFEbase\OFFEbase\Properties\AssemblyInfo.cs

     文件        914  2020-04-04 22:32  OFFEbase\OFFEbase.sln

    ..A..H.     36352  2020-04-05 00:55  OFFEbase\OFFEbase.v11.suo

     文件    1292288  2020-03-10 14:58  OFFEbase\VFPOLEDBSetup.msi

     目录          0  2020-04-04 22:32  OFFEbase\OFFEbase\obj\Debug\TempPE

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase\bin\Debug

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase\obj\Debug

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase\bin

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase\obj

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase\Properties

     目录          0  2020-04-05 00:56  OFFEbase\OFFEbase

     目录          0  2020-04-05 01:05  OFFEbase

----------- ---------  ---------- -----  ----

              1386714                    23


评论

共有 条评论