Difference between revisions of "Spreadsheet Workbench/es"

From FreeCAD Documentation
Jump to navigation Jump to search
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 1: Line 1:
 
<languages/>
 
<languages/>
 
[[Image:Workbench_Spreadsheet.svg|64px]]
 
[[Image:Workbench_Spreadsheet.svg|64px]]
 +
{{VeryImportantMessage|2019-02-24 This page is actively being modified. Do not translate yet. This message will be removed when these modifications are complete.}}
  
 
== Introduction ==
 
== Introduction ==
Line 9: Line 10:
 
{{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, and references to other cells.
 +
Cells are referenced by their row (CAPITAL letter) and column (number).
 +
Example: B4 + A6
 +
 +
Numbers may use either a comma ',' or a decimal point '.' separating whole digits from decimals.
 +
 +
The constants ''pi'' and ''e'' are predefined, and must be written in lowercase.
  
 
== 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
+
=== Mathematical Functions ===
  
Trigonometric functions use degrees as its default unit; supplying '''rad''' allows to use radians.  
+
The mathematical functions listed below are available.
  
The additional functions: ''ceil'', ''floor'', ''trunc'', and ''round'' are available in FreeCAD {{Version|0.16}}
+
Multiple arguments to a function may be separated by either a semicolon (';') or
 +
a comma <em>followed by a space</em> (", ").
 +
In the latter case, the comma is converted to a semicolon after entry.
  
The following aggregate functions are supported: ''average'', ''count'', ''max'', ''min'', ''stddev'', ''sum''.
+
Trigonometric functions use degrees as their default unit;
 +
for radian measure, add '''rad''' following the <em>first</em> value in an expression.
 +
Example: cos(45) is the same as cos(pi rad / 4).
  
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)''
+
{{APIFunction  |abs|x|  Absolute value | value &gt;&#61; 0 }}
 +
{{APIFunction  |acos|x|  Arc cosine; -1 &lt;&#61; x &lt;&#61; 1 | acos(x)  }}
 +
{{APIFunction  |asin|x|  Arc sine; -1 &lt;&#61; x &lt;&#61; 1 | asin(x) }}
 +
{{APIFunction  |atan|x|  Arc tangent | atan(x) }}
 +
{{APIFunction  |atan2|y, x|  Arc tangent of y / x; | atan2(y,x) }}
 +
{{APIFunction  |ceil|x|  Ceiling | The smallest integer value greater than or equal to x {{Version|0.16}} }}
 +
{{APIFunction  |cos|angle|  Cosine; angle is in degrees (any value) | -1 &lt;&#61; cos(x) &lt;&#61; 1 }}
 +
{{APIFunction  |cosh|x| Hyperbolic cosine of x | cosh(x) }}
 +
{{APIFunction  |exp|y|  Natural exponent | e<sup> y</sup> }}
 +
{{APIFunction  |floor|x|  Floor | The largest integer value less than or equal to x {{Version|0.16}} }}
 +
{{APIFunction  |log|x|  Natural logarithm | log<sub>e</sub> x }}
 +
{{APIFunction  |log10|x|  Logarithm base 10 | log<sub>10</sub> x }}
 +
{{APIFunction  |mod|x, y| Remainder x/y | Remainder after dividing x by y }}
 +
{{APIFunction  |pow|x, y| Power function| x<sup> y</sup> }}
 +
{{APIFunction  |round|x| | x rounded to the nearest integer {{Version|0.16}} }}
 +
{{APIFunction  |sin|angle| Cosine; angle in degrees (any value) | -1 &lt;&#61; sin(x) &lt;&#61; 1 }}
 +
{{APIFunction  |sinh|x|  Hyperbolic sine of x | sinh(x) }}
 +
{{APIFunction  |sqrt|x|  Square root; x &gt;&#61; 0 | Square root of x }}
 +
{{APIFunction  |tan|angle|  Tangent; angle in degrees (any value) | tan(angle) }}
 +
{{APIFunction  |tanh|x|  Hyperbolic tangent of x | tanh(x) }}
 +
{{APIFunction  |trunc|x|  Truncate | x truncated to the nearest integer {{Version|0.16}} }}
  
The constants ''pi'' and ''e'' are predefined.
+
=== Statistical / Aggregating Functions ===
 +
The aggregating functions listed below are supported.
 +
Aggregating functions take one or more arguments, separated by a semicolon ';' or a comma <em>and</em> a space ", ".
 +
Arguments may include references to cells;
 +
cell references consist of the row letter (CAPITAL) followed by the column number.
 +
Arguments may include ranges of cells (two cell references separated by a colon).
 +
Example: ''average(B1:B8)''
  
The conditional statement works like this: ''= condition ? resultTrue : resultFalse''
+
{{APIFunction  |average|x y|  Average of values in cells x through y | sum(x, y) / count(x, y) }}
 +
{{APIFunction  |count|x y|  Number of cells from x through y | The number of cells from x through y, inclusive }}
 +
{{APIFunction  |max|x y|  Maximum value in cells x through y | Maximum value }}
 +
{{APIFunction  |min|x y|  Minimum value in cells x through y | Minimum value }}
 +
{{APIFunction  |stddev|x y|  Standard deviation of values in cells x through y | Standard deviation }}
 +
{{APIFunction  |sum|x y|  Sum of values in cells x through y | Sum }}
  
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 <=.
+
=== Conditional Expressions ===
  
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.
+
Conditional expressions are of the form ''condition ? resultTrue : resultFalse''
  
Formulas are written as follows: ''=A2+A3''
+
The condition is defined as an expression that evaluates to either 0 (false) or non-zero (true). The following comparison operators are defined: ==, !=, >, <, >=, and <=.
  
Noteː Cell-references have to be written with capital letters.
+
The conditional statement has a bug regarding nested conditional statements. Only the true-result may contain another conditional statement. This is because parentheses are removed after an expression is entered. Trying to put a nested conditional statement in the false-result may result in incorrect parentheses causing a different result after saving and reopening the document.
 +
Note: This may not longer be true; at least <em>some</em> false result conditionals work properly.
  
 
== Reference To CAD-Data ==
 
== Reference To CAD-Data ==

Revision as of 09:17, 25 February 2019

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

Workbench Spreadsheet.svg

2019-02-24 This page is actively being modified. Do not translate yet. This message will be removed when these modifications are complete.


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, and references to other cells. Cells are referenced by their row (CAPITAL letter) and column (number). Example: B4 + A6

Numbers may use either a comma ',' or a decimal point '.' separating whole digits from decimals.

The constants pi and e are predefined, and must be written in lowercase.

Supported Functions

Mathematical Functions

The mathematical functions listed below are available.

Multiple arguments to a function may be separated by either a semicolon (';') or a comma followed by a space (", "). In the latter case, the comma is converted to a semicolon after entry.

Trigonometric functions use degrees as their default unit; for radian measure, add rad following the first value in an expression. Example: cos(45) is the same as cos(pi rad / 4).

Method.png abs(x)

Description: Absolute value

Returns: value >= 0

Method.png acos(x)

Description: Arc cosine; -1 <= x <= 1

Returns: acos(x)

Method.png asin(x)

Description: Arc sine; -1 <= x <= 1

Returns: asin(x)

Method.png atan(x)

Description: Arc tangent

Returns: atan(x)

Method.png atan2(y, x)

Description: Arc tangent of y / x;

Returns: atan2(y,x)

Method.png ceil(x)

Description: Ceiling

Returns: The smallest integer value greater than or equal to x introduced in version 0.16

Method.png cos(angle)

Description: Cosine; angle is in degrees (any value)

Returns: -1 <= cos(x) <= 1

Method.png cosh(x)

Description: Hyperbolic cosine of x

Returns: cosh(x)

Method.png exp(y)

Description: Natural exponent

Returns: e y

Method.png floor(x)

Description: Floor

Returns: The largest integer value less than or equal to x introduced in version 0.16

Method.png log(x)

Description: Natural logarithm

Returns: loge x

Method.png log10(x)

Description: Logarithm base 10

Returns: log10 x

Method.png mod(x, y)

Description: Remainder x/y

Returns: Remainder after dividing x by y

Method.png pow(x, y)

Description: Power function

Returns: x y

Method.png round(x)

Description:

Returns: x rounded to the nearest integer introduced in version 0.16

Method.png sin(angle)

Description: Cosine; angle in degrees (any value)

Returns: -1 <= sin(x) <= 1

Method.png sinh(x)

Description: Hyperbolic sine of x

Returns: sinh(x)

Method.png sqrt(x)

Description: Square root; x >= 0

Returns: Square root of x

Method.png tan(angle)

Description: Tangent; angle in degrees (any value)

Returns: tan(angle)

Method.png tanh(x)

Description: Hyperbolic tangent of x

Returns: tanh(x)

Method.png trunc(x)

Description: Truncate

Returns: x truncated to the nearest integer introduced in version 0.16

Statistical / Aggregating Functions

The aggregating functions listed below are supported. Aggregating functions take one or more arguments, separated by a semicolon ';' or a comma and a space ", ". Arguments may include references to cells; cell references consist of the row letter (CAPITAL) followed by the column number. Arguments may include ranges of cells (two cell references separated by a colon). Example: average(B1:B8)

Method.png average(x y)

Description: Average of values in cells x through y

Returns: sum(x, y) / count(x, y)

Method.png count(x y)

Description: Number of cells from x through y

Returns: The number of cells from x through y, inclusive

Method.png max(x y)

Description: Maximum value in cells x through y

Returns: Maximum value

Method.png min(x y)

Description: Minimum value in cells x through y

Returns: Minimum value

Method.png stddev(x y)

Description: Standard deviation of values in cells x through y

Returns: Standard deviation

Method.png sum(x y)

Description: Sum of values in cells x through y

Returns: Sum

Conditional Expressions

Conditional expressions are of the form condition ? resultTrue : resultFalse

The condition is defined as an expression that evaluates to either 0 (false) or non-zero (true). The following comparison operators are defined: ==, !=, >, <, >=, and <=.

The conditional statement has a bug regarding nested conditional statements. Only the true-result may contain another conditional statement. This is because parentheses are removed after an expression is entered. Trying to put a nested conditional statement in the false-result may result in incorrect parentheses causing a different result after saving and reopening the document. Note: This may not longer be true; at least some false result conditionals work properly.

Reference To CAD-Data

It is possible to use data from the construction in the spreadsheet. 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):

CAD-Data Call in Spreadsheet Result
Parametric Length of a Part-Workbench Cube =Cube.Length Length with units mm
Volume of the Cube =Cube.Shape.Volume Volume in mm³ without units
Type of the Cube-shape =Cube.Shape.ShapeType String: Solid
Label of the Cube =Cube.Label String: Cube
x-coordinate of center of mass of the Cube =Cube.Shape.CenterOfMass.x x-coordinate in mm without units

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

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 introduced in version 0.16

The expressions are explained here: 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 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 in the PartDesign Workbench. Expression usage1.png

Typing an "M" shows a list of available names. The arrow-buttons allow to select "MySheet".

Expression usage2.png

Typing an "n" shows now the list of available alias names in MySheet starting with "n". The "number" can be selected with the down-arrow-button. Once a valid name with a usable content is given, the result field will present the calculated length.

Expression usage3.png

Units

The Spreadsheet uses units. If a number has a unit, this unit will be used in all calculations. The multiplication of two length with the unit mm gives an area with the unit mm².

You can switch the length-unit from mm to inch in the dialog, you get with a right-click on a cell. The cell will now show the length in inches. The value used for calculations does not change. The results of a formula using this value do not change, when the shown unit of an input was changed. The result is still calculated from the length in mm.

A number without a unit cannot be changed in a number with 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.

Sometime it is desirably to get rid of a unit. This can only to be done by multiplying with 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 over 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... 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 Document-open.svg. In this case a new document with a spreadsheet inside is created. Supported are the following features:

  • all functions that are also available in the FreeCAD spreadsheet. Other functions do give an error in the corresponding cell after the import.
  • Alias names for cells
  • More than one table in the Excel-sheet. In this case more FreeCAD spreadsheets are created.

Other functionality is not imported into the FreeCAD spreadsheet. The Excel-import is introduced in version 0.17of FreeCAD.

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 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 for geometry and another for reporting 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.

For FreeCAD earlier versions see Spreadsheet legacy


Scripting Basics

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