从电子表格中提取数据以通过Google可视化显示,但日期时间对象引发错误:"脚本已完成但返回的值不是支持的返回类型"生成。
我发现在将日期时间手动转换为"纯文本"格式,一切正常。
Range类有一个清晰的方法,应该能够删除格式,但它是清除单元格中的内容。
clear({formatOnly:true})
段:
var sheetId = '1k1p0SNweftGVBIH4vxBFlkAYEhdRrepmboSyQnm_OXc_we';
var sheet = SpreadsheetApp.openById(sheetId).getSheets()[3];
//The timestamp object causes an error when imported in G.A.S. so the next 4 lines of code removes the formatting.
var range = sheet.getRange("A1:A999");
range.clear({formatOnly:true}); // remove formatting for column A
range = sheet.getRange("E1:E999");
range.clear({formatOnly:true}); // remove formatting for column E
var data = sheet.getDataRange().getValues();
有谁可以帮助澄清这一点并协助解决方案?
答案 0 :(得分:0)
private DataTable table;
private SqlDataAdapter dataAdapter;
private void sampleForm_Load(object sender, EventArgs e)
{
var command = "SELECT * FROM Table1";
var connection = @"Your connection string";
table = new DataTable();
dataAdapter = new SqlDataAdapter(command, connection);
var commandBuilder = new SqlCommandBuilder(dataAdapter);
dataAdapter.Fill(table);
//Set false as default value for Column2
table.Columns["Column2"].DefaultValue = false;
var column1 = new DataGridViewTextBoxColumn();
column1.Name = "Column1";
column1.DataPropertyName = "Column1";
var column2 = new DataGridViewCheckBoxColumn();
column2.Name = "Column2";
column2.DataPropertyName = "Column2";
column2.TrueValue = "Y";
column2.FalseValue = "N";
this.dataGridView1.Columns.Add(column1);
this.dataGridView1.Columns.Add(column2);
//Bind grid to table
this.dataGridView1.DataSource = table;
}
private void saveButton_Click(object sender, EventArgs e)
{
//Save data
this.dataGridView1.EndEdit();
dataAdapter.Update(table);
}
或.clearFormat()
清除范围内一个或多个单元格的文本格式,但不会重置任何数字格式规则。
.clear({formatOnly:true})
如果要设置纯文本格式,
var range = sheet.getRange("A1:A");
range.clearFormat();
您可以进一步参考range class documentation。