Spreadsheet Workbench: Difference between revisions
(typo) |
(Docnav) |
||
(32 intermediate revisions by 5 users not shown) | |||
Line 5: | Line 5: | ||
{{Docnav |
{{Docnav |
||
|[[Sketcher_Workbench|Sketcher Workbench]] |
|[[Sketcher_Workbench|Sketcher Workbench]] |
||
|[[ |
|[[Surface_Workbench|Surface Workbench]] |
||
|IconL=Workbench_Sketcher.svg |
|IconL=Workbench_Sketcher.svg |
||
|IconR= |
|IconR=Workbench_Surface.svg |
||
}} |
}} |
||
Line 79: | Line 79: | ||
<!--T:135--> |
<!--T:135--> |
||
* [[Image:Preferences-spreadsheet.svg|32px]] [[Spreadsheet_Preferences|Preferences]]: the preferences for the Spreadsheet Workbench. {{Version|0.20}} |
* [[Image:Preferences-spreadsheet.svg|32px]] [[Spreadsheet_Preferences|Preferences]]: the preferences for the Spreadsheet Workbench. {{Version|0.20}} |
||
== Removing cells can be dangerous == <!--T:183--> |
|||
⚫ | |||
⚫ | |||
== Insert and remove rows and columns == <!--T:136--> |
== Insert and remove rows and columns == <!--T:136--> |
||
Line 85: | Line 90: | ||
Rows and columns can be inserted or removed by right-clicking a row or column header and selecting the appropriate option from the contex menu. It is possible to select multiple rows or columns first. Either by holding down the {{KEY|Ctrl}} key while selecting the headers, or by holding down the left mouse button and dragging. |
Rows and columns can be inserted or removed by right-clicking a row or column header and selecting the appropriate option from the contex menu. It is possible to select multiple rows or columns first. Either by holding down the {{KEY|Ctrl}} key while selecting the headers, or by holding down the left mouse button and dragging. |
||
<!--T: |
== Edit cells == <!--T:184--> |
||
In FreeCAD version 0.19 and earlier rows are inserted above the selected rows, and colomns on the left of the selected columns. In FreeCAD version 0.20 you can specify the insertion side. |
|||
<!--T: |
<!--T:185--> |
||
The content of a cell can be edited by selecting the cell and entering a value in the {{MenuCommand|Content}} inputbox at the top of the window. To edit a cell in-place, select it and press {{KEY|F2}}, or double-click it. |
|||
Note that removing rows or columns with data can break the spreadsheet and your model if it relies on the spreadheet. You are not prewarned if this happens. |
|||
== Delete cells == <!--T:186--> |
|||
⚫ | |||
To delete one or more cells select them and press {{KEY|Del}}. This will delete their contents, their properties and their aliases. To only delete the content of a cell it should be edited instead. |
|||
== Cut and copy-paste cells == <!--T:140--> |
== Cut and copy-paste cells == <!--T:140--> |
||
<!--T:141--> |
<!--T:141--> |
||
Cut and copy-paste operations can be used on cells |
Cut and copy-paste operations can be used on spreadsheets cells. You can use the normal shortcuts for these operations: {{KEY|Ctrl}}+{{KEY|X}}, {{KEY|Ctrl}}+{{KEY|C}} and {{KEY|Ctrl}}+{{KEY|V}} respectively. To select multiple cells hold down the {{KEY|Ctrl}} key while selecting, or hold down the left mouse button and drag to select a rectangular cell range. |
||
<!--T:142--> |
<!--T:142--> |
||
The cut and copy operations store the contents and |
The cut and copy operations store the contents, properties and aliases of the cells on the Clipboard. The paste operation writes the data in such a way that the content of the top left cell of the stored data is dropped in the active cell. Other stored content is placed relative to that cell. Formulas are updated accordingly. Aliases are only pasted if they are unique. |
||
⚫ | |||
⚫ | |||
⚫ | |||
In FreeCAD version 0.19 and earlier there is a bug that can cause FreeCAD to hang if a non-rectangular cell range is pasted. It is advisable to save your work before performing any paste operations. |
|||
== Cell properties == <!--T:21--> |
== Cell properties == <!--T:21--> |
||
Line 120: | Line 123: | ||
* Alignment: Text horizontal and vertical alignment |
* Alignment: Text horizontal and vertical alignment |
||
* Style: Text style: bold, italic, underline |
* Style: Text style: bold, italic, underline |
||
* Units: |
* Units: Display units for this cell. Please read the [[#Units|Units]] section below. |
||
* Alias: |
* Alias: Define an [[Spreadsheet_SetAlias|alias]] for this cell. This alias can be used in cell formulas and also in general [[Expressions|expressions]]; see section [[#Spreadsheet_data_in_expressions|Spreadsheet data in expressions]] for more information. |
||
== Cell expressions == <!--T:53--> |
== Cell expressions == <!--T:53--> |
||
<!--T:54--> |
<!--T:54--> |
||
A spreadsheet cell may contain |
A spreadsheet cell may contain a number, a text or an expression. Expressions must start with an equal sign '='. |
||
<!--T:55--> |
<!--T:55--> |
||
Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model (But see [[#Current_limitations|Current limitations]] below). |
Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model (But see [[#Current_limitations|Current limitations]] below). A cell can be referenced by its address (CAPITAL column letter + row number, e.g. B4) or by its [[Spreadsheet_SetAlias|alias]]. |
||
Example: B4 + A6 |
|||
<!--T:91--> |
<!--T:91--> |
||
'''Note:''' Cell expressions are treated by FreeCAD as programming code. Therefore, when you edit a cell the content you see |
'''Note:''' Cell expressions are treated by FreeCAD as programming code. Therefore, when you edit a cell the content you see may not follow your display settings: |
||
* |
* The decimal separator is always a dot. But commas can also be used when entering values. |
||
* |
* The number of displayed decimals can differ from your [[Preferences_Editor#Units|preferences settings]]. |
||
<!--T:63--> |
<!--T:63--> |
||
Line 152: | Line 154: | ||
<!--T:92--> |
<!--T:92--> |
||
FreeCAD will automatically assign a unique name to a spreadsheet when it is created. These names follow the pattern {{incode|Spreadsheet}}, {{incode|Spreadsheet001}}, {{incode|Spreadsheet002}} and so on. The name can not be changed |
FreeCAD will automatically assign a unique name to a spreadsheet when it is created. These names follow the pattern {{incode|Spreadsheet}}, {{incode|Spreadsheet001}}, {{incode|Spreadsheet002}} and so on. The name can not be changed, and it is not visible in the properties of the spreadsheet. It can be used to refer to the spreadsheet in an [[Expressions|Expression]] (see [[#Spreadsheet_data_in_expressions|Spreadsheet data in expressions]] below.) |
||
<!--T:93--> |
<!--T:93--> |
||
The label of a spreadsheet is automatically set to the name of the spreadsheet upon creation. Unlike the name, the label can be changed, for example in the properties panel or using the context menu action Rename. |
The label of a spreadsheet is automatically set to the name of the spreadsheet upon creation. Unlike the name, the label can be changed, for example in the properties panel or using the context menu action Rename. By default FreeCAD does not accept duplicate labels, but there is a [[Preferences_Editor#Document|preference]] to override this. Spreadsheets with duplicate labels in the same document cannot be referenced by their label. |
||
<!--T:69--> |
<!--T:69--> |
||
Line 164: | Line 166: | ||
<!--T:20--> |
<!--T:20--> |
||
As indicated above, one can reference data from the CAD model in spreadsheet expressions. |
As indicated above, one can reference data from the CAD model in spreadsheet expressions. |
||
<!--T:70--> |
|||
Computed expressions in spreadsheet cells start with an equals ('=') sign. However, the spreadsheet entry mechanism attempts to be smart. An expression may be entered without the leading '='; if the string entered is a valid expression, an '=' is automatically added when the final {{KEY|Enter}} is typed. If the string entered is not a valid expression (often the result of entering something with the wrong case, e.g. "MyCube.length" instead of "MyCube.Length"), no leading '=' is added and it is treated as simply a text string. |
|||
<!--T:71--> |
|||
'''Note:''' The above behavior (auto insert of '=') has some unpleasant ramifications: |
|||
* If you want to keep a column of names corresponding to the [[#alias_name|alias-names]] in an adjacent column of values, you must enter the name in the label column ''before'' giving the cell in the value column its alias-name. Otherwise, when you enter the alias-name in the label column the spreadsheet will assume it is an expression and change it to "=<alias-name>"; and the displayed text will be the value from the <alias-name> cell. |
|||
* If you make an error when entering the name in the label column and wish to correct it, you cannot simply change it to the alias-name. Instead, you must first change the alias-name to something else, then fix the text name in the label column, then change the alias-name in the value column back to its original. |
|||
<!--T:72--> |
|||
One way to side-step these issues is to prefix text labels corresponding to alias-names with a fixed string, thereby making them different. Note that "_" will not work, as it is converted to "=". However, a blank, while invisible, will work. |
|||
<!--T:73--> |
<!--T:73--> |
||
Line 184: | Line 175: | ||
|- |
|- |
||
|Parametric Length of a Part-Workbench Cube |
|Parametric Length of a Part-Workbench Cube |
||
|=MyCube.Length |
|{{Incode|<nowiki>=MyCube.Length</nowiki>}} |
||
|Length with units mm |
|Length with units mm |
||
|- |
|- |
||
|Volume of the Cube |
|Volume of the Cube |
||
|=MyCube.Shape.Volume |
|{{Incode|<nowiki>=MyCube.Shape.Volume</nowiki>}} |
||
|Volume in mm³ without units |
|Volume in mm³ without units |
||
|- |
|- |
||
|Type of the Cube-shape |
|Type of the Cube-shape |
||
|=MyCube.Shape.ShapeType |
|{{Incode|<nowiki>=MyCube.Shape.ShapeType</nowiki>}} |
||
|String: Solid |
|String: Solid |
||
|- |
|- |
||
|Label of the Cube |
|Label of the Cube |
||
|=MyCube.Label |
|{{Incode|<nowiki>=MyCube.Label</nowiki>}} |
||
|String: MyCube |
|String: MyCube |
||
|- |
|- |
||
| |
|X coordinate of the center of mass of the Cube |
||
|=MyCube.Shape.CenterOfMass.x |
|{{Incode|<nowiki>=MyCube.Shape.CenterOfMass.x</nowiki>}} |
||
| |
|Coordinate in mm without units |
||
|} |
|} |
||
Line 226: | Line 217: | ||
<!--T:96--> |
<!--T:96--> |
||
<div class="mw-collapsible mw-collapsed"> |
<div class="mw-collapsible mw-collapsed"> |
||
The recommended way to refer to spreadsheet data is to use the spreadsheet label and cell alias name. For a more in-depth explanation of the pros and cons of the |
The recommended way to refer to spreadsheet data is to use the spreadsheet label and cell alias name. For a more in-depth explanation of the pros and cons of the referencing modes, see the expanded section below. |
||
<div class="mw-collapsible-content"> |
<div class="mw-collapsible-content"> |
||
Line 236: | Line 227: | ||
<!--T:99--> |
<!--T:99--> |
||
While you may use the row and column number in an expression to reference a cell, best practice is to give the cell an alias name and use that. See [[# |
While you may use the row and column number in an expression to reference a cell, best practice is to give the cell an alias name and use that. See [[#Cell_properties|Cell properties]] on how to set the alias. For example, if the data in cell B1 contained the length parameter for an object, an alias name of {{incode|MyObject_Length}} would allow the value to be referred to as {{incode|<<MyParams>>.MyObject_Length}} instead of {{incode|Spreadsheet.B1}}. Besides being much easier to read and understand, alias names are also much easier to change if you decide to adjust the structure of your spreadsheet. Using an alias also has the advantage that it is reasier to see which cells are used to control other parts of the document. Note that FreeCAD will automatically adjust the positional references in expressions if you insert or remove rows and columns in the spreadsheet, so even if you use row and column numbers in an expression, you can insert rows and columns without breaking the references to the surrounding cells. |
||
<!--T:101--> |
<!--T:101--> |
||
Line 272: | Line 263: | ||
<!--T:28--> |
<!--T:28--> |
||
You can change the units displayed for a cell value using the |
You can change the units displayed for a cell value using the [[#Cell_properties|Cell properties dialog]]. This does not change the value contained in the cell; it only converts the existing value for display. The value used for calculations does not change, and the results of formulas using the value do not change. For example, a cell containing the value "5.08cm" can be displayed as "2in" by changing the units tab value to "in". |
||
<!--T:29--> |
<!--T:29--> |
||
Line 500: | Line 491: | ||
<!--T:182--> |
<!--T:182--> |
||
Similar steps apply to a [[PartDesign_SubShapeBinder|PartDesign SubShapeBinder]], except that its property for activating a variant instance is called {{PropertyData| |
Similar steps apply to a [[PartDesign_SubShapeBinder|PartDesign SubShapeBinder]], except that its property for activating a variant instance is called {{PropertyData|Bind Copy On Change}}. |
||
</translate> |
</translate> |
||
Line 530: | Line 521: | ||
{{Docnav |
{{Docnav |
||
|[[Sketcher_Workbench|Sketcher Workbench]] |
|[[Sketcher_Workbench|Sketcher Workbench]] |
||
|[[ |
|[[Surface_Workbench|Surface Workbench]] |
||
|IconL=Workbench_Sketcher.svg |
|IconL=Workbench_Sketcher.svg |
||
|IconR= |
|IconR=Workbench_Surface.svg |
||
}} |
}} |
||
</translate> |
</translate> |
Revision as of 18:45, 25 April 2024
Introduction
The Spreadsheet Workbench allows you to create and edit spreadsheets, use data from the spreadsheet as parameters in a model, fill the spreadsheet with data retrieved from a model, perform calculations, and export the data to other spreadsheet applications such as LibreOffice or Microsoft Excel.
A spreadsheet with certain cells filled with text and quantities
Tools
Create sheet: create a new spreadsheet.
Import: import a CSV file into a spreadsheet.
Export: export a CSV file from a spreadsheet.
Merge cells: merge selected cells.
Split cell: split previously merged cells.
Align left: align the contents of selected cells to the left.
Align center: align the contents of selected cells to the center horizontally.
Align right: align the contents of selected cells to the right.
Align top: align the contents of selected cells to the top.
Align vertical center: align the contents of selected cells to the center vertically.
Align bottom: top align the contents of selected cells to the bottom.
Style bold: set the contents of selected cells to bold.
Style italic: set the contents of selected cells to italic.
Style underline: set the contents of selected cells to underlined.
Set alias: set the alias for a selected cell.
- Black and White set the foreground and the background colors of selected cells.
Preferences
Preferences: the preferences for the Spreadsheet Workbench. introduced in version 0.20
Removing cells can be dangerous
Note that deleting or removing cells with data can break the spreadsheet and your model if it relies on the spreadheet. You are not prewarned if this happens.
Insert and remove rows and columns
Rows and columns can be inserted or removed by right-clicking a row or column header and selecting the appropriate option from the contex menu. It is possible to select multiple rows or columns first. Either by holding down the Ctrl key while selecting the headers, or by holding down the left mouse button and dragging.
Edit cells
The content of a cell can be edited by selecting the cell and entering a value in the Content inputbox at the top of the window. To edit a cell in-place, select it and press F2, or double-click it.
Delete cells
To delete one or more cells select them and press Del. This will delete their contents, their properties and their aliases. To only delete the content of a cell it should be edited instead.
Cut and copy-paste cells
Cut and copy-paste operations can be used on spreadsheets cells. You can use the normal shortcuts for these operations: Ctrl+X, Ctrl+C and Ctrl+V respectively. To select multiple cells hold down the Ctrl key while selecting, or hold down the left mouse button and drag to select a rectangular cell range.
The cut and copy operations store the contents, properties and aliases of the cells on the Clipboard. The paste operation writes the data in such a way that the content of the top left cell of the stored data is dropped in the active cell. Other stored content is placed relative to that cell. Formulas are updated accordingly. Aliases are only pasted if they are unique.
Cell properties
The properties of a spreadsheet cell can be edited by right-clicking the cell and selecting Properties... from the context menu. The following dialog pops up:
As indicated by the tabs, the following properties can be changed:
- Color: Text color and background color
- Alignment: Text horizontal and vertical alignment
- Style: Text style: bold, italic, underline
- Units: Display units for this cell. Please read the Units section below.
- Alias: Define an alias for this cell. This alias can be used in cell formulas and also in general expressions; see section Spreadsheet data in expressions for more information.
Cell expressions
A spreadsheet cell may contain a number, a text or an expression. Expressions must start with an equal sign '='.
Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model (But see Current limitations below). A cell can be referenced by its address (CAPITAL column letter + row number, e.g. B4) or by its alias.
Note: Cell expressions are treated by FreeCAD as programming code. Therefore, when you edit a cell the content you see may not follow your display settings:
- The decimal separator is always a dot. But commas can also be used when entering values.
- The number of displayed decimals can differ from your preferences settings.
References to objects in the model are explained under References to CAD-data below. Using spreadsheet cell values to define model properties are explained under Spreadsheet data in expressions below. For more information on expressions and the available functions, see Expressions.
Interaction between spreadsheets and the CAD model
Data in the cells of a spreadsheet may be used in CAD model parameter expressions. Thus, a spreadsheet may be used as the source for parameter values used throughout a model, effectively gathering the values in one place. When values are changed in the spreadsheet, they are propagated throughout the model.
Similarly, properties from CAD model objects may be used in expressions in spreadsheet cells. This allows use of object properties like volume or area in the spreadsheet. If the name of an object in the CAD model is changed, the change will automatically be propagated to any references in spreadsheet expressions using the name which was changed.
More than one spreadsheet may be used in a document. A spreadsheet can be identified using either its name or its label.
FreeCAD will automatically assign a unique name to a spreadsheet when it is created. These names follow the pattern Spreadsheet
, Spreadsheet001
, Spreadsheet002
and so on. The name can not be changed, and it is not visible in the properties of the spreadsheet. It can be used to refer to the spreadsheet in an Expression (see Spreadsheet data in expressions below.)
The label of a spreadsheet is automatically set to the name of the spreadsheet upon creation. Unlike the name, the label can be changed, for example in the properties panel or using the context menu action Rename. By default FreeCAD does not accept duplicate labels, but there is a preference to override this. Spreadsheets with duplicate labels in the same document cannot be referenced by their label.
FreeCAD checks for cyclic dependencies. See Current limitations.
References to CAD-data
As indicated above, one can reference data from the CAD model in spreadsheet expressions.
The following table shows some examples assuming the model has a feature named "MyCube":
CAD-Data | Cell in Spreadsheet | Result |
---|---|---|
Parametric Length of a Part-Workbench Cube | =MyCube.Length
|
Length with units mm |
Volume of the Cube | =MyCube.Shape.Volume
|
Volume in mm³ without units |
Type of the Cube-shape | =MyCube.Shape.ShapeType
|
String: Solid |
Label of the Cube | =MyCube.Label
|
String: MyCube |
X coordinate of the center of mass of the Cube | =MyCube.Shape.CenterOfMass.x
|
Coordinate in mm without units |
Spreadsheet data in expressions
In order to use spreadsheet data in other parts of FreeCAD, you will usually create an Expression that refers to the spreadsheet and the cell that contains the data you want to use. You can identify spreadsheets by name or by label, and you can identify the cells by address or by alias. Autocompletion is available for all forms of referencing.
Spreadsheet by Name | Spreadsheet by Label | |
---|---|---|
Cell by Address | =Spreadsheet042.B5
|
=<<MySpreadsheet>>.B5
|
Cell by Alias | =Spreadsheet042.MyAlias
|
=<<MySpreadsheet>>.MyAlias
|
The recommended way to refer to spreadsheet data is to use the spreadsheet label and cell alias name. For a more in-depth explanation of the pros and cons of the referencing modes, see the expanded section below.
Using the spreadsheet label has the advantage that it can be freely changed to describe the contents of the spreadsheet. It is also easier to identify the spreadsheet that is being used since the text in the expression matches the label shown in the model and property views. If you decide to change the label of a spreadsheet, existing references to the contents of the spreadsheet will be updated, so you won't break your expressions by renaming the spreadsheet. The internal name of the spreadsheet is not readily available anywhere except within the expression editor, so if you use the internal name and later decide to rename the spreadsheets, you might have a hard time tracing your expression data back to its source.
Be aware that when you create a new spreadsheet, the name and the label are the same, so it is easy to accidentally use the spreadsheet name instead of the label. A simple way to avoid this is to give the spreadsheet a meaningful name before starting to use it in expressions.
While you may use the row and column number in an expression to reference a cell, best practice is to give the cell an alias name and use that. See Cell properties on how to set the alias. For example, if the data in cell B1 contained the length parameter for an object, an alias name of MyObject_Length
would allow the value to be referred to as <<MyParams>>.MyObject_Length
instead of Spreadsheet.B1
. Besides being much easier to read and understand, alias names are also much easier to change if you decide to adjust the structure of your spreadsheet. Using an alias also has the advantage that it is reasier to see which cells are used to control other parts of the document. Note that FreeCAD will automatically adjust the positional references in expressions if you insert or remove rows and columns in the spreadsheet, so even if you use row and column numbers in an expression, you can insert rows and columns without breaking the references to the surrounding cells.
Complex models and recomputes
Editing a spreadsheet will trigger a recompute of the 3D model, even if the changes do not affect the model. For a complex model a recompute can take a long time, and having to wait after every single edit is of course quite annoying.
There are three solutions to deal with this:
- Temporarily skip recomputes:
- In the Tree view right-click the
document that contains the spreadsheet.
- Select the Skip recomputes option from the context menu.
- There is a big disadvantage to this solution. New values entered in the spreadsheet will not be displayed until the document is recomputed. Instead
#PENDING
is shown. - You can either recompute manually, using the Std Refresh command, or disable Skip recomputes when you are done editing.
- In the Tree view right-click the
- Use a macro to automatically skip recomputes while editing a spreadsheet:
- Download and run skipSheet.FCMacro.
- This solution saves a few steps compared to the first solution, but also has the mentioned disadvantage.
- Put the spreadsheet in a separate FreeCAD file:
- You can reference spreadsheet data from an external .FCStd file with this syntax:
=NameOfFile#<<MySpreadsheet>>.MyAlias
. - The advantage of having the spreadsheet in another file over switching off recomputes is that the spreadsheet itself does get recomputed.
- The disadvantage is that the model won't automatically recompute after changes to the spreadsheet.
- In the scenario where you first open the 'spreadsheet' file, change one or more values and then open the 'model' file, there won't be any indication that the model needs to be recomputed. But if both files are open the Std Refresh icon will update correctly for the 'model' file after changes to the 'spreadsheet' file.
- You can reference spreadsheet data from an external .FCStd file with this syntax:
Units
The Spreadsheet has a notion of dimension (units) associated with cell values. A number entered without an associated unit has no dimension. The unit should be entered immediately following the number value, with no intervening space. If a number has an associated unit, that unit will be used in all calculations. For example, the multiplication of two lengths with the unit mm gives an area with the unit mm².
If a cell contains a value which represents a dimension, it should be entered with its associated unit. While in many simple cases one can get by with a dimensionless value, it is unwise to not enter the unit. If a value representing a dimension is entered without its associated unit, there are some sequences of operations which cause FreeCAD to complain of incompatible units in an expression when it appears the expression should be valid. (This may be better understood by viewing this thread in the FreeCAD forums.)
You can change the units displayed for a cell value using the Cell properties dialog. This does not change the value contained in the cell; it only converts the existing value for display. The value used for calculations does not change, and the results of formulas using the value do not change. For example, a cell containing the value "5.08cm" can be displayed as "2in" by changing the units tab value to "in".
A dimensionless number cannot be changed to a number with a unit by the cell properties dialog. One can put in a unit string, and that string will be displayed; but the cell still contains a dimensionless number. In order to change a dimensionless value to a value with a dimension, the value itself must be re-entered with its associated unit.
Occasionally it may be desirable to get rid of a dimension in an expression. This can be done by multiplying by 1 with a reciprocal unit.
Importing and exporting
CSV format
FreeCAD spreadsheets can be imported and exported to the CSV format which can also be read and written by most other spreadsheet applications such as Microsoft Excel or LibreOffice Calc. See Spreadsheet Import and Spreadsheet Export for more information.
XLSX format
Spreadsheets in the Excel-format XLSX can be imported with the Std Import command or the Std Open command. The following features are supported:
- All functions that are also available in the FreeCAD spreadsheet. Other functions give an error in the corresponding cell after import.
- Alias names for cells.
- More than one sheet in the Excel-spreadsheet. In this case one FreeCAD spreadsheet is created for each Excel sheet.
Other functionality is not imported into the FreeCAD spreadsheet.
Printing
To handle the page setup necessary for printing, FreeCAD spreadsheets are printed by inserting them into a TechDraw Spreadsheet View.
Current limitations
FreeCAD checks for cyclic dependencies when it recomputes. By design, that check stops at the level of the spreadsheet object. As a consequence, you should not have a spreadsheet which contains both cells whose values are used to specify parameters to the model, and cells whose values use output from the model. For example, you cannot have cells specifying the length, width, and height of an object, and another cell which references the total volume of the resulting shape. This restriction can be surmounted by having two spreadsheets: one used as a data-source for input parameters to the model and the other used for calculations based on resultant geometry-data.
Cell binding
It is possible to bind the content of cells to other spreadsheet cells. This can be useful when dealing with large tables or to get cell content from another spreadsheet.
Create binding
To bind, for example, the cell range A3-C4 to the cell range B1-D2:
- Select the cell range A3-C4.
- Right-click and select Bind... from the context menu.
- The Bind Spreadsheet Cells dialog opens.
-
Set the range B1-D2 for the To cells:
- Press OK.
- Bound cells have a blue border to highlight the binding.
- If you now enter something in cell C1, the same will immediately appear in cell B3.
The spreadsheet may now look like this
Change binding
- Right-click a bound cell (there is no need to highlight the whole bound range) and select Bind... from the context menu.
- The Bind Spreadsheet Cells dialog opens.
- Change one or more options. Note that the Bind cells, the bound cell range, cannot be changed.
- Press OK.
Remove binding
- Right-click a bound cell (there is no need to highlight the whole bound range) and select Bind... from the context menu.
- The Bind Spreadsheet Cells dialog opens.
- Press Unbind.
Notes
- The Hide dependency of binding option can be used to prevent problems with cyclic dependencies between spreadsheets. Selecting it is necessary when, for example, cells in Spreadsheet A are bound to Spreadsheet B, while cells in Spreadsheet B, in turn, are bound to some other cells in Spreadsheet A. This option should be used with caution:
- Hiding dependencies can be dangerous because broken dependencies can damage your FreeCAD file. For example, when you delete a spreadsheet you will not be warned about hidden dependencies.
- When you open a document with a spreadsheet containing a hidden dependency, you will get the spreadsheet marked to be recomputed. This is because a cyclic dependency cannot be recomputed automatically. To recompute the Std Refresh tool must be used.
- The cell binding has a range check and warns you about mismatched ranges. For example binding 1x3 cells to 3x2 cells cannot work because it is unknown which 3 cells of the original 6 cells should be used.
- You cannot change the cell range of an existing binding. You must first unbind the cells and then create a new binding.
- The frame color indicating the binding cannot be changed yet.
Configuration tables
You can use Spreadsheets to create configuration tables with sets of predefined parameters for your model, and then dynamically change which configuration to use. See this Forum post if you want to know more about the inner workings of this feature.
Expand this section for a brief tutorial on creating a configuration table.
- In a new document, first create a Std Part, then create a Part Box, a Part Cylinder and a Spreadsheet.
- The Box and the Cylinder are automatically placed in the Std Part container. Manually put the Spreadsheet in the container as well.
-
In the Spreadsheet enter the content as shown below. Set the alias for B2 as
width
, C2 aslength
and D2 asradius
:
-
Bind the expressions
Spreadsheet.width
andSpreadsheet.length
to the Box's properties DataWidth and DataLength, respectively:
-
Bind the expression
Spreadsheet.radius
to the Cylinder's property DataRadius. Also change the DataHeight of the Cylinder to5 mm
so that it is lower than the Box. - Right-click the cell A2 in the Spreadsheet and select Configuration table... from the context menu.
- The Setup Configuration Table dialog opens.
-
Enter the following:
- Press OK.
-
A new property called DataConfiguration is be added to the Std Part container to choose the configuration as shown below:
You can use either a Std Link or a PartDesign SubShapeBinder to instantiate a Variant Instance of a configurable object with the following steps:
- Create a Std Link to the Std Part container and set its DataLink Copy On Change property to
Enabled
. - Move the Link to a new place by changing its DataPlacement so that it is easier to distinguish from the original object.
- Select a different DataConfiguration for the Link to create a variant instance.
Similar steps apply to a PartDesign SubShapeBinder, except that its property for activating a variant instance is called DataBind Copy On Change.
Scripting basics
import Spreadsheet
sheet = App.ActiveDocument.addObject("Spreadsheet::Sheet","MySpreadsheet")
sheet.Label = "Dimensions"
sheet.set('A1','10mm')
sheet.recompute()
sheet.get('A1')
sheet.setAlias('B1','Diameter')
sheet.set('Diameter','20mm')
sheet.recompute()
sheet.get('Diameter')
- Creation: Create sheet, Import, Export, Merge cells, Split cell, Set alias
- Aligment: Align left, Align center, Align right, Align top, Align vertical center, Align bottom
- Style: Style bold, Style italic, Style underline
- Additional: Preferences
![](/images/thumb/9/94/User_hub.png/24px-User_hub.png)
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Assembly, BIM, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Surface, TechDraw, Test Framework
- Hubs: User hub, Power users hub, Developer hub