Advertisement
Guest User

Untitled

a guest
May 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2.  
  3. <!--- This will be you dbQuery for your export --->
  4. <cfset qList = queryNew("c1,c2,c3") />
  5. <cfloop from="1" to="10" index="i">
  6. <cfset queryAddRow(qList, 1) />
  7. <cfset querySetCell(qList, "C1", i) />
  8. <cfset querySetCell(qList, "C2", "10/" & i & "/1985") />
  9. <cfset querySetCell(qList, "C3", "Vikas" & i) />
  10. </cfloop>
  11.  
  12. <!--- 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 --->
  13. <cfset data = arrayNew(1) />
  14. <cfloop query="qList">
  15. <cfset dataRow = structNew() />
  16. <cfset dataRow.ID = qList.c1 />
  17. <cfset dataRow.Name = qList.c3 />
  18. <cfset dataRow.DOB = qList.c2 />
  19. <cfset ArrayAppend(data, dataRow) />
  20. </cfloop>
  21.  
  22. <!--- We delcared column order once we have JSON file ready. This makes an easy process if you want to reorder columns --->
  23.  
  24. <cfset hdr = ["ID","Name","DOB"] />
  25.  
  26. <!--- Our final JSON object will be in 2 dimentional array with specification of all cell formatting --->
  27. <cfset arrData = arrayNew(2) />
  28. <cfloop from="1" to="#arrayLen(data)#" index="i">
  29. <cfloop from="1" to="#arrayLen(hdr)#" index="j">
  30. <cfset cell = structNew() />
  31.  
  32. <!--- 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 --->
  33. <cfset cell.value = " " & data[i][hdr[j]] />
  34. <cfif hdr[j] EQ "ID">
  35. <cfset cell.number = " 1" />
  36. <cfset cell.format = " 0.0" />
  37. <cfelseif hdr[j] EQ "Name">
  38. <cfset cell.style.color = " red" />
  39. <cfset cell.style.backgroundcolor = " Yellow" />
  40. </cfif>
  41. <cfset arrData[i][j] = cell />
  42. </cfloop>
  43. </cfloop>
  44.  
  45. <!--- This output needs to be uploaded in Google Drive as a JSON file --->
  46. <cfoutput>#SerializeJSON(arrData)#</cfoutput>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement