コード例 #1
0
        /// <summary>
        /// 範囲から値を検索する.
        /// </summary>
        /// <param name="range">検索範囲</param>
        /// <param name="targetStr">検索文字列</param>
        /// <param name="foundRow">見つかった行番号</param>
        /// <param name="FoundColumn">見つかった列番号</param>
        /// <param name="isPartialMatch">部分一致検索かどうか</param>
        /// <returns></returns>
        public bool Find(CellsRange searchRange, string keyword, out int foundRow, out int foundColumn, bool isPartialMatch = false)
        {
            Range xlSearchRange = null;
            Range xlFoundRange  = null;

            try
            {
                xlSearchRange = xlSheet.Range[searchRange.A1Address];
                XlLookAt xlLookAt = isPartialMatch ? XlLookAt.xlPart : XlLookAt.xlWhole;
                xlFoundRange = xlSearchRange.Find(What: keyword, LookAt: xlLookAt);
                if (xlFoundRange == null)
                {
                    foundRow    = 0;
                    foundColumn = 0;
                    return(false);
                }

                foundRow    = xlFoundRange.Row;
                foundColumn = xlFoundRange.Column;
                return(true);
            }
            finally
            {
                if (xlSearchRange != null)
                {
                    Marshal.ReleaseComObject(xlSearchRange);
                    xlSearchRange = null;
                }
                if (xlFoundRange != null)
                {
                    Marshal.ReleaseComObject(xlFoundRange);
                    xlFoundRange = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 指定セルに取り消し線が設定されているかを調べる
        /// </summary>
        /// <typeparam name="T">読み取ったときの型</typeparam>
        /// <param name="row">行番号(0開始)</param>
        /// <param name="column">列番号(0開始)</param>
        /// <returns></returns>
        public bool IsStrikethrough(CellsRange range)
        {
            Range xlRange = null;

            try
            {
                xlRange = xlSheet.Range[range.A1Address];
                bool?result = xlRange.Font.Strikethrough as bool?;
                return(result ?? false);
            }
            finally
            {
                if (xlRange != null)
                {
                    Marshal.ReleaseComObject(xlRange);
                    xlRange = null;
                }
            }
        }