Estoy abriendo un archivo de Excel como esto:filas eliminación de un archivo de Excel utilizando C#
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("csharp.net-informations.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
me gustaría saber:
Cómo hacer yo bucle a través de todas las filas y eliminar todas las filas de los cuales la cadena SomeString
no aparece en column A
?
sé cómo recorrer todos los valores:
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
MessageBox.Show(str);
}
}
Pero no sé cómo eliminar toda la fila
Debería poder usar: 'range.EntireRow.Delete (Excel.XLDirection.xlUp)' - simplemente configure el rango con el objeto de la hoja de cálculo (xlWorksheet). –
@PatrickPitre muchas gracias! ¿Cómo configuro el rango? –
Se vería así: range = xlWorksheet.get_Range ("A1", "B1"); range.EntireRow.Delete (Excel.XLDirection.xlUp); –