darknessomi/excellibrary

How to delete the entire row or column in excel

Opened this issue · 2 comments

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by pradipku...@gmail.com on 28 Nov 2013 at 12:52

I cant find any delete method on GetRow(x). How to a row in Excel worksheet ?

Im using: ExcelLibrary_20110730.zip
OS: Windows 7 Premium

Original comment by maxis...@gmail.com on 10 Jun 2015 at 9:58

A way to delete a row.

private void RemoveRecord(int index)
        {
            Workbook book = Workbook.Load(excel_filename);
            Worksheet _sheet = book.Worksheets[0];
            Worksheet _newsheet = new Worksheet(_sheet.Name);

            for (int i = _sheet.Cells.FirstRowIndex; i <= _sheet.Cells.LastRowIndex; i++)
            {
                if(i != index)
                {
                    int lastRow = _newsheet.Cells.Rows.Count;
                    for (int col_index = _sheet.Cells.FirstColIndex; col_index <= _sheet.Cells.LastColIndex; col_index++ )
                    {
                        _newsheet.Cells[lastRow, col_index] = new Cell(_sheet.Cells[i, col_index].StringValue);
                    }
                }
            }

            book.Worksheets.RemoveAt(0);
            _newsheet.Book = book;

            book.Worksheets.Add(_newsheet);
            book.Save(excel_filename);
        }

Original comment by maxis...@gmail.com on 10 Jun 2015 at 1:11