• 大小: 4.67M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: 数据库  Excel  MySql  C#  操作  

资源简介

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NPOI.HSSF.UserModel;
using System.IO;
using NPOI.HSSF.Record.Formula.Functions;

namespace MysqlWinform
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream(@"c:\users\administrator\desktop\excel\goods_classone.xls", FileMode.Open, FileAccess.Read))
            {
                HSSFWorkbook work = new HSSFWorkbook(fs);
                HSSFSheet sheet = work.GetSheetAt(0);
                zlyfmallEntities2 db = new zlyfmallEntities2();
                HSSFRow row = null;
                goodsclasstwo gco = null;


                for (int i = 1; i <= 95; i  )
                {
                    row = sheet.GetRow(i);
                    gco = new goodsclasstwo();
                    gco.tname = row.GetCell(0).ToString();
                    gco.father = int.Parse(row.GetCell(1).ToString());
                    gco.status = 1;
                    db.goodsclasstwo.Add(gco);
                }

                db.SaveChanges();
                MessageBox.Show("插入成功");

            }
        }

        private void skinButton1_Click_1(object sender, EventArgs e)
        {
            
        }

        private void skinButton1_Click_2(object sender, EventArgs e)
        {

            int m = 0;
            
            using (FileStream fsread = new FileStream(@"C:\Users\Administrator\Desktop\Excel\zong.xls", FileMode.Open, FileAccess.Read))
            {
                using (FileStream fswrite = new FileStream(@"C:\Users\Administrator\Desktop\Excel\goodsClassThree.xls", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    HSSFWorkbook workread = new HSSFWorkbook(fsread);
                    HSSFSheet sheetread = workread.GetSheetAt(0);

                    HSSFWorkbook workwrite = new HSSFWorkbook();
                    HSSFSheet sheetwrite = workwrite.CreateSheet("goodsClassOne");
                    for (int i = 0; i <= sheetread.LastRowNum; i  )
                    {
                        HSSFRow row = sheetread.GetRow(i);
                        for (int j = 0; j <= row.LastCellNum; j  )
                        {
                            HSSFCell cell = row.GetCell(j);
                            if (cell != null)
                            {
                                if (cell.ToString() != "")
                                {
                                    HSSFRow newrow = sheetwrite.CreateRow(m);
                                    newrow.CreateCell(0, HSSFCellType.STRING).SetCellValue(cell.ToString());
                                    newrow.CreateCell(1, HSSFCellType.NUMERIC).SetCellValue(i 1);
                                    m  ;
                                }
                            }
                        }
                    }
                    workwrite.Write(fswrite);

                }
               
                MessageBox.Show("写入成功共"   m);
                
            }
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream(@"C:\Users\Administrator\Desktop\Excel\goodsClassThree.xls", FileMode.Open, FileAccess.Read))
            {
                HSSFWorkbook wk = new HSSFWorkbook(fs);
                HSSFSheet sheet = wk.GetSheetAt(0);
                HSSFRow row = null;
                goodsclassthree gc = null;
                zlyfmallEntities2 db = new zlyfmallEntities2();
                for (int i = 0; i <= sheet.LastRowNum; i  )
                {
                    row = sheet.GetRow(i);
                    gc = new goodsclassthree();
                    gc.tname = row.GetCell(0).ToString();
                    gc.father = int.Parse(row.GetCell(1).ToString());
                    gc.status = 1;
                    db.goodsclassthree.Add(gc);
                }
                db.SaveChanges();
                MessageBox.Show("插入成功");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream(@"C:\Users\Administrator\Desktop\Excel\goodstype1.xls", FileMode.Open, FileAccess.Read))
            {
                HSSFWorkbook work = new HSSFWorkbook(fs);
                HSSFSheet sheet = work.GetSheetAt(0);
                HSSFRow row = null;
                goodsclassone gt = null;
                zlyfmallEntities2 db = new zlyfmallEntities2();
                for (int i = 1; i <= sheet.LastRowNum; i  )
                {
                    row = sheet.GetRow(i);
                    gt = new goodsclassone();

                    gt.tname = row.GetCell(0).ToString().Replace(" ", ",");
                    gt.status = int.Parse(row.GetCell(1).ToString());
                    db.goodsclassone.Add(gt);
                }
                db.SaveChanges();
            }
        }
    }
}


