Difference between revisions of "Spreadsheet Workbench/es"

From FreeCAD Documentation
Jump to: navigation, search
(Updating to match new version of source page)
(Updating to match new version of source page)
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<languages/>
 
<languages/>
 +
{{Docnav|[[Sketcher Workbench|Sketcher Workbench]]|[[Start Workbench|Start Workbench]]|IconL=Workbench_Sketcher.svg|IconR=Workbench_Start.svg}}
 +
 
[[Image:Workbench_Spreadsheet.svg|64px]]
 
[[Image:Workbench_Spreadsheet.svg|64px]]
  
 
== Introduction ==
 
== Introduction ==
The [[Spreadsheet Workbench]] allows you to create and edit spreadsheets, 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.
+
The [[Spreadsheet Workbench|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.
  
The Spreadsheet Workbench is available since FreeCAD 0.15.
+
The Spreadsheet Workbench has been available since FreeCAD 0.15.
  
 
{{TOCright}}
 
{{TOCright}}
 
[[File:Spreadsheet_screenshot.jpg|800px]]
 
[[File:Spreadsheet_screenshot.jpg|800px]]
 +
 +
== Cell Expressions ==
 +
 +
A spreadsheet cell may contain arbitrary text or an expression.
 +
Technically, expressions must start with an equals '=' sign.
 +
However, the spreadsheet attempts to be intelligent;
 +
if you enter what looks like an expression without the leading '=',
 +
one will be added automatically.
 +
 +
Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model
 +
(But see [[#Current_Limitations|Current Limitations]] below).
 +
Cells are referenced by their column (CAPITAL letter) and row (number).
 +
A cell may also be referenced by its [[#alias_name|alias-name]] (below).
 +
Example: B4 + A6
 +
 +
References to objects in the model are explained under [[#References_To_CAD-Data|References to CAD-Data]] below.
 +
Using spreadsheet cell values to define model properties are explained under [[#Spreadsheet_Data_in_Expressions|Spreadsheet Data in Expressions]] below.
 +
For more specifics on how expressions are formed, see [[Expressions|Expressions]].
  
 
== Supported Functions ==
 
== Supported Functions ==
  
The spreadsheet provides the following functions taking one or two arguments: abs, acos, asin, atan, atan2, cos, cosh, exp, log, log10, mod, pow, sin, sinh, sqrt, tan, tanh
+
Standard trigonometric and other common mathematical functions as well as statistical aggregation functions are supported (see [[Expressions|Expressions]]).
  
Trigonometric functions use degrees as its default unit; supplying '''rad''' allows to use radians.
+
== Interaction between Spreadsheets and the CAD Model ==
  
The additional functions: ''ceil'', ''floor'', ''trunc'', and ''round'' are available in FreeCAD {{Version|0.16}}
+
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.
  
The following aggregate functions are supported: ''average'', ''count'', ''max'', ''min'', ''stddev'', ''sum''.
+
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.  
  
Aggregate functions can take one or more arguments, separated by comma or semicolon. Arguments may include ranges (two cells separated by a colon), e.g ''=average(B1:B8)''
+
More than one spreadsheet may be used in a document;
 +
spreadsheets may be given a user-assigned name (rename) like any other object.
  
The constants ''pi'' and ''e'' are predefined.
+
FreeCAD checks for cyclic dependencies.  See [[Spreadsheet_Workbench#Current_Limitations|Current Limitations]].
  
The conditional statement works like this: ''= condition ? resultTrue : resultFalse''
+
=== Cell Properties ===
  
The condition is defined as an expression that evaluates to either 0 (for false) or non-zero for true. The following comparison operators are defined: ==, !=, >, <, >=, and <=.
+
The properties of a spreadsheet cell can be edited with a right-click on a cell. The following
 +
dialog pops up:
  
The conditional statement has actually a bug regarding nested conditional statements. Only the true-result may have another conditional statement. Parentheses are removed after confirming the expression. Trying to put a nested conditional statement in the false-result results in wrong set parentheses with a different result after a saving and reopening of the document.  
+
[[File:SpreadsheetCellPropDialog.png]]
 +
 
 +
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: <span id="units_tab"></span>Display units for this cell. Please read the [[Spreadsheet_Workbench#Units|Units]] section below.
 +
* Alias: <span id="alias_name"></span>Define an alias-name for this cell. This alias-name can be used in cell formulas and also in general FreeCAD Expressions.
 +
While one 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.
 +
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 "Spreadsheet.MyObject_Length"
 +
instead of "Spreadsheet.B1". {{Version|0.16}}
 +
 
 +
=== References To CAD-Data ===
  
Formulas are written as follows: ''=A2+A3''
+
As indicated above, one can reference data from the CAD model in spreadsheet expressions.
  
Noteː Cell-references have to be written with capital letters.
+
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.
  
== Reference To CAD-Data ==
+
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.
  
It is possible to use data from the construction in the spreadsheet.  
+
One way to side-step these issues is to prefix text labels corresponding to alias-names with a fixed string,
The following table shows some examples assuming the model has a feature named "Cube" (note that this is the internal name of the feature, not the user assigned Label):
+
thereby making them different.  Note that "_" will not work, as it is converted to "=".  However, a blank, while invisible, will work.
 +
 
 +
The following table shows some examples assuming the model has a feature named "MyCube":
 
{|{{Prettytable}}
 
{|{{Prettytable}}
 
  !CAD-Data
 
  !CAD-Data
  !Call in Spreadsheet
+
  !Cell in Spreadsheet
 
  !Result
 
  !Result
 
  |-
 
  |-
 
  |Parametric Length of a Part-Workbench Cube
 
  |Parametric Length of a Part-Workbench Cube
  |=Cube.Length
+
  |=MyCube.Length
 
  |Length with units mm
 
  |Length with units mm
 
  |-
 
  |-
 
  |Volume of the Cube
 
  |Volume of the Cube
  |=Cube.Shape.Volume
+
  |=MyCube.Shape.Volume
 
  |Volume  in mm&sup3; without units
 
  |Volume  in mm&sup3; without units
 
  |-
 
  |-
 
  |Type of the Cube-shape
 
  |Type of the Cube-shape
  |=Cube.Shape.ShapeType
+
  |=MyCube.Shape.ShapeType
 
  |String: Solid
 
  |String: Solid
 
  |-
 
  |-
 
  |Label of the Cube
 
  |Label of the Cube
  |=Cube.Label
+
  |=MyCube.Label
  |String: Cube
+
  |String: MyCube
 
  |-
 
  |-
 
  |x-coordinate of center of mass of the Cube
 
  |x-coordinate of center of mass of the Cube
  |=Cube.Shape.CenterOfMass.x
+
  |=MyCube.Shape.CenterOfMass.x
 
  |x-coordinate in mm without units
 
  |x-coordinate in mm without units
 
  |}
 
  |}
  
== Cell Properties ==
+
=== Spreadsheet Data in Expressions ===
 
 
The properties of a spreadsheet cell can be edited with a right-click on a cell. The following
 
dialog pops up:
 
 
 
[[File:SpreadsheetCellPropDialog.png]]
 
 
 
It has several tabs. The following properties can be changed:
 
 
 
* Text color and background color
 
* Text horizontal and vertical alignment
 
* Text style: bold, italic, underline
 
* Display unit for this cell. Please read the section below.
 
* Define an alias-name for this cell. This alias-name can be used in cell formulas and also in FreeCADExpressions {{Version|0.16}}
 
 
 
The expressions are explained here: [[Expressions|Expressions]]
 
 
 
== Spreadsheet Data in Expressions ==
 
  
 
The usage of spreadsheet data in other parts of FreeCAD requires a fully defined name. Because it is possible to have
 
The usage of spreadsheet data in other parts of FreeCAD requires a fully defined name. Because it is possible to have
 
more than one spreadsheet in a document, the spreadsheet name together with the cell name or alias is required.  
 
more than one spreadsheet in a document, the spreadsheet name together with the cell name or alias is required.  
The following pictures showing the usage of an alias "number" from a spreadsheet "MySheet" in an expression
+
The following pictures show the usage of an alias "number" from a spreadsheet "MySheet" in an expression
 
in the PartDesign Workbench.
 
in the PartDesign Workbench.
 +
 
[[File:Expression usage1.png]]
 
[[File:Expression usage1.png]]
  
Typing an "M" shows a list of available names. The arrow-buttons allow to select "MySheet".
+
Typing an "M" shows a list of available names (above).  
 +
The arrow-keys allow one to move down to "MySheet" and select it;
 +
{{KEY|Enter}} will cause it to be completed in the expression.
 +
You can also continue typing or click the entry with the mouse.
  
 
[[File:Expression usage2.png]]
 
[[File:Expression usage2.png]]
  
Typing an "n" shows now the list of available alias names in MySheet starting with "n".
+
Typing an "n" now shows the list of available alias names in MySheet starting with "n" (above).
The "number" can be selected with the down-arrow-button.
+
"number" can now be selected as described above.
Once a valid name with a usable content is given, the result field will present the calculated length.
+
Once a valid name with usable content is entered,  
 +
the result field will show the calculated value; in this case, the length (below).
  
 
[[File:Expression usage3.png]]
 
[[File:Expression usage3.png]]
 +
 +
Further typing, such as adding a "+" sign, will result in an expression which is no longer valid
 +
which will be indicated.
 +
Continuing to complete the expression can again result in a valid expression.
  
 
== Units ==
 
== Units ==
  
The Spreadsheet uses units. If a number has a unit, this unit will be used in all calculations.
+
The Spreadsheet has a notion of dimension (units) associated with cell values.
The multiplication of two length with the unit mm gives an area with the unit mm&sup2;.
+
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&sup2;.
 +
 
 +
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 [https://forum.freecadweb.org/viewtopic.php?f=3&t=34713&p=292455#p292438 this thread] in the FreeCAD forums.)
  
You can switch the length-unit from mm to inch in the dialog, you get with a right-click on a cell.
+
You can change the units displayed for a cell value using the properties dialog [[#units_tab|units tab]] (above).
The cell will now show the length in inches. The value used for calculations does not change.
+
This does not change the value contained in the cell; it only converts the existing value for display.
The results of a formula using this value do not change, when the shown unit of an input was changed. The result
+
The value used for calculations does not change,
is still calculated from the length in mm.  
+
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 number without a unit cannot be changed in a number with unit by the cell properties dialog.  
+
A dimensionless number cannot be changed to a number with a unit by the cell properties dialog.  
One can put in a unit string, that will also be shown, but the cell still contains only a number without unit.
+
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.
  
Sometime it is desirably to get rid of a unit. This can only to be done by multiplying with 1 with a reciprocal 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 ==
 
== Importing and exporting ==
  
Sheets can be imported and exported to the [https://en.wikipedia.org/wiki/Comma-separated_values csv] format which can also be read and written by most other spreadsheet applications such as Microsoft Excel or LibreOffice Calc. When importing files into FreeCAD, the delimiter (the character that is used to separate columns) must be the TAB character (this can be set when exporting from other applications). The import of a CSV-file is available over the menu Spreadsheet/ Import Spreadsheet or by clicking on the icon [[Image:SpreadsheetImport.svg|24px]]. This import function does not open Excel files or any other spreadsheet format.
+
Sheets can be imported and exported to the [https://en.wikipedia.org/wiki/Comma-separated_values csv] format which can also be read and written by most other spreadsheet applications such as Microsoft Excel or LibreOffice Calc. When importing files into FreeCAD, the delimiter (the character that is used to separate columns) must be the TAB character (this can be set when exporting from other applications). The import of a CSV-file is available from the menu {{MenuCommand|Spreadsheet Import Spreadsheet}} or by clicking on the icon [[Image:SpreadsheetImport.svg|24px]]. This import function does not open Excel files or any other spreadsheet format.
  
Spreadsheets in Excel-format "xlsx" can be imported via the menu File/Import... into a FreeCAD document. Excel-spreadsheets can also be opened by FreeCAD by clicking in the menu File/Open... or by clicking on the icon [[Image:Document-open.svg|24px]]. In this case
+
Spreadsheets in Excel-format "xlsx" can be imported via the menu {{MenuCommand|File Import...}}. Excel-spreadsheets can also be opened by clicking in the menu {{MenuCommand|File Open...}} or by clicking on the icon [[Image:Document-open.svg|24px]]. In these cases
a new document with a spreadsheet inside is created. Supported are the following features:
+
a new document with a spreadsheet inside is created. The following features are supported:
  
* all functions that are also available in the FreeCAD spreadsheet. Other functions do give an error in the corresponding cell after the import.
+
* all functions that are also available in the FreeCAD spreadsheet. Other functions give an error in the corresponding cell after the import.
 
* Alias names for cells
 
* Alias names for cells
* More than one table in the Excel-sheet. In this case more FreeCAD spreadsheets are created.
+
* 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. The Excel-import is {{Version|0.17}}of FreeCAD.
+
Other functionality is not imported into the FreeCAD spreadsheet. The Excel-import is {{Version|0.17}} of FreeCAD.
  
 
== Current Limitations ==
 
== Current Limitations ==
  
It is not possible providing data for a geometry, for example a length, in a spreadsheet and retrieving in the same spreadsheet the volume of the
+
FreeCAD checks for cyclic dependencies.
resulting shape. This will create a circular reference. This is a design decision. However, it is possible to use two different spreadsheets: one as data-source  
+
By design, that check stops at the level of the spreadsheet object.
for geometry and another for reporting geometry-data.
+
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.
  
It is not possible to select and copy multiple cells. Only the content of a cell from the input field can be copied and paste into the input field of another cell.
+
When cells are copied, only the content (expression/value) is copied.
 
+
The [[Spreadsheet_Workbench#Cell_Properties|Cell Properties]] described above are not copied.
For FreeCAD earlier versions see [[Spreadsheet_legacy|Spreadsheet legacy]]
 
  
 +
For earlier versions see [[Spreadsheet_legacy|Spreadsheet legacy]].
  
 
== Scripting Basics==  
 
== Scripting Basics==  
Line 145: Line 208:
 
}}
 
}}
  
{{Docnav|Sketcher Workbench|Start Workbench}}
+
{{Docnav|[[Sketcher Workbench|Sketcher Workbench]]|[[Start Workbench|Start Workbench]]|IconL=Workbench_Sketcher.svg|IconR=Workbench_Start.svg}}
 +
 
 
{{Userdocnavi}}
 
{{Userdocnavi}}
 
[[Category:Spreadsheet]]
 
[[Category:Spreadsheet]]
 
[[Category:Workbenches]]
 
[[Category:Workbenches]]

Revision as of 10:21, 10 April 2019

Other languages:
български • ‎čeština • ‎Deutsch • ‎English • ‎español • ‎français • ‎hrvatski • ‎Bahasa Indonesia • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎română • ‎русский • ‎svenska • ‎Türkçe • ‎中文 • ‎中文(中国大陆)‎ • ‎中文(台灣)‎

Workbench Spreadsheet.svg

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.

The Spreadsheet Workbench has been available since FreeCAD 0.15.

Spreadsheet screenshot.jpg

Cell Expressions

A spreadsheet cell may contain arbitrary text or an expression. Technically, expressions must start with an equals '=' sign. However, the spreadsheet attempts to be intelligent; if you enter what looks like an expression without the leading '=', one will be added automatically.

Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model (But see Current Limitations below). Cells are referenced by their column (CAPITAL letter) and row (number). A cell may also be referenced by its alias-name (below). Example: B4 + A6

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 specifics on how expressions are formed, see Expressions.

Supported Functions

Standard trigonometric and other common mathematical functions as well as statistical aggregation functions are supported (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; spreadsheets may be given a user-assigned name (rename) like any other object.

FreeCAD checks for cyclic dependencies. See Current Limitations.

Cell Properties

The properties of a spreadsheet cell can be edited with a right-click on a cell. The following dialog pops up:

SpreadsheetCellPropDialog.png

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-name for this cell. This alias-name can be used in cell formulas and also in general FreeCAD Expressions.

While one 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. 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 "Spreadsheet.MyObject_Length" instead of "Spreadsheet.B1". introduced in version 0.16

References To CAD-Data

As indicated above, one can reference data from the CAD model in spreadsheet expressions.

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 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.

Note: The above behavior (auto insert of '=') has some unpleasant ramifications:

  • If you want to keep a column of names corresponding to the 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.

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.

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 center of mass of the Cube =MyCube.Shape.CenterOfMass.x x-coordinate in mm without units

Spreadsheet Data in Expressions

The usage of spreadsheet data in other parts of FreeCAD requires a fully defined name. Because it is possible to have more than one spreadsheet in a document, the spreadsheet name together with the cell name or alias is required. The following pictures show the usage of an alias "number" from a spreadsheet "MySheet" in an expression in the PartDesign Workbench.

Expression usage1.png

Typing an "M" shows a list of available names (above). The arrow-keys allow one to move down to "MySheet" and select it; Enter will cause it to be completed in the expression. You can also continue typing or click the entry with the mouse.

Expression usage2.png

Typing an "n" now shows the list of available alias names in MySheet starting with "n" (above). "number" can now be selected as described above. Once a valid name with usable content is entered, the result field will show the calculated value; in this case, the length (below).

Expression usage3.png

Further typing, such as adding a "+" sign, will result in an expression which is no longer valid which will be indicated. Continuing to complete the expression can again result in a valid expression.

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 properties dialog units tab (above). 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

Sheets 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. When importing files into FreeCAD, the delimiter (the character that is used to separate columns) must be the TAB character (this can be set when exporting from other applications). The import of a CSV-file is available from the menu Spreadsheet → Import Spreadsheet or by clicking on the icon SpreadsheetImport.svg. This import function does not open Excel files or any other spreadsheet format.

Spreadsheets in Excel-format "xlsx" can be imported via the menu File → Import.... Excel-spreadsheets can also be opened by clicking in the menu File → Open... or by clicking on the icon Document-open.svg. In these cases a new document with a spreadsheet inside is created. 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 the 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. The Excel-import is introduced in version 0.17 of FreeCAD.

Current Limitations

FreeCAD checks for cyclic dependencies. 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.

When cells are copied, only the content (expression/value) is copied. The Cell Properties described above are not copied.

For earlier versions see Spreadsheet legacy.

Scripting Basics

import Spreadsheet
sheet = App.ActiveDocument.addObject("Spreadsheet::Sheet")
sheet.Label = "Dimensions"