如何使用脚本确定列是否隐藏在Google Spreadsheet中? [英] How do I determine if a column is hidden in Google Spreadsheet using scripts?
问题描述
我正在为Google Spreadsheet编写一个函数,用于查找组的第一列和最后一列。然后它隐藏了该组,或者显示它是否已隐藏。
但是,我无法找到确定列是否隐藏的方法。我无法在Google课堂页面上找到任何内容 https:// developers.google.com/apps-script/reference/spreadsheet/sheet ,并且我还没有发现与Excel的.hidden等效的值。
getColumnWidth(column )
这是我的代码:
function hideShowColumns(startCol,endCol){
// endCol是应该隐藏的最后一个数据集之后的一列
var sheet = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName(Transposed Data );
//从列标题中导入数据
var colHeaderData = sheet.getRange(1,1,2,sheet.getMaxColumns())。getValues();
var startColNum = 0;
var endColNum = 0;
//这部分搜索标题行中的列名,并返回它们的列号
for(var i = 0; i< 2; ++ i){$ b $对于(var j = 0; j if(colHeaderData [i] [j] == startCol)
startColNum = j;
if(colHeaderData [i] [j] == endCol)
endColNum = j;
//这是错误的命令getColumnWidth不会改变如果列隐藏
if(sheet.getColumnWidth(startColNum + 1)!= 0){
sheet.hideColumns(startColNum + 2,endColNum - startColNum - 1);
Logger.log(sheet.getColumnWidth(startColNum + 2));
return;
}
//这是错误的命令getColumnWidth不会更改如果列隐藏
if(sheet.getColumnWidth(startColNum + 1)== 0){$ b (var j = startColNum + 1; j< endColNum - 1; ++ j){
sheet.unhideColumn(j);
Logger.log(sheet.getColumnWidth(startColNum + 2));
}
return;
$ / code>
感谢您的帮助!
遗憾的是,没有Google Apps脚本方法会返回列或行是否隐藏。作为一种方式,您可能希望将为其打开的问题列为明星。接收关于该问题的更新,以及b。 签署请愿书可以这么说。
I'm trying to write a function for Google Spreadsheet that locates the first and last column of a group. It then hides the group, or shows it if it's already hidden.
However, I haven't been able to find a way to determine whether a column is hidden or not. I haven't been able to find anything anything on Google's Class Sheet page https://developers.google.com/apps-script/reference/spreadsheet/sheet, and I haven't found an equivalent to Excel's .hidden
getColumnWidth(column) returns the unhidden column width even when it's hidden.
Here's my code:
function hideShowColumns(startCol, endCol) {
//endCol is one column past the last data set that should be hidden
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Transposed Data");
//import the data from the Column Headers
var colHeaderData = sheet.getRange(1, 1, 2, sheet.getMaxColumns()).getValues();
var startColNum = 0;
var endColNum = 0;
// This section searches for the column names in the header rows and returns their column number
for (var i =0; i < 2; ++i) {
for (var j = 0; j < colHeaderData[0].length; ++j) {
if (colHeaderData[i][j] == startCol)
startColNum = j;
if (colHeaderData[i][j] == endCol)
endColNum = j;
}
}
//This is the wrong command getColumnWidth doesn't change if column is hidden
if (sheet.getColumnWidth(startColNum + 1) != 0) {
sheet.hideColumns(startColNum + 2, endColNum - startColNum - 1);
Logger.log(sheet.getColumnWidth(startColNum + 2));
return;
}
//This is the wrong command getColumnWidth doesn't change if column is hidden
if (sheet.getColumnWidth(startColNum + 1) == 0) {
for (var j = startColNum + 1; j < endColNum - 1; ++j) {
sheet.unhideColumn(j);
Logger.log(sheet.getColumnWidth(startColNum + 2));
}
return;
}
}
Thanks for the help!
Unfortunately there is no Google Apps Script method that will return whether a column or row is hidden or not. You might like to star the issue opened for it, as a way of a. receiving updates about the issue, and b. "signing the petition", so to speak.
这篇关于如何使用脚本确定列是否隐藏在Google Spreadsheet中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!