在谷歌电子表格上通过谷歌脚本垂直对齐文本 [英] Vertically Align Text on google spreadsheet via google script

查看:187
本文介绍了在谷歌电子表格上通过谷歌脚本垂直对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何垂直对齐中间的文字。根据文档,我发现我的下面的例子应该可以工作:

  var form = FormApp.getActiveForm(); 
var ss = SpreadsheetApp.openById(form.getDestinationId());
var sheet = ss.getSheets()[0];
var fullRange = sheet.getRange(A1:Z1001);

fullRange.setHorizo​​ntalAlignment(DocumentApp.Horizo​​ntalAlignment.CENTER);
fullRange.setVerticalAlignment(DocumentApp.VerticalAlignment.CENTER);

我发现有趣的事情是水平对齐起作用,但垂直对齐不起作用。我可能使用过时的方法吗?有没有更好的方法来完成这项工作? 作为 setVerticalAlignment()的参数:

  fullRange.setHorizo​​ntalAlignment(center)。setVerticalAlignment(middle); 

您使用适用于Google Docs表格和单元格的DocumentApp ,并使用Spreadsheets。


I am trying to figure out how to align text in the middle vertically. According to the documentation I have found my following example should work:

var form = FormApp.getActiveForm();
var ss = SpreadsheetApp.openById(form.getDestinationId()); 
var sheet = ss.getSheets()[0];
var fullRange = sheet.getRange("A1:Z1001");

fullRange.setHorizontalAlignment(DocumentApp.HorizontalAlignment.CENTER);
fullRange.setVerticalAlignment(DocumentApp.VerticalAlignment.CENTER);

The interesting thing I find is that the Horizontal Alignment works, but the vertical one does not. Am I possibly using out dated methods? Is there a better way to accomplish this?

解决方案

Just use middle as the parameter for setVerticalAlignment() :

fullRange.setHorizontalAlignment("center").setVerticalAlignment("middle");

You're using the Enum for the DocumentApp intended for Google Docs tables and cells and you're using Spreadsheets.

这篇关于在谷歌电子表格上通过谷歌脚本垂直对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