Spreadsheet Workbench/zh-cn



电子表格工作台允许您创建和编辑电子表格、执行计算以及从模型中检索数据, 并将其数据导出到其他电子表格应用程序 (如 LibreOffice 或 Microsoft Excel).





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.

支持的功能
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.

单元格的属性
可以使用右键单击单元格来编辑电子表格单元格的属性. 以下对话框弹出:



它有几个选项卡. 可以更改以下属性:


 * 文本颜色和背景颜色
 * 文本水平和垂直对齐 * 文本样式: 粗体、斜体、下划线
 * 此单元格的显示单位. 请阅读下面的章节.
 * 为此单元格定义别名. 此别名可用于单元格公式, 也可以在 FreeCAD 表达式中中使用

对 CAD 数据的引用
可以在电子表格中使用结构中的数据. 下表显示了一些示例, 假设模型有一个名为 "立方体" 的功能 (请注意, 这是功能的内部名称, 而不是用户指定的标签):

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 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 "="; and the displayed text will be the value from the  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":

在表达式中的电子表格数据
在 FreeCAD 的其他部分使用电子表格数据需要一个完全定义的名称. 因为有可能文档中有多个电子表格, 则需要电子表格名称以及单元格名称或别名. 以下图片显示了在零件设计工作台的表达式中使用从电子表格 "MySheet " 中的别名 "number".



键入 "M " 显示可用名称的列表. 箭头按钮允许选择 "MySheet ".



键入 "n" 现在显示 MySheet 中可用别名的列表, 以 "n" 开头. 可以使用向下箭头按钮选择 "number". 一旦给定了具有可用内容的有效名称, 结果字段将显示计算出的长度.



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.

单位
电子表格使用单位. 如果一个数字有一个单位, 这个单位将用于所有的计算. 两个单位 mm 的长度相乘将会赋一个以 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 this thread in the FreeCAD forums.)

您可以在对话框中将长度单位从 mm 切换到英寸, 然后在单元格上右键单击. 单元格现在将显示长度 (以英寸为单位). 用于计算的值不会更改. 当输入的显示单位更改时, 使用该值的公式的结果不会更改. 结果仍按 mm 的长度计算.

单元格属性对话框不能在带单位的数字中更改一个没有单位的数字. 没有单位的数字可以放在一个单位字符串, 这也将显示, 但单元格仍然只包含一个数字没有单位.

有时是刻意, 以摆脱一个单位. 这只能通过乘以1与一个倒数单位来完成.

导入与导出
可以将工作表导入并导出到 csv 格式, 这些形式也可以由大多数其他电子表格应用程序 (如 Microsoft Excel 或 LibreOffice 计算器) 读取和写入. 将文件导入 FreeCAD 时, 分隔符 (用于分隔列的字符) 必须是 TAB 字符 (可以在从其他应用程序导出时设置).

Excel 中的电子表格-格式 "xlsx " 可以导入到 FreeCAD 文档中. Excel 电子表格也可以通过 FreeCAD 打开. 在这种情况下将创建一个带有电子表格的新文档. 支持以下功能:


 * FreeCAD 电子表格中还提供的所有功能. 其他函数在导入后的相应单元格中会出现错误.
 * 单元格的别名
 * 在 Excel 工作表中有多个表. 在这种情况下, 将创建更多的 FreeCAD 电子表格.

其他功能不会被导入到 FreeCAD 电子表格中. Excel 导入是 FreeCAD 的功能.

当前限制
这是不可能提供一个几何的数据, 例如一个长度, 在电子表格和检索在同一个电子表格中生成形状的体积. 这将创建一个循环引用. 这是一个设计决定. 但是, 可以使用两个不同的电子表格: 一个是几何图形的数据源, 另一个用于报告几何数据.

不可能选择和复制多个单元格. 只有输入字段中的单元格内容才能被复制并粘贴到另一个单元格的输入字段中.

对于 FreeCAD 早期版本, 请参见 Spreadsheet legacy