Last active
September 29, 2016 10:05
-
-
Save isummation/1fc6c3577ad960a4119b60582761a652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--- This will be you dbQuery for your export ---> | |
| <cfset qList = queryNew("c1,c2,c3") /> | |
| <cfloop from="1" to="10" index="i"> | |
| <cfset queryAddRow(qList, 1) /> | |
| <cfset querySetCell(qList, "C1", i) /> | |
| <cfset querySetCell(qList, "C2", "10/" & i & "/1985") /> | |
| <cfset querySetCell(qList, "C3", "Vikas" & i) /> | |
| </cfloop> | |
| <!--- This will be your JSON file for your shpreadsheet content. If you have paging query, you can store this JSON in text file and append new data for each page ---> | |
| <cfset data = arrayNew(1) /> | |
| <cfloop query="qList"> | |
| <cfset dataRow = structNew() /> | |
| <cfset dataRow.ID = qList.c1 /> | |
| <cfset dataRow.Name = qList.c3 /> | |
| <cfset dataRow.DOB = qList.c2 /> | |
| <cfset ArrayAppend(data, dataRow) /> | |
| </cfloop> | |
| <!--- We delcared column order once we have JSON file ready. This makes an easy process if you want to reorder columns ---> | |
| <cfset hdr = ["ID","Name","DOB"] /> | |
| <!--- Our final JSON object will be in 2 dimentional array with specification of all cell formatting ---> | |
| <cfset arrData = arrayNew(2) /> | |
| <cfloop from="1" to="#arrayLen(data)#" index="i"> | |
| <cfloop from="1" to="#arrayLen(hdr)#" index="j"> | |
| <cfset cell = structNew() /> | |
| <!--- Notice that we are prepending space for each values because we don't want serialization and deserialization changes our value. e.g. "0.0" will be converted to 0 ---> | |
| <cfset cell.value = " " & data[i][hdr[j]] /> | |
| <cfif hdr[j] EQ "ID"> | |
| <cfset cell.number = " 1" /> | |
| <cfset cell.format = " 0.0" /> | |
| <cfelseif hdr[j] EQ "Name"> | |
| <cfset cell.style.color = " red" /> | |
| <cfset cell.style.backgroundcolor = " Yellow" /> | |
| </cfif> | |
| <cfset arrData[i][j] = cell /> | |
| </cfloop> | |
| </cfloop> | |
| <!--- This output needs to be uploaded in Google Drive as a JSON file ---> | |
| <cfoutput>#SerializeJSON(arrData)#</cfoutput> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment