Assign a value to the first row of cells + WPS JS to get the total number of rows in the worksheet + WPS JS to get the total number of rows in the worksheet

Poke me to learn more about office tips

assign a value to the cell in the first row

operation result

1. There is an ASCII code in the computer, in which Athe number represented in the computer is 65, athe ASCII code is 97, band the ASCII code is 98.ASCII code table

2. From A1to, F1you can see that the first letter is changing, the second number is always 1, the AASCII code is 65, Fand the ASCII code is 70.

3. We define letter=65, so that the letter gradually approaches 70.

4. Sheets.Item(1).Range("A1").Value2='小知识酷'We have learned that this line of code means that the value of cell A1 is "cool knowledge", so we only need to increment the value at position A.

5. String.fromCharCode(letter), letteris a variable defined by yourself, String.fromCharCode(65)which converts the ascii code into characters A.

function test(){
	for(var letter = 65;letter <= 70; letter++){
		Sheets.Item(1).Range(String.fromCharCode(letter) +"1").Value2 = letter;
	} 
}
Replenish

1. If you define it directly letter = 'a', and then make the letter gradually increase, I tried it, but it doesn't work. It will only output the first value.

function test(){
	for(var letter = 'a';letter <= 'c'; letter++){
		Sheets.Item(1).Range(letter+"1").Value2 = letter;
	} 
}

running result

2. To simplify the code, the window will input a,#QNAN

function test(){
	var letter = 'a';
	alert(letter);
	++letter;
	alert(letter);
}

3. Add 1 to the value of letter to make it larger. The window will enter a, a1, and they will be linked.

function test(){
	var letter = 'a';
	alert(letter);
	letter = letter + 1;
	alert(letter);
}

WPS JS gets the total number of rows of the worksheet

Get the total number of rows in the worksheet being used

function UsedRangeNum(){
	let a=ActiveSheet.UsedRange.Rows.Count;
	alert(a);
}

As shown in the figure, the running result outputs 5

  1. Get the total number of table rows used in the first table:var colcount=wb.Worksheets(1).UsedRange.Cells.Rows.Count ;
  2. Get the total number of columns used in the first table:var colcolumn=wb.Worksheets(1).UsedRange.Columns.Count;
  3. Get the total number of rows used in the table "Little Knowledge Cool":var colcount=wb.Worksheets(“小知识酷”).UsedRange.Cells.Rows.Count ;

Guess you like

Origin blog.csdn.net/MrFlySand/article/details/131149552