资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NPOI.HSSF.UserModel;
using System.IO;
using NPOI.HSSF.Record.Formula.Functions;

namespace MysqlWinform
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void skinButton1_Click(object sender EventArgs e)
        {
            //using (FileStream fs = new FileStream(@“C:\Users\Administrator\Desktop\Excel\goodstype1.xls“ FileMode.Open FileAccess.Read))
            //{
            //    HSSFWorkbook work = new HSSFWorkbook(fs);
            //    HSSFSheet sh

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

    ..A..H.     52224  2017-07-29 18:15  MysqlWinform\.vs\MysqlWinform\v14\.suo

     文件       1998  2017-07-29 14:11  MysqlWinform\MysqlWinform\App.config

     文件    2738176  2016-05-18 18:13  MysqlWinform\MysqlWinform\bin\Debug\CSkin.dll

     文件     263246  2016-05-18 18:11  MysqlWinform\MysqlWinform\bin\Debug\CSkin.xml

     文件    1116760  2015-11-03 17:43  MysqlWinform\MysqlWinform\bin\Debug\Entityframework.dll

     文件    1138045  2015-11-03 17:43  MysqlWinform\MysqlWinform\bin\Debug\Entityframework.xml

     文件     196608  2010-05-25 12:55  MysqlWinform\MysqlWinform\bin\Debug\ICSharpCode.SharpZipLib.dll

     文件      18944  2017-07-29 18:12  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.exe

     文件       1998  2017-07-29 14:11  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.exe.config

     文件      36352  2017-07-29 18:12  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.pdb

     文件      22696  2017-07-31 09:36  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.vshost.exe

     文件       1998  2017-07-29 14:11  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.vshost.exe.config

     文件        490  2014-09-19 01:53  MysqlWinform\MysqlWinform\bin\Debug\MysqlWinform.vshost.exe.manifest

     文件      92160  2009-12-20 12:57  MysqlWinform\MysqlWinform\bin\Debug\NPOI.DDF.dll

     文件       9728  2009-12-20 13:16  MysqlWinform\MysqlWinform\bin\Debug\NPOI.dll

     文件      53248  2009-12-20 13:16  MysqlWinform\MysqlWinform\bin\Debug\NPOI.HPSF.dll

     文件     964608  2009-12-20 13:33  MysqlWinform\MysqlWinform\bin\Debug\NPOI.HSSF.dll

     文件      49664  2009-12-20 13:16  MysqlWinform\MysqlWinform\bin\Debug\NPOI.POIFS.dll

     文件      39424  2009-12-20 12:57  MysqlWinform\MysqlWinform\bin\Debug\NPOI.Util.dll

     文件      71256  2015-11-03 17:43  MysqlWinform\MysqlWinform\bin\Debug\zh-Hans\Entityframework.resources.dll

     文件       6358  2017-07-29 18:12  MysqlWinform\MysqlWinform\Form1.cs

     文件       2033  2017-07-29 18:12  MysqlWinform\MysqlWinform\Form1.Designer.cs

     文件       5817  2017-07-29 18:12  MysqlWinform\MysqlWinform\Form1.resx

     文件        683  2017-07-29 14:12  MysqlWinform\MysqlWinform\goodsclassone.cs

     文件        736  2017-07-29 14:12  MysqlWinform\MysqlWinform\goodsclassthree.cs

     文件        734  2017-07-29 14:12  MysqlWinform\MysqlWinform\goodsclasstwo.cs

     文件       1092  2017-07-29 14:11  MysqlWinform\MysqlWinform\Model1.Context.cs

     文件      26161  2017-07-29 14:11  MysqlWinform\MysqlWinform\Model1.Context.tt

     文件        417  2017-07-29 14:12  MysqlWinform\MysqlWinform\Model1.cs

     文件        750  2017-07-29 14:12  MysqlWinform\MysqlWinform\Model1.Designer.cs

............此处省略93个文件信息

评论

共有 条评论