You are on page 1of 2

var ss = SpreadsheetApp.

getActiveSpreadsheet()
var form = ss.getSheetByName('แผน
่ 1')
var data = ss.getSheetByName('แผน่ 2')

function Submit() {
var values = [[form.getRange("B6").getValue(),
form.getRange("B8").getValue(),
form.getRange("B10").getValue(),
form.getRange("D6").getValue(),
form.getRange("D8").getValue(),
form.getRange("D10").getValue()]]
data.getRange(data.getLastRow() + 1, 1, 1, 6).setValues(values)
Clear()
}

function Clear() {
var clear = ["B3", "B6", "B8", "B10", "D6", "D8", "D10"]
for (var i = 0; i < clear.length; i++) {
form.getRange(clear[i]).clearContent()
}
}

var searchID = 0
function Search() {
var str = form.getRange("B3").getValue()
var values = ss.getSheetByName('แผน
่ 2').getDataRange().getValues()
for (var i = 0; i < values.length; i++) {
var row = values[i]
if (row[searchID] == str) {
form.getRange("B6").setValue(row[0])
form.getRange("B8").setValue(row[1])
form.getRange("B10").setValue(row[2])
form.getRange("D6").setValue(row[3])
form.getRange("D8").setValue(row[4])
form.getRange("D10").setValue(row[5])
}
}
}

function Update() {
var str = form.getRange("B3").getValue()
var values = ss.getSheetByName('แผน
่ 2').getDataRange().getValues()
for (var i = 0; i < values.length; i++) {
var row = values[i]
if (row[searchID] == str) {
var int = i + 1
var values1 = [[form.getRange("B6").getValue(),
form.getRange("B8").getValue(),
form.getRange("B10").getValue(),
form.getRange("D6").getValue(),
form.getRange("D8").getValue(),
form.getRange("D10").getValue()]]
data.getRange(int, 1, 1, 6).setValues(values1)
SpreadsheetApp.getUi().alert('อั พเดตแลว้ ')
}
}
}
function Delete() {
var ui = SpreadsheetApp.getUi()
var response = ui.alert('ตอ
้ งการลบ?', ui.ButtonSet.YES_NO)
if (response == ui.Button.YES) {
var str = form.getRange("B3").getValue()
var values = ss.getSheetByName('แผน ่ 2').getDataRange().getValues()
for (var i = 0; i < values.length; i++) {
var row = values[i]
if (row[searchID] == str) {
var int = i + 1
data.deleteRow(int)
Clear()
}
}
}
}

You might also like