I. Overview
1.1 Requirement
How to get or modify the value of a cell through JavaScript, as shown below:
Get the value of a cell:
Modify the value of a cell:
1.2 Solution
Add a button widget and add a JS event to it to get or modify the value of a cell.
II. Sample
2.1 Steps
1) Add two buttons—one is used to get the value and the other is used to assign the value, as shown in the figure below:
2) Add a Click Event to the button used for getting the value:
Input the following JS codes:
// Get the value of the cell by sheet, column and row numbers
var v1=contentPane.getCellValue(0,1,3);
// Get the value of the cell by the column number
var v2=contentPane.curLGP.getCellValue(3,3);
//Get the value of the cell by cell name
var v3=contentPane.curLGP.getCellValue("E4");
alert("The value of the second column and the fourth row of the first sheet is " +v1+ "\n The value in column 4 and row 4 is " +v2+ "\n The value of cell E4 is " +v3);
3)Add a JS click event to the Value Assignment button:
Input the following JS codes:
contentPane.setCellValue(0,1,3,"Male");
contentPane.curLGP.setCellValue(3,3,"Phone:");
contentPane.curLGP.setCellValue("E4", null,"19356958746");
alert("The first row and column 4 of the first sheet were changed to Male \n The third row and column 4 were changed to Phone: \n E4 cell was changed to 19356957746");
Note
By inputting the above JS codes, the actual value of a cell will be modified. But if the display value of a cell is modified, it may fail to be submitted for data entry.
2.2 Preview
Save the template and click [Data Entry Preview]. The preview effect on a PC is shown as below: