我有一个Google表单,用户可以在其中输入邮政编码。表单回复会记录在Google电子表格中,然后与Google Fusion Table同步,以便对地图进行地理编码。邮政编码在电子表格中表示为文本以保留前导零,但是当同步到融合表时,零被删除。有没有办法在电子表格同步到融合表时保留列格式,以便不删除前导零?
答案 0 :(得分:0)
根据这些说明,有一个名为sync()
的函数。请参阅下面的代码:所以,我假设这是正在进行工作的代码。这对于评论部分来说很重要,所以我将其发布在答案中,或者我必须编辑您的问题。所以,如果这是代码,请在评论中告诉我。
/**
* Syncs the Fusion Table to the form data. Run this every hour or so.
*/
function sync() {
init();
// Get the data in the spreadsheet and convert it to a dictionary.
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var spreadsheetData = sheet.getRange(1, 1, lastRow, lastColumn);
var spreadsheetValues = spreadsheetData.getValues();
var columns = spreadsheetValues[0];
var spreadsheetMap = mapRowsByRowId(columns,
spreadsheetValues.slice(1, spreadsheetValues.length));
// Get the columns in the spreadsheet and escape any single quotes
var escapedColumns = [];
for (var i = 0; i < columns.length; i++) {
var columnName = columns[i];
columnName = escapeQuotes(columnName);
escapedColumns.push(columnName);
if (column === ADDRESS_COLUMN) {
escapedColumns.push(escapedQuotes(LOCATION_COLUMN));
}
}
// Get the data from the table and convert to a dictionary.
var query = "SELECT '" + escapedColumns.join("','") + "' FROM " + DOCID;
var ftResults = runSqlWithRetry(query);
if (!ftResults) {
return;
}
var ftMap = mapRowsByRowId(ftResults.columns, ftResults.rows);
// For each row in the Fusion Table, find if the row still exists in the
// spreadsheet. If it exists, make sure the values are the same. If
// they are different, update the Fusion Table data.
// If the row doesn't exist in the spreadsheet, delete the row from the table.
for (var rowId in ftMap) {
var spreadsheetRow = spreadsheetMap[rowId];
if (spreadsheetRow) {
var updates = [];
var tableRow = ftMap[rowId];
for (var column in tableRow) {
if (column === 'rowid') {
continue;
}
var tableValue = tableRow[column];
var spreadsheetValue = spreadsheetRow[column];
if (tableValue != spreadsheetValue) {
spreadsheetValue = processSpreadsheetValue(column, spreadsheetValue, updates, true);
}
}
// If there are updates, send the UPDATE query.
if (updates.length) {
var query = [];
query.push('UPDATE ');
query.push(DOCID);
query.push(' SET ');
query.push(updates.join(','));
query.push(" WHERE rowid = '");
query.push(rowId);
query.push("'");
runSqlWithRetry(query.join(''));
waitBetweenCalls();
}
} else {
// If the row doesn't exist in the spreadsheet, delete it from the table
runSqlWithRetry('DELETE FROM ' + DOCID + " WHERE rowid = '" +
rowId + "'");
waitBetweenCalls();
}
}
// Insert all the data into the Fusion Table that failed to insert.
// These rows were given a rowid of -1 or have a blank rowid.
var failedInserts = spreadsheetMap[-1];
for (var i = 0; failedInserts && i < failedInserts.length; i++) {
var rowId = createRecord(failedInserts[i]);
if (!rowId) {
rowId = -1;
}
insertRowId(rowId, failedInserts[i].spreadsheetRowNum);
waitBetweenCalls();
}
}
答案 1 :(得分:0)
导入帐号时遇到相同的问题。每当我导入任何帐号时,数字前的所有前导零都不会显示。
我已经使用数据作为纯文本解决了它。从电子表格导入任何值之前,请使用格式菜单->数字->纯文本
将列值设置为纯文本