public void シートチェック_セル位置違い()
        {
            var st = Stiffer.GetInstance();
            try
            {
                var cd = System.IO.Directory.GetCurrentDirectory();

                var criteria = new SheetInfo
                {
                    Name = "",
                    CellPosition = new System.Drawing.Point(0, 0),
                    Zoom = 100,
                    Gridlines = false,
                    View = Microsoft.Office.Interop.Excel.XlWindowView.xlNormalView
                };

                var sheet = new SheetInfo
                {
                    Name = "",
                    CellPosition = new System.Drawing.Point(1, 0),
                    Zoom = 100,
                    Gridlines = false,
                    View = Microsoft.Office.Interop.Excel.XlWindowView.xlNormalView
                };
                var result = new[] { true, true, true, true };

                st.CompareSheetInfo(criteria, sheet, result);
                Assert.True(result[0] == false);
                Assert.True(result[1] == true);
                Assert.True(result[2] == true);
                Assert.True(result[3] == true);
            }
            finally
            {
                st.Dispose();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Excelシート各種情報取得
        /// </summary>
        private SheetInfo GetSheetInformation(Excel.Worksheet oSheet)
        {
            SheetInfo       info            = null;
            Excel.Range     oCells          = null;
            Excel.Worksheet oActiveSheet    = null;
            Excel.Window    oActiveWindow   = null;

            Debug.Assert(oSheet != null);
            try
            {
                if (oSheet == null)
                {
                    return null;
                }

                // シートをアクティベートする
                oActiveSheet    = (Excel.Worksheet)this._app.ActiveSheet;
                oSheet.Activate();
                oActiveWindow   = this._app.ActiveWindow;
                oCells          = oActiveWindow.ActiveCell;

                // シート情報取得および格納
                info = new SheetInfo();
                {
                    info.Name           = oSheet.Name;
                    info.Zoom           = (double)oActiveWindow.Zoom;
                    info.Gridlines      = oActiveWindow.DisplayGridlines;
                    info.View           = oActiveWindow.View;
                    info.CellPosition = new Point((int)oCells.Column, (int)oCells.Row);
                }
            }
            finally
            {
                if (oActiveSheet != null)
                {
                    oActiveSheet.Activate();
                    Marshal.ReleaseComObject(oActiveSheet);
                }
                oActiveSheet = null;

                if (oActiveWindow != null)
                {
                    Marshal.ReleaseComObject(oActiveWindow);
                }
                oActiveWindow = null;

                if (oCells != null)
                {
                    Marshal.ReleaseComObject(oCells);
                }
                oCells = null;
            }
            return info;
        }
Beispiel #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="criteria"></param>
 /// <param name="book"></param>
 public void CheckSheetInformations(SheetInfo criteria, BookInfo book)
 {
     try
     {
         book.Result = true;
         foreach (var sheet in book.Sheets)
         {
             this.CompareSheetInfo(criteria, sheet, book.CheckResult);
         }
     }
     finally
     {
     }
     return;
 }
Beispiel #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="criteria"></param>
 /// <param name="sheet"></param>
 /// <param name="checkResult"></param>
 private void CompareSheetInfo(SheetInfo criteria, SheetInfo sheet, bool[] checkResult)
 {
     if (criteria.CellPosition != sheet.CellPosition)
     {
         checkResult[0] = false;
     }
     if (criteria.Zoom != sheet.Zoom)
     {
         checkResult[1] = false;
     }
     if (criteria.Gridlines != sheet.Gridlines)
     {
         checkResult[2] = false;
     }
     if (criteria.View != sheet.View)
     {
         checkResult[3] = false;
     }
     return;
 }
        /// <summary>
        /// ブック情報の取得
        /// </summary>
        /// <param name="files">ファイル名配列</param>
        private List<BookInfo> getBookInformations(string[] files)
        {
            var list = new List<BookInfo>();

            // この値が基準だ
            var criteria = new SheetInfo
            {
                CellPosition    = new System.Drawing.Point(1, 1),
                Zoom            = Double.Parse(this.zoom.Text),
                Gridlines       = this.gridOn.Checked,
                View            = this.view.Text == "標準モード" ?
                                      Microsoft.Office.Interop.Excel.XlWindowView.xlNormalView
                                    : Microsoft.Office.Interop.Excel.XlWindowView.xlPageBreakPreview
            };
            // 設定を保存しておく
            {
                Settings.Default.zoom   = criteria.Zoom ;
                Settings.Default.grid   = this.gridOn.Checked;
                Settings.Default.view   = this.view.Text;
                Settings.Default.Save();
            }

            // 情報取得
            foreach( var file in files )
            {
                var info = this.stiffer.GetBookInformations(file);
                this.stiffer.CheckSheetInformations(criteria, info);
                list.Add(info);
            }
            return list;
        }