C# NPOI 读取Excel数据,附案例源码
2020-12-28 18:28
标签:throw datarow dem def sse assert namespace 演示 exists 注意:需要引入NPOI类库 演示过程中,提示另外一个进程xxxx的,是因为NPOI读取Excel的时候,Excel不可以打开,我们关闭,然后再次执行即可 C# NPOI 读取Excel数据,附案例源码 标签:throw datarow dem def sse assert namespace 演示 exists 原文地址:https://www.cnblogs.com/chenyanbin/p/13300297.html项目结构
C#代码
Form1.cs
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NPOIDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const int DEFAULT_CHECK_CELL_NUM = 4;
private void button1_Click(object sender, EventArgs e)
{
try
{
DataTable dt=ReadExcelData(@"C:\Users\apple\Desktop\Test.xls");
MessageBox.Show("ok");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
Assert.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NPOIDemo
{
public static class Assert
{
public static void IsTrue(bool flag,string msg)
{
if (flag)
{
throw new Exception(msg);
}
}
}
}
演示
项目下载
链接:https://pan.baidu.com/s/1YLer2fgV6QhJIQVsxqozJQ
提取码:30a9
文章标题:C# NPOI 读取Excel数据,附案例源码
文章链接:http://soscw.com/index.php/essay/38888.html