Commit e4b0ad9b authored by Jahrules's avatar Jahrules
Browse files

a couple initial changes to docs; also tightened up my try/catch with specific exception

--HG--
branch : 3.2
parent 8c66fd1dc903
Pipeline #53843 failed with stage
in 21 minutes and 47 seconds
......@@ -6,6 +6,8 @@ Instantiating a search
Create a search object supplying a Worksheet object
search takes a search text and optional boolean to ignore case and integer to limit result quantity
The default value for ignorecase is False (that is, case sensitive search)
The default value for limitresults is 0 (representing no limit)
.. :: doctest
......@@ -13,39 +15,32 @@ search takes a search text and optional boolean to ignore case and integer to li
>>> from openpyxl.utils.search import Search
>>> wb = Workbook()
>>> ws = wb.active
>>> Search = Search(ws,"searchtext")
>>> Search2 = search(ws,"searchtext", ignorecase=False)
>>> Search3 = search(ws,"searchtext", ignorecase=False, limitresults=1000)
>>> Search1 = Search(ws,"searchtext")
>>> Search2 = Search(ws,"searchtext", ignorecase=False)
>>> Search3 = Search(ws,"searchtext", ignorecase=False, limitresults=1000)
searching
---------
The search object supports common searches such as find all, find first, find next and find last
The find commands return None under the following circumstances:
find_all returns None if no cells matched
find_first returns None if no cells matched
find_last returns None if no cells matched
find_next returns None if no cells matched or if we have exhausted the results list.
.. :: doctest
>>> from openpyxl import Workbook
>>> from openpyxl.utils.search import Search
>>> wb = Workbook()
>>> ws = wb.active
>>> Search = Search(ws,"searchtext")
>>> Search.find_all()
<array of cells>
<list of cells> or None
>>> Search.find_first()
<cell>
<cell> or None
>>> Search.find_next()
<cell>
<cell> or None
>>> Search.find_last()
<cell>
replacing searchtext
--------------------
Replace should be used with caution as it will replace contents of any cell that matches (even partial)
.. :: doctest
>>> from openpyxl import Workbook
>>> wb = Workbook()
>>> ws = wb.active
>>> Search = Search(ws,"searchtext")
>>> Search.Replace("newtext")
<cell> or None
import re
from warnings import warn
class Search:
"""
Search object to mimic a standard search and find/replace feature
......@@ -131,7 +132,7 @@ class Search:
try:
retval = next(self._searchiter)
except:
except StopIteration:
return None
return retval
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment