davidcon / excellibrary

Automatically exported from code.google.com/p/excellibrary
0 stars 0 forks source link

How to delete the entire row or column in excel #157

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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