一个.net库,可以读取/写入没有安装microsoft office的office格式。没有com +,没有互操作。

public class excelnpoitest
{
    /// <summary>
    /// npoi基础的excel创建
    /// </summary>
    public static void createexcel()
    {
        //创建工作薄
        hssfworkbook wk = new hssfworkbook();
        //创建一个名称为mysheet的表
        isheet tb = wk.createsheet("mysheet");
        for (int i = 0; i < 20; i++)
        {
            //创建行
            irow row = tb.createrow(i);
            for (int j = 0; j < 20; j++)
            {
                //创建列
                icell cell = row.createcell(j);
                //赋值
                cell.setcellvalue($"[{i},{j}]");
            }
        }
        //打开一个现有文件或创建一个新文件以进行写入。
        using (filestream fs = file.openwrite(@"d:\myxls.xls"))
        {
            //向打开的这个xls文件中写入mysheet表并保存。
            wk.write(fs);
        }
    }

    /// <summary>
    /// npoi基础的excel读取
    /// </summary>
    public static void readexcel()
    {
        //打开现有文件以进行读取。
        using (filestream fs = file.openread(@"d:\myxls.xls"))
        {
            //把文件写入wk中
            hssfworkbook wk = new hssfworkbook(fs);
            for (int i = 0; i < wk.numberofsheets; i++)
            {
                //获取sheet
                isheet sheet = wk.getsheetat(i);
                for (int j = 0; j < sheet.lastrownum; j++)
                {
                    //获取行
                    irow row = sheet.getrow(j);
                    if (row != null)
                    {
                        for (int k = 0; k < row.lastcellnum; k++)
                        {
                            //获取列
                            icell cell = row.getcell(k);
                            if (cell != null)
                            {
                                //获取值
                                console.write(cell.tostring());
                            }
                        }
                    }
                    console.writeline();
                }
            }
        }
    }


}