I have a Google form in which users enter their zip code. The form responses are recorded onto a Google spreadsheet, which is then synced with a Google Fusion Table to be geocoded onto a map. The zip codes are formulated as text in the spreadsheet to retain the leading zero, but when synced to the fusion table the zero is removed. Is there a way to retain the column formatting when the spreadsheet is synced to fusion tables so the leading zero is not removed?
Asked
Active
Viewed 4,021 times
4
-
@pnuts I added an array formula to a new column in the spreadsheet that formats the zip codes as text and adds the zero back. This is the formula I'm using: =ARRAYFORMULA(TEXT(D1:D, "00000")) – Sean Henderson Jan 21 '15 at 17:33
-
1Is the sync done in code? I found these instructions: [Fusion Tables Form Sync](http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesFormSync/docs/reference.html) How does the sync happen? – Alan Wells Jan 21 '15 at 17:36
-
@SandyGood yes, those are the instructions I followed to sync the spreadsheet with the fusion table. The sync works great, only issue is the zip codes losing the leading zeros. – Sean Henderson Jan 21 '15 at 17:38
-
1@pnuts wouldn't that formula only format the zip codes for cells D1 to D10? I need to format an indefinite number of rows as user responses come in. – Sean Henderson Jan 21 '15 at 17:40
-
1@pnuts I just tried adding the `'` but unfortunately fusion tables ignores it and still removes the leading zero :( – Sean Henderson Jan 21 '15 at 17:42
-
1@pnuts unfortunately no luck with that either – Sean Henderson Jan 21 '15 at 17:47
2 Answers
0
From those instructions, there is one function named sync()
. See code below: So, I'm assuming that this is the code that is doing the work. This is to big for the comments section, so I'm posting it in an answer, or I'd have to edit your question. So, let me know in the comments if this is the code.
/**
* 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();
}
}

Alan Wells
- 30,746
- 15
- 104
- 152
-
that is the code I'm using to sync the spreadsheet and fusion table. Do you think there may be a way to edit that code so that the fusion table retains all the formulas and formatting from the spreadsheet? – Sean Henderson Jan 21 '15 at 18:03
-
It's a possibility worth examining. In your Fusion table, click on the column header, and choose "change". In the TYPE section, you can change the format to text if it's not already. If the current type is number, the fusion table maybe automatically deleting leading zeros. – Alan Wells Jan 21 '15 at 19:49
0
I have the same problem while importing account numbers. Whenever I am importing any account numbers, all the leading zero before numbers not showing.
I have solved it using data as plain text. Before importing any value from the spreadsheet, make column value plain text using Format Menu -> Number -> Plain Text

prajapati1010
- 1
- 2