我试图将这两个语句放在Google表格/电子表格的单个单元格中,而不必使用其他单元格?:
IF(A1="x", "YES")
IF(B1="x", "SIR")
例如,如果A1有'x'而B1有'x',我想在C1中看到“YESSIR”。如果要么有'x',那么C1要么分别有“YES”或“SIR”。
我相信这可以通过创建两个允许我连接的额外列来轻松实现。但是,我想将公式的使用限制为仅一列。
答案 0 :(得分:1)
您可以在单列内使用import sqlite3
import csv
import os
db= "mydb.sqlite"
con = sqlite3.connect(db)
con.text_factory = str # allows utf-8 data to be stored
cursor = con.cursor()
csvfile= 'mycsv.csv'
tablename = os.path.splitext(os.path.basename(csvfile))[0]
with open (csvfile, 'r') as f:
reader = csv.reader(f)
header_line_from_csv = next(reader)
columns = [h.strip() for h in header_line_from_csv] #Strips white space in header
headers= ', '.join([f'{column} text' for column in columns]) ##
sql = f'CREATE TABLE {tablename} ({headers})'
print (sql)
cursor.execute(sql)
query = 'insert into {0}({1}) values ({2})'
query = query.format(tablename, ','.join(columns), ','.join('?' * len(columns)))
print(query)
cursor = con.cursor()
for row in reader:
cursor.execute(query, row)
con.commit()
print(cursor.rowcount)
cursor.execute(f"SELECT * FROM {tablename}")
print("fetchall:\n",cursor.fetchall())
print(cursor.description)
con.close()
CONCAT
,即公式为:
IF
答案 1 :(得分:0)
尝试此自定义功能。这是你输入的内容:= specialOr(A1," x","是",A2," x"," sir&#34 ;)
function specialOr(val1,match1,output1,val2,match2,output2)
{
if(val1==match1 && val2==match2)
{
return String(output1 + output2);
}else
if(val1==match1 && val2!=match2)
{
return output1;
}else
if(val2==match2 && val1!=match2)
{
return output2
}else
return '';
}
答案 2 :(得分:0)
使用REPT
以及连接运算符&
:
=REPT("YES", A1="x") & REPT("SIR",B1="x")