• 大小: 2.22MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-10
  • 语言: C#
  • 标签: excel转sql  

资源简介

将excel表中数据读取转换为sql插入语句 附有c#源码及exe可执行文件(需要.net4.5环境)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel; 

namespace ExcelToSqlTool
{
    class ExcelHelper
    {


        //public static DataTable ConvertExcelFileToDatatable(string filePathref string msg) {
        //    // 打开文件 
        //    FileStream fileStream = new FileStream(filePath FileMode.Open FileAccess.Read FileShare.Read); 
        //    return ConvertExcelToDataTable(fileStreamref msg);
        //}

        ///// 
        ///// 判断Excel是否有数据
        ///// 

        ///// Excel文件流
        ///// 
        //public static bool HasData(Stream excelFileStream)
        //{
        //    using (excelFileStream)
        //    {
        //        IWorkbook workbook = new HSSFWorkbook(excelFileStream);
        //        if (workbook.NumberOfSheets > 0)
        //        {
        //            ISheet sheet = workbook.GetSheetAt(0);
        //            return sheet.PhysicalNumberOfRows > 0;
        //        }
        //    }
        //    return false;
        //}

        //#region DataTable 转换成 Excel

        ///// 
        ///// DataTable转换成内存流
        ///// 

        ///// 数据源
        ///// 内存流
        //public static MemoryStream RenderDataToMemoryStream(DataTable table)
        //{
        //    MemoryStream ms = new MemoryStream();
        //    using (table)
        //    {
        //        IWorkbook workbook = new HSSFWorkbook();
        //        ISheet sheet = workbook.CreateSheet();
        //        IRow headerRow = sheet.CreateRow(0);

        //        foreach (DataColumn column in table.Columns)
        //        {
        //            headerRow.CreateCell(column.Ordinal).SetCellValue(column.Caption);//If Caption not set returns the ColumnName value
        //        }


        //        int rowIndex = 1;

        //        foreach (DataRow row in table.Rows)
        //        {
        //            IRow dataRow = sheet.CreateRow(rowIndex);

        //            foreach (DataColumn column in table.Columns)
        //            {
        //                dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());

        //            }
        //            rowIndex++;
        //        }

        //        workbook.Write(ms);
        //        ms.Flush();
        //        ms.Position = 0;
        //    }
        //    return ms;
        //}

        //public static MemoryStream RenderDataToMemoryStream(DataTable table bool moreColumn)
        //{
        //    MemoryStream ms = new MemoryStream();
        //    using (table)
        //    {
        //        XSSFWorkbook workbook = new XSSFWorkbook();

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-12-09 15:53  ExcelToSqlTool\
     目录           0  2016-12-09 15:52  ExcelToSqlTool\Bin\
     文件       11776  2016-12-09 15:48  ExcelToSqlTool\Bin\ExcelToSqlTool.exe
     文件         189  2016-12-08 19:38  ExcelToSqlTool\Bin\ExcelToSqlTool.exe.config
     文件       24064  2016-12-09 15:48  ExcelToSqlTool\Bin\ExcelToSqlTool.pdb
     文件      445440  2016-12-08 20:53  ExcelToSqlTool\Bin\Ionic.Zip.dll
     文件     1443840  2016-12-08 20:53  ExcelToSqlTool\Bin\NPOI.dll
     文件     2014019  2016-12-08 20:53  ExcelToSqlTool\Bin\NPOI.xml
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\
     文件         189  2016-12-08 19:38  ExcelToSqlTool\ExcelToSqlTool\App.config
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\bin\
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\bin\Debug\
     文件       22696  2016-12-09 15:25  ExcelToSqlTool\ExcelToSqlTool\bin\Debug\ExcelToSqlTool.vshost.exe
     文件         189  2016-12-08 19:38  ExcelToSqlTool\ExcelToSqlTool\bin\Debug\ExcelToSqlTool.vshost.exe.config
     文件         490  2016-07-16 19:44  ExcelToSqlTool\ExcelToSqlTool\bin\Debug\ExcelToSqlTool.vshost.exe.manifest
     文件       19384  2016-12-08 20:59  ExcelToSqlTool\ExcelToSqlTool\ExcelHelper.cs
     文件        4607  2016-12-08 20:56  ExcelToSqlTool\ExcelToSqlTool\ExcelToSqlTool.csproj
     文件        4169  2016-12-09 15:51  ExcelToSqlTool\ExcelToSqlTool\Form1.cs
     文件        5432  2016-12-08 22:00  ExcelToSqlTool\ExcelToSqlTool\Form1.Designer.cs
     文件        6021  2016-12-08 22:00  ExcelToSqlTool\ExcelToSqlTool\Form1.resx
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\libs\
     文件      445440  2016-12-08 20:53  ExcelToSqlTool\ExcelToSqlTool\libs\Ionic.Zip.dll
     文件     1443840  2016-12-08 20:53  ExcelToSqlTool\ExcelToSqlTool\libs\NPOI.dll
     文件     2014019  2016-12-08 20:53  ExcelToSqlTool\ExcelToSqlTool\libs\NPOI.xml
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\obj\
     目录           0  2016-12-09 15:53  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\
     文件        1464  2016-12-08 20:31  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7614  2016-12-08 20:53  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2016-12-08 19:38  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-12-08 19:38  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2016-12-08 19:38  ExcelToSqlTool\ExcelToSqlTool\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
............此处省略9个文件信息

评论

共有 条评论

相关资源