[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Automatically Expand the Number of Columns Encompassed in a JavaScript Function

ottopageken

4/2/2016 12:41:00 AM

I have a function similar to the following:
function Tabulate() {
var spreadsheetAll = SpreadsheetApp.getActiveSpreadsheet();
var currentSheet = ss.getSheetByName("XYZ");
var $CountofColumnsinSheet= 27
var $combinedAll= currentSheet.getRange(27,2,currentSheet.getLastRow(),1).getValues();
var count = [];
for (var i=0; i<$combinedAll.length; i++) {
if ($Combined[i]!="") {
count.push(1);
}

I plan on adding more columsn so that var $CountofColumnsinSheet will grow to 28 or 29 or 30. I don't want to have to go into my Script Editor to constantly change the var $CountofColumnsinSheet to some incrementally larger number and then make appropriate changes in var $Combined where I would need to change the initial 27 to 28 or 29. Is there a function in JavaScript that automatically expands to fill in any additional columns to the right that are created?
2 Answers

ram

4/2/2016 3:35:00 AM

0

ottopageken@gmail.com writes:
>Is there a function in JavaScript that automatically expands
>to fill in any additional columns to the right that are created?

For the following I assume the Microsoft Scripting Host
with Microsoft JScript and Microsoft Excel.

One can measure the number of filled columns extending to
the right and starting at cell »A1« using

..Cells( 1, 1 ).End( xlToRight ).Column

. So, for example, the following program prints

The extension is 6

.

var ExcelApp = new ActiveXObject( "Excel.Application" );
var ExcelSheet = new ActiveXObject( "Excel.Sheet" );
var xlToRight = -4161
ExcelSheet.ActiveSheet.Cells( 1, 1 ).Value = "This is column A, row 1";
ExcelSheet.ActiveSheet.Cells( 1, 2 ).Value = "This is column B, row 1";
ExcelSheet.ActiveSheet.Cells( 1, 3 ).Value = "This is column C, row 1";
ExcelSheet.ActiveSheet.Cells( 1, 4 ).Value = "This is column D, row 1";
ExcelSheet.ActiveSheet.Cells( 1, 5 ).Value = "This is column E, row 1";
ExcelSheet.ActiveSheet.Cells( 1, 6 ).Value = "This is column F, row 1";
WSH.echo
( "The extension is " +
ExcelSheet.ActiveSheet.Cells( 1, 1 ).End( xlToRight ).Column );
ExcelSheet.Application.Quit();

Scott Sauyet

4/2/2016 8:03:00 PM

0

ottopageken wrote:

> I have a function similar to the following:
> function Tabulate() {
> var spreadsheetAll = SpreadsheetApp.getActiveSpreadsheet();
> var currentSheet = ss.getSheetByName("XYZ");
> var $CountofColumnsinSheet= 27
> var $combinedAll= currentSheet.getRange
> (27,2,currentSheet.getLastRow(),1).getValues();
> [ ... ]
> I plan on adding more columsn so that var $CountofColumnsinSheet will
> grow to 28 or 29 or 30. I don't want to have to go into my Script Editor
> to constantly change the var $CountofColumnsinSheet to some
> incrementally larger number and then make appropriate changes in var
> $Combined where I would need to change the initial 27 to 28 or 29. Is
> there a function in JavaScript that automatically expands to fill in any
> additional columns to the right that are created?

You have not given enough context here. What environment is this in
which you're editing spreadsheets? What do you mean by "automatically
expands to fill in any additional columns"? Are you expecting something
to add data to a spreadsheet to accomplish this?

Please start over and start from the beginning. What are you trying to
do, and where are you attempting it?

-- Scott