我嘗試用Range.Replace
替換某些單元格,但是當我嘗試這樣做時,我的程序只更改第一個單元格找到它。Range.Replace in Excel
我該怎麼辦?
range = sheet.UsedRange;
// leer las celdas
int rows = range.Rows.Count;
int cols = range.Columns.Count;
Excel.Range startCell = sheet.Cells[1, 1];
Excel.Range endCell = sheet.Cells[rows, cols];
sheet.Range[startCell, endCell].Replace(@"'C:\", @"'C:\Gestion\");
現在我試着這樣做:
// seleccion rango activo
range = sheet.UsedRange;
// leer las celdas
int rows = range.Rows.Count;
int cols = range.Columns.Count;
Excel.Range startCell = sheet.Cells[1, 1];
Excel.Range endCell = sheet.Cells[rows, cols];
sheet.Range[startCell, endCell].Replace(@"C:\", @"C:\Gestion\", Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByColumns, false, Type.Missing, false, false);
但我有同樣的問題,只改變一個單元格在我的表:S
你肯定行和/或COLS> 1? –
是的,行和列是> 1:S我沒有找到錯誤 –
你可以發佈數據的圖片嗎?第二個代碼似乎是正確的。 –