Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Spread.Sheets supports AutoFit in columns and rows. AutoFit automatically sizes the column to fit the contents by adjusting the column width or automatically sizes the row to fit the contents by adjusting the row height. You can also include the header text when using AutoFit with the options.autoFitType property.
Double-click the right edge of the column header to resize the column to fit the longest string of text in the column.
Double-click the bottom edge of the row header to resize the row.
You can also select multiple columns or rows or the entire sheet and double-click on one selected column or row to apply AutoFit to all the selected columns or rows.
AutoFit works with hidden columns and rows, filtered columns and rows, grouped columns and rows, and selected columns and rows that are not shown in the viewport. AutoFit is not applied if the resizable method is false for the column or row.
You can also resize the width or height with the autoFitColumn method, autoFitRow method, and the Commands class.

Image Removed

You can enter multiple lines with Alt+Enter if the wordWrap method is true for the cell.

Using Code
支持自动调整行高和列宽(AutoFit)。AutoFit 操作支持按照单元格内容的大小自适应工作表的行高和列宽。

options.autoFitType 可以让工作表进行 AutoFit 操作时是否包含行表头和列表头。

双击列标题的右侧边缘来自动调整该列的列宽。

双击行标题的底部边缘来自动调整该行的行宽。

你也可以选择多列和多行并双击选中行或者列的其中一个表头的边缘,多列和多行将会一起进行自动调整行高或列宽的操作。

AutoFit 将会对隐藏的列和行,被筛选掉的列和行,以及在视口中的列和行进行自适应操作。

当行或者列的 resizable 为 false 时,AutoFit 会失效。

你也可以使用 autoFitColumn 方法, autoFitRow 方法和 Commands 类来对行和列进行自适应大小操作。


Image Added

wordWrap 为 true 时,你可以使用 Alt+Enter 来输入多行文字。


示例代码

以下代码将给列重新设置了宽度。
This example fits the width of the column to the text.


JavaScript

Copy Code

activeSheet.setValue(0, 1, "testing");activeSheet.autoFitColumn(1);

 


Using Code
This example sets the height of the row to display the text.示例代码
以下代码给行重新设置了高度。


JavaScript

Copy Code

activeSheet.setValue(0, 1, "testing\r\nmultiple\r\nlines");activeSheet.getCell(0,1).wordWrap(true);activeSheet.autoFitRow(0);

 


See Also另见
Workbook Method