Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用NPOI从excel中删除行?_C#_Xlsx_Xls_Npoi - Fatal编程技术网

C# 如何使用NPOI从excel中删除行?

C# 如何使用NPOI从excel中删除行?,c#,xlsx,xls,npoi,C#,Xlsx,Xls,Npoi,我正在使用下面的代码从.xlsx中删除上面的行,并且我成功地安装了NPOI库。它已成功执行,但无法删除行 namespace A { class B { path = "File path"; XSSFWorkbook hswb; using(FileStream file = new FileStream(path,FileMode.Open,FileAccess.ReadWrite))

我正在使用下面的代码从.xlsx中删除上面的行,并且我成功地安装了NPOI库。它已成功执行,但无法删除行

namespace A
{
    class B
    {
            path = "File path";
            XSSFWorkbook hswb;
            using(FileStream file = new FileStream(path,FileMode.Open,FileAccess.ReadWrite))
            {
                hswb = new XSSFWorkbook(file);
            }

            ISheet sheet = hswb.GetSheetAt(0);
            for (int row = 0; row <= sheet.LastRowNum; row++)
            {
                var row1 = sheet.GetRow(row);
                if((row<3) && row1 != null)
                {
                    sheet.RemoveRow(row1);
                    sheet.ShiftRows(row+1,sheet.LastRowNum,-1);
                }
            }
    }
    
}
名称空间A
{
B类
{
path=“文件路径”;
XSSF和hswb;
使用(FileStream file=newfilestream(路径,FileMode.Open,FileAccess.ReadWrite))
{
hswb=新的XSSF工作簿(文件);
}
ISHET sheet=hswb.GetSheetAt(0);
对于(int row=0;row)