Remove edge of cells excel

0

I'm making a console application that reads a protected excel and dumps it into a database, the problem is that this excel has marked the edges of the cells in all lines.

        Excel.Application xlApp = new Excel.Application();
        Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(item);
        Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[2];
        Excel.Range xlRange = xlWorksheet.UsedRange;

and said cells read them as if they were data.

As I can avoid that I read the edges as data of this excel, the excel file I can not edit it.

    
asked by Sebastian 25.07.2018 в 17:41
source

1 answer

1

Dear, in xlRange , you can save the range to read that only contains data, even when you make a ctrl + end to locate the last row with data. In the following code, you can store this data and go through the Excel to the last row with data:

Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(item);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[2];

int fin = xlWorksheet.Rows.Count;
int ultima = xlWorksheet.Cells[fin,1].End(Excel.XlDirection.xlUp).Row;
Excel.Range xlRange = xlWorksheet.Range["A1", "última columna a leer" + ultima];

I hope it serves you, regards

    
answered by 26.07.2018 / 00:53
source