5
sto aprendo un file excel in questo modo:eliminazione di righe da un file Excel con 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);
Vorrei sapere:
Come faccio a scorrere tutti i file e cancellare ogni riga in cui la stringa SomeString
non viene visualizzata in column A
?
So come scorrere ogni valore:
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);
}
}
Ma non so come eliminare l'intera riga
Dovresti essere in grado di utilizzare: 'range.EntireRow.Delete (Excel.XLDirection.xlUp)' - basta impostare l'intervallo con l'oggetto del foglio di lavoro (xlWorksheet). –
@PatrickPitre grazie mille! come posso impostare l'intervallo? –
Sembrerebbe: range = xlWorksheet.get_Range ("A1", "B1"); range.EntireRow.Delete (Excel.XLDirection.xlUp); –