Removing a row from an Excel sheet with Apache POI HSSF

前端 未结 7 1042
小鲜肉
小鲜肉 2020-11-29 05:38

I\'m using the Apache POi HSSF library to import info into my application. The problem is that the files have some extra/empty rows that need to be removed first before pars

相关标签:
7条回答
  • 2020-11-29 06:42

    I know, this is a 3 year old question, but I had to solve the same problem recently, and I had to do it in C#. And here is the function I'm using with NPOI, .Net 4.0

        public static void DeleteRow(this ISheet sheet, IRow row)
        {
            sheet.RemoveRow(row);   // this only deletes all the cell values
    
            int rowIndex = row.RowNum;
    
            int lastRowNum = sheet.LastRowNum;
    
            if (rowIndex >= 0 && rowIndex < lastRowNum)
            {
                sheet.ShiftRows(rowIndex + 1, lastRowNum, -1);
            }
        }
    
    0 讨论(0)
提交回复
热议问题