Пример #1
0
 //获取一个工作表
 /// <summary>
 /// 获得sheet
 /// </summary>
 /// <param name="sheets">sheet</param>
 /// <param name="sc">序号</param>
 public Excel._Worksheet GetSheet(Excel.Sheets sheets, int sc)
 {
     Excel._Worksheet worksheet = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(sc);
     return worksheet;
 }
        static private bool CheckAllProfiles(Hashtable oldBook, Excel.Sheets newSheets)
        {
            try
            {
                Hashtable oldRows = new Hashtable();
                Hashtable newRows = new Hashtable();
                Excel.Worksheet saveSheet = null;


                #region Läs in alla nya, och hitta sheetet "AllProfiles"
                //Läs in alla nya
                int numOfNewSheets = _newLog.Worksheets.Count;
                //// get the first worksheet from the collection of worksheets
                Excel.Worksheet newWorksheet = null;// (Excel.Worksheet)newSheets.get_Item(1);
                //// loop through 10 rows of the spreadsheet and place each row in the list view

                //_compareProgress.StartTotal("Loading new AllProfiles Log sheets and compares...", numOfNewSheets);//-1 );
                //int sheetsDone = 0;//För progress

                //Compare to old rows
                for (int sheetNr = 1; sheetNr <= numOfNewSheets; sheetNr++)
                {
                    //if (MainForm.StopGracefully)
                    //    break;

                    string name = ((Excel.Worksheet)newSheets.get_Item(sheetNr)).Name;

                    newWorksheet = (Excel.Worksheet)newSheets.get_Item(sheetNr);

                    //Läs in hela nuv. nya arket till en HT
                    if (name.StartsWith("AllProfiles"))//Specialfall för AllProfiles-flikar
                        getExcelRows(newWorksheet, newRows);

                    if (name == "AllProfiles")
                        saveSheet = newWorksheet;

                    //Ev. Rensa _part1...X

                    //_compareProgress.SetTotal(sheetsDone++);
                }

                #endregion

                #region Lägg ihop alla gamla
                oldRows = oldBook["AllProfiles"] as Hashtable;

                foreach (DictionaryEntry item in oldBook)
                {
                    string name = item.Key as string;
                    Hashtable rows = item.Value as Hashtable;

                    //if (name == "AllProfiles")//Specialfall för AllProfiles-flikar
                    //{
                    //    oldRows = rows;
                    //}
                    if (name.StartsWith("AllProfiles_"))//Specialfall för AllProfiles-flikar
                    {
                        foreach (DictionaryEntry innerItem in rows)
                        {
                            if (oldRows.ContainsKey(innerItem.Key as string))
                            {
                                //Här finns en dublett! Det ska ladrig inträffa, för det ska vara unika som läggs till, även om det iofs är olika blad
                                Console.WriteLine("Double fond in CheckAllProfiles old rows: " + name + ". Key: >" + innerItem.Key as string + "<");
                            }
                            else
                                oldRows.Add(innerItem.Key as string, innerItem.Value as ExcelRowEntry);
                        }
                    }
                }
                #endregion

                compareExcelRows(saveSheet, oldRows, newRows);
            }
            catch (Exception allPexcp)
            {
                throw new Exception("Error in comparing AllProfiles log with new log. Was the log opened in Excel during compare processing?\r\n\r\n(Sys err: " + allPexcp.Message + ").", allPexcp);
            }

            return true;
        }