В общем сделал так:
Код | public Excel.Worksheet[] ExportWorksheets() { Excel.Application XL = null; Excel.Workbook WB = null; Excel.Worksheet[] WS = new Excel.Worksheet[19]; Excel.Sheets WSS = null; try { XL = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application") as Excel.Application; WB = XL.ActiveWorkbook; WSS = WB.Worksheets; for (int i = 1; i <= WB.Worksheets.Count; i++) WS[i] = WSS.get_Item(i) as Excel.Worksheet; } catch { } return WS; } public Excel.Worksheet[] SampleWorksheets() { Excel.Application XLsample = null; Excel.Workbook WBsample = null; Excel.Worksheet[] WSsample = new Excel.Worksheet[19]; Excel.Sheets WSSsample = null; try { XLsample = new Excel.ApplicationClass(); WBsample = XLsample.Workbooks.Open(TestConst.Sample, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing); WSSsample = WBsample.Worksheets; for (int i = 1; i <= WBsample.Worksheets.Count; i++) WSsample[i] = WSSsample.get_Item(i) as Excel.Worksheet; } catch { } return WSsample; } void CompareExcelCells() { bool a; Excel.Worksheet[] wk = new Excel.Worksheet[19]; Excel.Worksheet[] wk2 = new Excel.Worksheet[19]; for (int i = 2; i < 19; i++) { wk[i] = ExportWorksheets()[i]; wk2[i] = SampleWorksheets()[i]; for (int j = 1; j <= wk[i].UsedRange.Rows.Count; j++) for (int k = 1; k <= wk[i].UsedRange.Columns.Count; k++) if (System.Convert.ToString((wk[i].Cells[j, k] as Excel.Range).Value2) == System.Convert.ToString((wk2[i].Cells[j, k] as Excel.Range).Value2)) a = true; else a = false; } }
|
|