Calc Guide
Chapter
2
Entering, Editing, and Formatting
Data
This document is Copyright © 2005–2011 by its contributors as listed below. You may distribute it and/or modify it under the terms of either the GNU General Public License (http://www.gnu.org/licenses/gpl.html), version 3 or later, or the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0/), version 3.0 or later.
All trademarks within this guide belong to their legitimate owners.
Contributors
Barbara Duprey
Hal Parker
Feedback
Please direct any comments or suggestions about this document to: documentation@libreoffice.org
Acknowledgments
This chapter is based on Chapter 2 of the OpenOffice.org 3.3 Calc Guide. The contributors to that chapter are:
Peter
Kupfer Andy Brown Stephen Buck
Iain Roberts Hazel Russman Barbara
M. Tobias
Jean Hollis Weber Jared Kobos
Publication date and software version
Published 12 April 2011. Based on LibreOffice 3.3.
Some keystrokes and menu items are different on a Mac from those used in Windows and Linux. The table below gives some common substitutions for the instructions in this chapter. For a more detailed list, see the application Help.
Windows/Linux |
Mac equivalent |
Effect |
Tools → Options menu selection |
LibreOffice → Preferences |
Access setup options |
Right-click |
Control+click |
Open context menu |
Ctrl (Control) |
z (Command) |
Used with other keys |
F5 |
Shift+z+F5 |
Open the Navigator |
F11 |
z+T |
Open Styles & Formatting window |
Contents
Entering data using the keyboard 5
Deactivating automatic changes 7
Using the Fill tool on cells 7
Sharing content between sheets 10
Replacing all the data in a cell 13
Changing part of the data in a cell 13
Formatting multiple lines of text 14
Shrinking text to fit the cell 15
Setting cell alignment and orientation 17
Formatting the cell borders 18
Formatting the cell background 18
Autoformatting cells and sheets 19
Formatting spreadsheets using themes 20
Using conditional formatting 20
Filtering which cells are visible 23
Finding and replacing in Calc 25
Using the Find & Replace dialog 25
Finding and replacing formulas or values 26
You can enter data into Calc in several ways: using the keyboard, the mouse (dragging and dropping), the Fill tool, and selection lists. Calc also provides the ability to enter information into multiple sheets of the same document at the same time.
After entering data, you can format and display it in various ways.
Entering data using the keyboard
Most data entry in Calc can be accomplished using the keyboard.
Click in the cell and type in the number using the number keys on either the main keyboard or the numeric keypad.
To enter a negative number, either type a minus (–) sign in front of it or enclose it in parentheses (brackets), like this: (1234).
By default, numbers are right-aligned and negative numbers have a leading minus symbol.
Click in the cell and type the text. Text is left-aligned by default.
If a number is entered in the format 01481, Calc will drop the leading 0. (Exception: see Tip below.) To preserve the leading zero, for example for telephone area codes, type an apostrophe before the number, like this: '01481.
The data is now treated as text and displayed exactly as entered. Typically, formulas will treat the entry as a zero and functions will ignore it.
Tip |
Numbers can have leading zeros and still be regarded as numbers (as opposed to text) if the cell is formatted appropriately. Right-click on the cell and chose Format Cells → Numbers. Adjust the Leading zeros setting to add leading zeros to numbers. |
Note |
When a plain apostrophe is used to allow a leading 0 to be displayed, it is not visible in the cell after the Enter key is pressed. If “smart quotes” are used for apostrophes, the apostrophe remains visible in the cell. To choose this type of apostrophe, use Tools → AutoCorrect Options → Localized Options. Select the Replace option for apostrophes to activate this function. The selection of the apostrophe type affects both Calc and Writer. |
Caution
|
When a number is formatted as text, take care that the cell containing the number is not used in a formula because Calc will ignore the value. |
Select the cell and type the date or time. You can separate the date elements with a slash (/) or a hyphen (–) or use text such as 10 Oct 03. Calc recognizes a variety of date formats. You can separate time elements with colons such as 10:43:45.
A “special” character is one not found on a standard English keyboard. For example, © ¾ æ ç ñ ö ø ¢ are all special characters. To insert a special character:
Place the cursor in your document where you want the character to appear.
Click Insert → Special Character to open the Special Characters dialog (Figure 1).
Select the characters (from any font or mixture of fonts) you wish to insert, in order; then click OK. The selected characters are shown in the bottom left of the dialog. As you select each character, it is shown alone at the bottom right, along with the numerical code for that character.
Note |
Different fonts include different special characters. If you do not find a particular special character you want, try changing the Font selection. |
To enter en and em dashes, you can use the Replace dashes option under Tools → AutoCorrect Options → Options tab. This option replaces two hyphens, under certain conditions, with the corresponding dash.
In the following table, the A and B represent text consisting of letters A to z or digits 0 to 9.
Text that you type: |
Result |
A - B (A, space, hyphen, space, B) |
A – B (A, space, en-dash, space, B) |
A -- B (A, space, hyphen, hyphen, space, B) |
A – B (A, space, en-dash, space, B) |
A--B (A, hyphen, hyphen, B) |
A—B (A, em-dash, B) |
A-B (A, hyphen, B) |
A-B (unchanged) |
A -B (A, space, hyphen, B) |
A -B (unchanged) |
A --B (A, space, hyphen, hyphen, B) |
A –B (A, space, en-dash, B) |
Deactivating automatic changes
Calc automatically applies many changes during data input, unless you deactivate those changes. You can also immediately undo any automatic changes with Ctrl+Z.
AutoCorrect changes
Automatic correction of typing errors, replacement of straight quotation marks by curly (custom) quotes, and starting cell content with an uppercase (capital) letter are controlled by Tools → AutoCorrect Options. Go to the Options or Replace tabs to deactivate any of the features that you do not want. On the Replace tab, you can also delete unwanted word pairs and add new ones as required.
AutoInput
When you are typing in a cell, Calc automatically suggests matching input found in the same column. To turn the AutoInput on and off, set or remove the check mark in front of Tools → Cell Contents → AutoInput.
Automatic date conversion
Calc automatically converts certain entries to dates. To ensure that an entry that looks like a date is interpreted as text, type an apostrophe at the beginning of the entry. The apostrophe is not displayed in the cell.
Entering data into a spreadsheet can be very labor-intensive, but Calc provides several tools for removing some of the drudgery from input.
The most basic ability is to drop and drag the contents of one cell to another with a mouse. Many people also find AutoInput helpful. Calc also includes several other tools for automating input, especially of repetitive material. They include the Fill tool, selection lists, and the ability to input information into multiple sheets of the same document.
At its simplest, the Fill tool is a way to duplicate existing content. Start by selecting the cell to copy, then drag the mouse in any direction (or hold down the Shift key and click in the last cell you want to fill), and then choose Edit → Fill and the direction in which you want to copy: Up, Down, Left or Right.
Caution
|
Choices that are not available are grayed out, but you can still choose the opposite direction from what you intend, which could cause you to overwrite cells accidentally. |
Tip |
A shortcut way to fill cells is to grab the “handle” in the lower right-hand corner of the cell and drag it in the direction you want to fill. If the cell contains a number, the number will fill in series. If the cell contains text, the same text will fill in the direction you chose. |
A more complex use of the Fill tool is to use a fill series. The default lists are for the full and abbreviated days of the week and the months of the year, but you can create your own lists as well.
To add a fill series to a spreadsheet, select the cells to fill, choose Edit → Fill → Series. In the Fill Series dialog, select AutoFill as the Series type, and enter as the Start value an item from any defined series. The selected cells then fill in the other items on the list sequentially, repeating from the top of the list when they reach the end of the list.
You can also use Edit → Fill → Series to create a one-time fill series for numbers by entering the start and end values and the increment. For example, if you entered start and end values of 1 and 7 with an increment of 2, you would get the sequence of 1, 3, 5, 7.
In all these cases, the Fill tool creates only a momentary connection between the cells. Once they are filled, the cells have no further connection with one another.
To define your own fill series, go to Tools → Options → LibreOffice Calc → Sort Lists. This dialog shows the previously-defined series in the Lists box on the left, and the contents of the highlighted list in the Entries box.
Click New. The Entries box is cleared. Type the series for the new list in the Entries box (one entry per line), and then click Add.
Selection lists are available only for text, and are limited to using only text that has already been entered in the same column.
To use a selection list, select a blank cell and press Ctrl+D. A drop-down list appears on any cell in the same column that either has at least one text character or whose format is defined as text. Click on the entry you require.
Sharing content between sheets
You might want to enter the same information in the same cell on multiple sheets, for example to set up standard listings for a group of individuals or organizations. Instead of entering the list on each sheet individually, you can enter it in all the sheets at once. To do this, select all the sheets (Edit → Sheet → Select), then enter the information in the current one.
Caution
|
This technique overwrites any information that is already in the cells on the other sheets—without any warning. For this reason, when you are finished, be sure to deselect all the sheets except the one you want to edit. (Ctrl+click on a sheet tab to select or deselect the sheet.) |
When creating spreadsheets for other people to use, you may want to make sure they enter data that is valid or appropriate for the cell. You can also use validation in your own work as a guide to entering data that is either complex or rarely used.
Fill series and selection lists can handle some types of data, but they are limited to predefined information. To validate new data entered by a user, select a cell and use Data → Validity to define the type of contents that can be entered in that cell. For example, a cell might require a date or a whole number, with no alphabetic characters or decimal points; or a cell may not be left empty.
Depending on how validation is set up, the tool can also define the range of values that can be entered and provide help messages that explain the content rules you have set up for the cell and what users should do when they enter invalid content. You can also set the cell to refuse invalid content, accept it with a warning, or—if you are especially well-organized—start a macro when an error is entered.
Validation is most useful for cells containing functions. If cells are set to accept invalid content with a warning, rather than refusing it, you can use Tools → Detective → Mark Invalid Data to find the cells with invalid data. The Detective function marks any cells containing invalid data with a circle.
Note that a validity rule is considered part of a cell’s format. If you select Format or Delete All from the Delete Contents window, then it is removed. (Repeating the Detective’s Mark Invalid Data command removes the invalid data circle, because the data is no longer invalid.) If you want to copy a validity rule with the rest of the cell, use Edit → Paste Special → Paste Formats or Paste All.
Figure 7 shows the choices for a typical validity test. Note the Allow blank cells option under the Allow list.
The validity test options vary with the type of data selected from the Allow list. For example, Figure 8 shows the choices when a cell must contain a cell range.
To provide input help for a cell, use the Input Help page of the Validity dialog (Figure 9). To show an error message when an invalid value is entered, use the Error Alert page (Figure 10). Be sure to write something helpful, explaining what a valid entry should contain—not just “Invalid data—try again” or something similar.
Editing data is done is in much the same way as entering it. The first step is to select the cell containing the data to be edited.
Data can be removed (deleted) from a cell in several ways.
The data alone can be removed from a cell without removing any of the formatting of the cell. Click in the cell to select it, and then press the Backspace key.
The data and the formatting can be removed from a cell at the same time. Press the Delete key (or right-click and choose Delete Contents, or use Edit → Delete Contents) to open the Delete Contents dialog (Figure 11). From this dialog, different aspects of the cell can be deleted. To delete everything in a cell (contents and format), check Delete all.
Replacing all the data in a cell
To remove data and insert new data, simply type over the old data. The new data will retain the original formatting.
Changing part of the data in a cell
Sometimes it is necessary to change the contents of a cell without removing all of the contents, for example when the phrase “See Dick run” is in a cell and it needs to be changed to “See Dick run fast.” It is often useful to do this without deleting the old cell contents first.
The process is the similar to the one described above, but you need to place the cursor inside the cell. You can do this in two ways.
After selecting the appropriate cell, press the F2 key and the cursor is placed at the end of the cell. Then use the keyboard arrow keys to move the cursor through the text in the cell.
Using the mouse, either double-click on the appropriate cell (to select it and place the cursor in it for editing), or single-click to select the cell and then move the mouse pointer up to the input line and click into it to place the cursor for editing.
The data in Calc can be formatted in several ways. It can either be edited as part of a cell style so that it is automatically applied, or it can be applied manually to the cell. Some manual formatting can be applied using toolbar icons. For more control and extra options, select the appropriate cell or cells range, right-click on it, and select Format Cells. All of the format options are discussed below.
Note |
All the settings discussed in this section can also be set as a part of the cell style. See Chapter 4, Using Styles and Templates, for more information. |
Formatting multiple lines of text
Multiple lines of text can be entered into a single cell using automatic wrapping or manual line breaks. Each method is useful for different situations.
To set text to wrap at the end of the cell, right-click on the cell and select Format Cells (or choose Format → Cells from the menu bar, or press Ctrl+1). On the Alignment tab (Figure 13), under Properties, select Wrap text automatically. The results are shown below (Figure 12).
To insert a manual line break while typing in a cell, press Ctrl+Enter. This method does not work with the cursor in the input line. When editing text, first double-click the cell, then single-click at the position where you want the line break.
When a manual line break is entered, the cell width does not change. Figure 14 shows the results of using two manual line breaks after the first line of text.
Shrinking text to fit the cell
The font size of the data in a cell can automatically adjust to fit in a cell. To do this, select the Shrink to fit cell option in the Format Cells dialog (Figure 13). Figure 15 shows the results.
Several different number formats can be applied to cells by using icons on the Formatting toolbar. Select the cell, then click the relevant icon. Some icons may not be visible in a default setup; click the down-arrow at the end of the Formatting bar and select other icons to display.
For more control or to select other number formats, use the Numbers tab (Figure 17) of the Format Cells dialog.
Apply any of the data types in the Category list to the data.
Control the number of decimal places and leading zeros.
Enter a custom format code.
The Language setting controls the local settings for the different formats such as the date order and the currency marker.
To quickly choose the font used in a cell, select the cell, then click the arrow next to the Font Name box on the Formatting toolbar and choose a font from the list.
Tip |
To choose whether to show the font names in their font or in plain text, go to Tools → Options → LibreOffice → View and select or deselect the Show preview of fonts option in the Font Lists section. For more information, see Chapter 14, Setting Up and Customizing Calc. |
To
choose the size of the font, click the arrow next to the Font Size
box on the Formatting toolbar. For other formatting, you can use the
Bold, Italic, or Underline icons.
To choose a font color, click the arrow next to the Font Color icon to display a color palette. Click on the required color.
(To define custom colors, use Tools → Options → LibreOffice → Colors. See Chapter 14 for more information.)
To specify the language of the cell (useful because it allows different languages to exist in the same document and be spell checked correctly), use the Font tab of the Format Cells dialog. See Chapter 4 for more information.
The Font Effects tab (Figure 18) of the Format Cells dialog offers more font options.
Overlining and underlining
You can choose from a variety of overlining and underlining options (solid lines, dots, short and long dashes, in various combinations) and the color of the line.
The strikethrough options include lines, slashes, and Xs.
Relief
The relief options are embossed (raised text), engraved (sunken text), outline, and shadow.
Setting cell alignment and orientation
Some of the cell alignment and orientation icons are not shown by default on the Formatting toolbar. To show them, click on the small arrow at the right-hand end of the toolbar and select them from the list of icons.
Some of the alignment and orientation icons are available only if you have Asian or CTL (Complex Text Layout) languages enabled (in Tools → Options → Language Settings → Languages). If you choose an unavailable icon from the list, it does not appear on the toolbar.
For more control and other choices, use the Alignment tab (Figure 13) of the Format Cells dialog to set the horizontal and vertical alignment and rotate the text. If you have Asian languages enabled, then the Text orientation section shows an extra option (labeled Asian layout mode) under the Vertically stacked option, as shown in Figure 20.
The difference in results between having Asian layout mode on or off is shown in Figure 21.
To quickly choose a line style and color for the borders of a cell, click the small arrows next to the Line Style and Line Color icons on the Formatting toolbar. If the Line Style and Line Color icons are not displayed in the formatting toolbar, select the down arrow on the right side of the bar, then select Visible Buttons. In each case, a palette of choices is displayed.
For more control, including the spacing between the cell borders and the text, use the Borders tab of the Format Cells dialog. There you can also define a shadow. See Chapter 4 for details.
Note |
The cell border properties apply to a cell, and can only be changed if you are editing that cell. For example, if cell C3 has a top border (which would be equivalent visually to a bottom border on C2), that border can only be removed by selecting C3. It cannot be removed in C2. |
Formatting the cell background
To quickly choose a background color for a cell, click the small arrow next to the Background Color icon on the Formatting toolbar. A palette of color choices, similar to the Font Color palette, is displayed.
(To define custom colors, use Tools → Options → LibreOffice → Colors. See Chapter 14 for more information.)
You can also use the Background tab of the Format Cells dialog. See Chapter 4 for details.
Autoformatting cells and sheets
You can use the AutoFormat feature to quickly apply a set of cell formats to a sheet or a selected cell range.
Select the cells that you want to format, including the column and row headers.
Choose Format → AutoFormat.
To select which properties (number format, font, alignment, borders, pattern, autofit width and height) to include in an AutoFormat, click More. Select or deselect the required options. Click OK.
If you do not see any change in color of the cell contents, choose View → Value Highlighting from the menu bar. This function only affects cells with numerical data.
Note |
If the selected cell range does not have column and row headers, AutoFormat is not available. |
You can define a new AutoFormat that is available to all spreadsheets.
Format a sheet.
Choose Edit → Select All.
Choose Format → AutoFormat. The Add button is now active.
Click Add.
In the Name box of the Add AutoFormat dialog, type a meaningful name for the new format.
Click OK to save. The new format is now available in the Format list in the AutoFormat dialog.
Formatting spreadsheets using themes
Calc comes with a predefined set of formatting themes that you can apply to your spreadsheets.
It is not possible to add themes to Calc, and they cannot be modified. However, you can modify their styles after you apply them to a spreadsheet.
To apply a theme to a spreadsheet:
Click the Choose Themes icon in the Tools toolbar. If this toolbar is not visible, you can show it using View → Toolbars → Tools. The Theme Selection dialog appears. This dialog lists the available themes for the whole spreadsheet.
In the Theme Selection dialog, select the theme that you want to apply to the spreadsheet. As soon as you select a theme, some of the properties of the custom styles are applied to the open spreadsheet and are immediately visible.
Click OK. If you wish, you can now go to the Styles and Formatting window to modify specific styles. These modifications do not change the theme; they only change the appearance of this specific spreadsheet document.
You can set up cell formats to change depending on conditions that you specify. For example, in a table of numbers, you can show all the values above the average in green and all those below the average in red.
Note |
To apply conditional formatting, AutoCalculate must be enabled. Choose Tools → Cell Contents → AutoCalculate. |
Conditional formatting depends upon the use of styles. If you are not familiar with styles, please refer to Chapter 4. An easy way to set up the required styles is to format a cell the way you want it and click the New Style from Selection icon in the Styles and Formatting window.
After the styles are set up, here is how to use them.
In your spreadsheet, select the cells to which you want to apply conditional formatting.
Choose Format → Conditional Formatting from the menu bar.
On the Conditional Formatting dialog (Figure 23), enter the conditions. Click OK to save. The selected cells are now formatted in the relevant style.
Cell value is / Formula is
Specifies whether conditional formatting is dependent on a cell value or on a formula. If you select cell value is, the Cell Value Condition box is displayed, as shown in the example. Here you can choose from conditions including less than, greater than, between, and others.
Parameter field
Enter a reference, value, or formula in the parameter field, or in both parameter fields if you have selected a condition that requires two parameters. You can also enter formulas containing relative references.
Cell style
Choose the cell style to be applied if the specified condition matches. The style must have been defined previously.
See the Help for more information and examples of use.
To
apply the same conditional formatting later to other cells:
Select one of the cells that has been assigned conditional formatting.
Copy the cell to the clipboard.
Select the cells that are to receive this same formatting.
Choose Edit → Paste Special.
On the Paste Special dialog, in the Selection area, select only the Formats option. Make sure all other options are not selected. Click OK.
When elements are hidden, they are neither visible nor printed, but can still be selected for copying if you select the elements around them. For example, if column B is hidden, it is copied when you select columns A and C. When you need a hidden element again, you can reverse the process, and show the element.
To hide or show sheets, rows, and columns, use the options on the Format menu or the right-click (context) menu. For example, to hide a row, first select the row, and then choose Format → Row → Hide (or right-click and choose Hide).
To hide or show selected cells, choose Format → Cells from the menu bar (or right-click and choose Format Cells). On the Format Cells dialog, go to the Cell Protection tab.
If you are continually hiding and showing the same cells, you can simplify the process by creating outline groups, which add a set of controls for hiding and showing the cells in the group that are quick to use and always available.
If the contents of cells fall into a regular pattern, such as four cells followed by a total, then you can use Data → Group and Outline → AutoOutline to have Calc add outline controls based on the pattern. Otherwise, you can set outline groups manually by selecting the cells for grouping, then choosing Data → Group and Outline → Group. On the Group dialog, you can choose whether to group the selected cells by rows or columns.
When you close the dialog, the outline group controls are visible between either the row or column headers and the edges of the editing window. The controls resemble the tree-structure of a file-manager in appearance, and can be hidden by selecting Data → Group and Outline → Hide Details. They are strictly for online use, and do not print.
The basic outline controls have plus or minus signs at the start of the group to show or hide hidden cells. However, if outline groups are nested, the controls have numbered buttons for hiding the different levels.
If you no longer need a group, place the mouse cursor in any cell in it and select Data → Group and Outline → Ungroup. To remove all groups on a sheet, select Data → Group and Outline → Remove.
Filtering which cells are visible
A filter is a list of conditions that each entry has to meet in order to be displayed. You can set three types of filters from the Data → Filter sub-menu.
Automatic filters add a drop-down list to the top row of a column that contains commonly used filters. They are quick and convenient and almost as useful with text as with numbers, because the list includes every unique entry in the selected cells.
In addition to these unique entries, automatic filters include the option to display all entries, the ten highest numerical values, and all cells that are empty or not empty, as well as a standard filter that you can customize (see below). However, they are somewhat limited. In particular, they do not allow regular expressions, so you cannot use them to display cell contents that are similar but not identical.
Standard filters are more complex than automatic filters. You can set as many as three conditions as a filter, combining them with the operators AND and OR. Standard filters are mostly useful for numbers, although a few of the conditional operators, such as = and < > can also be used for text.
Other conditional operators for standard filters include options to display the largest or smallest values, or a percentage of them. Useful in themselves, standard filters take on added value when they are used to further refine automatic filters.
Advanced filters are structured similarly to standard filters. The differences are that advanced filters are not limited to three conditions, and their criteria are not entered in a dialog. Instead, advanced filters are entered in a blank area of a sheet, then referenced by the advanced filter tool in order to apply them.
Sorting rearranges the visible cells on the sheet. In Calc, you can sort by up to three criteria, which are applied one after another. Sorts are handy when you are searching for a particular item, and become even more powerful after you have filtered data.
In addition, sorting is often useful when you add new information. When a list is long, it is usually easier to add new information at the bottom of the sheet, rather than inserting rows in the proper places. After you have added the information, you can sort it to update the sheet.
Highlight
the cells to be sorted, then select Data
→
Sort to open the Sort dialog (Figure 26) or click
the Sort
Ascending or Sort
Descending toolbar buttons. Using the dialog, you
can sort the selected cells using up to three columns, in either
ascending (A-Z, 1-9) or descending (Z-A, 9-1) order.
Tip |
You can define a custom sort order if the supplied alphanumeric ones do not fit your requirements. See “Defining a fill series” on page 9 for instructions. |
On the Options tab of the Sort dialog (Figure 27), you can choose the following options.
Case sensitive
If two entries are otherwise identical, one with an upper case letter is placed before one with a lower case letter in the same position if the sort is descending; if the sort is ascending, then the entry with an upper case letter is placed after one with a lower case letter in the same position.
Range contains column labels
Does not include the column heading in the sort.
Include formats
A cell's formatting is moved with its contents. If formatting is used to distinguish different types of cells, then use this option.
Copy sort results to
Sets a spreadsheet address to which to copy the sort results. If a range is specified that does not have the necessary number of cells, then cells are added. If a range contains cells that already have content, then the sort fails.
Custom sort order
Select the box, then choose from the drop-down list one of the sort orders defined in Tools → Options → LibreOffice Calc → Sort Lists.
Direction
Sets whether rows or columns are sorted. The default is to sort by columns unless the selected cells are in a single column.
Calc has two ways to find text within a document: the Find toolbar for fast text searching and the Find & Replace dialog.
The Find toolbar is located by default on the right-hand end of the Standard toolbar. You can hide or show the Find toolbar using View → Toolbars → Find.
Type a search term in the Find box, and then click the Find Next (down-arrow) or Find Previous (up-arrow) button. To find other occurrences of the same term, continue clicking the button.
Using the Find & Replace dialog
To display the Find & Replace dialog (Figure 28), use the keyboard shortcut Control+F or choose Edit → Find & Replace from the menu bar.
In spreadsheet documents you can search for text, formulas, and styles. You can navigate from one occurrence to the next using Find, or you can highlight all matching cells at once using Find All, then apply another format or replace the cell contents by other content.
Text and numbers in cells may have been entered directly or may be the result of a calculation. The search method you use depends on the type of data you are searching for.
Tip |
Cell contents can be formatted in different ways. For example, a number can be formatted as a currency, to be displayed with a currency symbol. You see the currency symbol in the cell, but you cannot search for it. |
By default, Calc searches the current sheet. To search through all sheets of the document, click More Options, then select Search in all sheets option.
Caution
|
Use Replace All with caution; otherwise, you may end up with some highly embarrassing mistakes. A mistake with Replace All might require a manual, word-by-word search to fix, if it is not discovered in time to undo it. |
Finding and replacing formulas or values
You can use the Find & Replace dialog to search in formulas or in the displayed values that result from a calculation.
To open the Find & Replace dialog, use the keyboard shortcut Control+F or select Edit → Find & Replace.
Click More Options to expand the dialog.
Select Formulas or Values in the Search in drop-down list.
Formulas finds parts of the formulas.
Values finds the results of the calculations.
Type the text you want to find in the Search for box.
To replace the text with different text, type the new text in the Replace with box.
When you have set up your search, click Find. To replace text, click Replace instead.
Open the Find & Replace dialog, click More Options to expand the dialog, and select Values or Notes in the Search in drop-down list.
Type the text you want to find in the Search for box.
To replace the text with different text, type the new text in the Replace with box.
Click Find, Find All, Replace, or Replace All.
When you click Find, Calc selects the next cell that contains your text. You can edit the text, then click Find again to advance to the next found cell. If you closed the dialog, you can press Ctrl+Shift+F to find the next cell without opening the dialog.
When you click Find All, Calc selects all cells that contain your entry. Now you can, for example, apply a cell style to all of them at once.
Finding and replacing cell styles
To quickly change all the paragraphs of one (unwanted) style to another (preferred) style:
On the expanded Find & Replace dialog, select Search for Styles. The Search for and Replace with boxes now contain a list of styles.
Select the styles you want to search for and replace.
Click Find, Find All, Replace, or Replace All.
Using wildcards (regular expressions)
Wildcards (also known as regular expressions) are combinations of characters that instruct LibreOffice how to search for something. Regular expressions are very powerful but not very intuitive. They can save time and effort by combining multiple finds into one.
To use wildcards and regular expressions when searching and replacing:
On the Find & Replace dialog, click More Options to see more choices. On this expanded dialog, select the Regular expressions option.
Type the search text, including the wildcards, in the Search for box and the replacement text (if any) in the Replace with box.
Click Find, Find All, Replace, or Replace All (not recommended).
Tip |
The online help describes many of the regular expressions and their uses. |
The following points may be of interest to Calc users:
In Calc, regular expressions are applied separately to each cell. This means that a search for r.d will match red in cell A1 but will not match r in cell A2 and d (or ed) in cell A3. (The regular expression r.d means the system will try to match r followed by any other character followed by d.)
When a match is found, the entire cell is highlighted but only the text found will be replaced. For example, searching for brown will result in highlighting a cell containing redbrown clay, and choosing nothing in the Replace with box leaves the cell containing red clay.
If Find is used twice in a row, and the second time the Current selection only box is activated, then the second search will evaluate the whole of each selected cell, not just the strings that caused the cells to be selected in the first search. For example, searching for joh?n, then activating Current selection only and searching for sm.th will find cells containing Jon Smith and Smythers, Johnathon.
If a cell contains a hard line break (entered by Ctrl+Enter), it may be found by using the regular expression \n. For example, if a cell contains red [hard line break] clay then searching for d\nc and entering nothing in the Replace with box leaves the cell containing relay.
The hard line break acts to mark “end of text” (similar to “end of paragraph” in Writer), found by the regular expression special character $, in addition to the end of text in the cell. For example, if a cell contains red [hard line break] clay then a search for d$ replacing with al leaves the cell with real [hard line break] clay. Note that with this syntax the hard line break is not replaced.
Using \n in the Replace with box will replace with the literal characters \n, not a hard line break.
The Find & Replace dialog has an option to search within formulas, values, or notes. This option applies to any search, not just one using regular expressions. Searching with the Formulas option for SUM would find a cell containing the formula =SUM(A1:A6) as well as a cell containing the simple text SUMMARY.
Searching for the regular expression ^$ will not find empty cells. This is intentional, to avoid performance issues when selecting a huge number of cells. Note that empty cells will not be found even if you are only searching a selection.
Finding cell contents using the regular expression .+ (or similar) and replacing them with & effectively re-enters the cell contents without any formatting. This technique can be used to remove formatting automatically applied by Calc when importing data from the clipboard or from badly formatted files. For example, to convert text strings consisting of digits into actual numbers, first format the cells as numbers and then perform the search and replace.
See Chapter 7, Using Formulas and Functions, for the use of regular expressions within formulas.