我想掃描一個excel表格,並用零替換任何出現的社會安全號碼......我希望儘可能使用Excel.Interop來做到這一點,但我會「M開在這一點上什麼...這裏是我的一些代碼...我敲我的桌子,在過去幾個月的頭......使用excel替換excel中的單元格值.interop
// Get range and convert it to a string variable Excel.Range _range =(Excel.Range)_excelApp.get_Range("A1:K1",Type.Missing); // convert the value of our cells in our range // to the string variable string myString = _range.Cells.Value2.ToString(); // match any SSN e.g. 1236780909, 123-33-2445 if (Regex.IsMatch(myString, @"\b\d{3}\b\d{2}\b\d{4}")); { _range.Cells.Value2 = replaceSSN; } // save our workbook with a new name and create a backup _excelWorkbook.SaveAs("Results.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); // close workbook _excelWorkbook.Close(false, Type.Missing, Type.Missing); // send quit signal to app _excelApp.Quit(); // report success MessageBox.Show("File masked successfully.", "Mask Data", MessageBoxButtons.OK); // release memory //System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApp); // change label back to being blank lblActivity.Text = ""; }
完美地工作。非常感謝你Ori ...你從頭痛中拯救了我的頭......大聲笑......我也完全理解你做了什麼......一種學習體驗......再次感謝! – Woody 2009-08-02 02:22:29
任何時候都沒有問題:) – 2009-08-02 08:37:43