ExportToCSV exporter = new ExportToCSV(this.ketticGridView1); string fileName = "C:\\ExportedGridData1.csv"; exporter.RunExport(fileName); void exporter_CSVFormatCell(object sender, Kettic.WinForms.UI.Export.CSV.CSVFormatCellEventArgs e) { if (e.GridColumnIndex == 1 && e.GridRowInformationType == typeof(GridViewDataRowInformation)) { e.CSVCellElement.Value = "Value for Test"; } }
<div id="tp_print" data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Print Options', closable:false, open:false"> <div> <form data-dojo-type="dijit/form/Form" method="post" action="" style="height: 0px; width: 0px; display:none;" class="dlform" id="downloadForm" target="_blank"> <input type="hidden" name="report" class="ri" id="reportinput" value="" /> <input type="hidden" name="filename" class="fn" id="filename" value="" /> <input type="hidden" name="s" class="s" id="s" value="" /> <input type="hidden" name="numberofcolumns" class="rit" id="numberofcolumns" value="pdf" /> </form> <button id="btnExportGridCSV" data-dojo-type="dijit/form/Button" data-dojo-props="title:'Save Search Results to CSV file', label:'Save List'"></button> </div> </div>
//functions for printing function exportGridCSV() {//creates a CSV file that can be saved by the user var fieldValue = ""; dataArray.length = 0; arrayUtil.forEach(qTaskNameList, function(gridName) { dataArray.length = 0; var gridData = registry.byId(gridName+"_grid"); var gridLength = gridData.rowCount; var fields = gridData.layout.cells; fieldNames.length = 0; //populates an array with the field names used to find the values in the data store if (fields.length > 0){ arrayUtil.forEach(fields, function (field) { if (field.name) { //this skips the internal IDs, which don't have names var lastField = fields[fields.length -1].name; var fName = field.name; fieldNames.push(fName); if (fName != lastField) { dataArray.push(fName); } else { dataArray.push(fName+" \n"); } } }); } if (gridLength > 0) {//don't try to export if there were not values in that grid var gridStore = gridData.store._arrayOfAllItems;//the store of one grid //populates the array with the values for one record for (var i=0; i< gridStore.length; i++) { rowData.length = 0; var gridRec = gridStore; arrayUtil.forEach (fieldNames, function(fieldName) { var lastField = fieldNames[fieldNames.length -1]; fieldValue = gridRec[fieldName]; var stringValue = String(fieldValue); if (stringValue.indexOf(",") > 0) { console.log ("Field Value before replace " + stringValue); stringValue = stringValue.replace(/,/g , " "); console.log ("Field Value after replace = " + stringValue); } if (stringValue.indexOf('\'') != -1 || stringValue.indexOf('\"') != -1 ) { console.log ("Data has a slash in it. Not sure of this section of the code!"); if (stringValue.indexOf('\"') != -1) { stringValue = stringValue.replace("\"", "\"\""); } stringValue = "\"" + stringValue + "\""; } if (fieldName == lastField) { dataArray.push(stringValue + " \n"); }else{ dataArray.push(stringValue); } }); }//end of one row of datarecord } var data = dataArray.join(); var inputData = data.replace(/\n,/g, "\n");//some clean up to get rid of the leading commas in the data submitCSVprint(gridName, inputData);//calls the form that is mostly hidden which runs the c# script }); }
function submitCSVprint(gridName, inputData) { //opens the data in a hidden form used for printing and allows the user to either open or save the file. var url = "webservices/csv.ashx"; var f = registry.byId("downloadForm"); f.action = url; dom.byId("reportinput").value = inputData; var distType = registry.byId("distTypeSelect").value; var distNum = registry.byId("txtDistNumber").value; dom.byId("filename").value = distType+"Dist_"+distNum+"_"+gridName; f.submit(); }
<%@ WebHandler Language="C#" Class="csv" %> using System; using System.Web; public class csv : IHttpHandler { public void ProcessRequest (HttpContext context) { String content = "no data"; String filename = "MyFile"; if (context.Request["report"] != null) { try { content = context.Request["report"].ToString(); } catch { } } if (context.Request["filename"] != null) { try { filename = context.Request["filename"].ToString() + "_" + DateTime.Now.ToString("MMdyyyy"); } catch { } } context.Response.ContentType = "text/csv"; context.Response.AddHeader("Content-disposition","attachment;filename="+filename+".csv"); context.Response.Write(content); } public bool IsReusable { get { return false; } } }
var inputData = data.replace(/\n,/g, "\n");//some clean up to get rid of the leading commas in the data
function exportGridCSV() { dataArray.length = 0; var fieldValue; var fieldNames = []; //qTaskNameList created from query task that populated the grids dojo.forEach(qTaskNameList, function(gridName) { var gridData = dijit.byId(gridName+"_grid"); var gridLength = gridData.rowCount; var fields = gridData.layout.cells; var fieldNames.length = 0; //populates an array with the field names used to find the values in the data store dojo.forEach(fields, function (field) { fieldNames.push(field.field); dataArray.push(field.field); }); dataArray.push("\r");//first line is the field names if (gridLength > 0) {//don't try to export if there were not values in that grid var gridStore = gridData.store._arrayOfAllItems;//the store of one grid //for each record, populates the array with the values for the fields stored in the field array for (var i=0; i< gridStore.length; i++) { var gridRec = gridStore; var j = 0; dojo.forEach (fieldNames, function(fieldName) { fieldValue = gridRec[fieldName]; if (isNaN(fieldValue)) {//for data containing slashes if (fieldValue.indexOf('\'') != -1 || fieldValue.indexOf('\"') != -1 || fieldValue.indexOf(',') != -1) { if (fieldValue.indexOf('\"') != -1) { fieldValue = fieldValue.replace("\"", "\"\""); } fieldValue = "\"" + fieldValue + "\""; } } dataArray.push(fieldValue); j++; }); dataArray.push("\r"); }//end of record dataArray.push("\r"); //puts an empty row before the next set of records } }); submitCSVprint(); } function submitCSVprint() { //opens the data in a hidden form used for printing and allows the user to either open or save the file. var url = "webservices/csv.ashx"; var data = dataArray.join(); var f = dojo.byId("downloadForm"); f.action = url; dojo.byId("reportinput").value = data; var distType = dijit.byId("distTypeSelect").value; var distNum = dojo.byId("txtDistNumber").value; dojo.byId("filename").value = distType+"_Dist_"+distNum+"_"; f.submit(); }
Could you please provide all the code for your MyWebHandler.ashx file? I am trying to implement your strategy but keep getting errors in that file. I assume I missed some code or something so if you could provide the entire code for that file it would be greatly appreciated.Thanks,Mark
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; System.Collections.Specialized.NameValueCollection parameters = context.Request.Form; string moduleName = parameters["module"]; string requestFeedback = ""; switch (moduleName) { case "ExportToExcel": EgisWeb.ExportHelper objExportCSVHelper = new EgisWeb.ExportHelper(); objExportCSVHelper.CSV2Excel(parameters["csvdata"].ToString(), HttpContext.Current, parameters["title"].ToString()); break; } if (moduleName != "ExportToExcel") context.Response.Write(requestFeedback); }
I have taken this approach for exporting the data to csv from datagrid.Added a form in page with hidden attribute and set its action to handler[HTML]<form id="csvForm" action="Handlers/MyWebHandler.ashx?module=ExportToExcel" method="post"><input type="hidden" value="" id="csvdata" name="csvdata" /><input type="hidden" value="" id="title" name="title" /></form>[/HTML]Then in js function is written to get the grid data. function exportCSVData() { var gridData = dijit.byId("grid"); var csvdatafield = dojo.byId("csvdata"); var csvText = ""; var fields = gridData.structure[0].cells[0]; if (fields != null && fields.length > 0) { for (var ifldCnt = 0; ifldCnt < fields.length; ifldCnt++) { if (ifldCnt == 0) { csvText = fields[ifldCnt].name; } else { csvText += "," + fields[ifldCnt].name; } } csvText += "\n"; var fieldValue = ""; for (var i = 0; i < gridData.rowCount; i++) { var featureAttribute = gridData.store._arrayOfAllItems; var columnVal; for (var ifldCnt = 0; ifldCnt < fields.length; ifldCnt++) { fieldValue = ""; //columnVal = this.getValuefromAttribute(featureAttribute[fields[ifldCnt].field], false, ""); columnVal = featureAttribute[fields[ifldCnt].field][0]; if (columnVal != null && columnVal != "") fieldValue = columnVal; if (isNaN(fieldValue)) { if (fieldValue.indexOf('\'') != -1 || fieldValue.indexOf('\"') != -1 || fieldValue.indexOf(',') != -1) { if (fieldValue.indexOf('\"') != -1) { fieldValue = fieldValue.replace("\"", "\"\""); } fieldValue = "\"" + fieldValue + "\""; } } if (ifldCnt == 0) csvText += fieldValue; else csvText += "," + fieldValue; } csvText += "\n"; } if (csvText != "") csvText = escape(csvText); csvdatafield.value = csvText; // After value is set for the hidden field submit the form var formCSV = dojo.byId("csvForm"); formCSV.submit(); } }Once the form is submitted, the control is passed to handler, that will fetch the data from form submitted and create csvIn handler get the attributes "MyWebHandler.ashx" public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; System.Collections.Specialized.NameValueCollection parameters = context.Request.Form; string moduleName = parameters["module"]; ExportHelper objExportCSVHelper = new ExportHelper(); objExportCSVHelper.ExportToCSV(parameters["csvdata"].ToString(), HttpContext.Current, parameters["title"].ToString()); }And in ExportHelper class write the ExportToCSV Function public void CSV2Excel(string strCSV, HttpContext current, string strTitle) { current.Response.Clear(); strCSV = removeUniCodeSequenceCharacters(strCSV); strCSV = System.Text.RegularExpressions.Regex.Unescape(strCSV); current.Response.AddHeader("content-disposition", "attachment;filename=" + strTitle +"_"+DateTime.Now.ToString("ddmmyyyyHHMMSS") + ".csv"); current.Response.Charset = ""; current.Response.ContentType = "application/octet-stream"; current.Response.Write(strCSV); current.Response.End(); } //Since we used escape to send text from javascript to Server side we need this function private string removeUniCodeSequenceCharacters(string strWithEscapeSequence) { string strUse = ""; strUse = strWithEscapeSequence.Replace("%20", " "); strUse = strUse.Replace("%2C", ","); strUse = strUse.Replace("%27", "'"); strUse = strUse.Replace("%22", "\""); strUse = strUse.Replace("%3F", "?"); strUse = strUse.Replace("%0A", "\n"); strUse = strUse.Replace("%28", "("); strUse = strUse.Replace("%29", ")"); strUse = strUse.Replace("%26", "&"); strUse = strUse.Replace("%23", "#"); strUse = strUse.Replace("%3A", ":"); strUse = strUse.Replace("%21", "!"); strUse = strUse.Replace("%2D", "-"); strUse = strUse.Replace("%3B", ";"); strUse = strUse.Replace("%2A", "*"); strUse = strUse.Replace("%2B", "+"); strUse = strUse.Replace("%2E", "."); strUse = strUse.Replace("%3C", "<"); strUse = strUse.Replace("%3D", "="); strUse = strUse.Replace("%3E", ">"); strUse = strUse.Replace("%40", "@); return strUse; }
function exportCSVData() { var gridData = dijit.byId("grid"); var csvdatafield = dojo.byId("csvdata"); var csvText = ""; var fields = gridData.structure[0].cells[0]; if (fields != null && fields.length > 0) { for (var ifldCnt = 0; ifldCnt < fields.length; ifldCnt++) { if (ifldCnt == 0) { csvText = fields[ifldCnt].name; } else { csvText += "," + fields[ifldCnt].name; } } csvText += "\n"; var fieldValue = ""; for (var i = 0; i < gridData.rowCount; i++) { var featureAttribute = gridData.store._arrayOfAllItems; var columnVal; for (var ifldCnt = 0; ifldCnt < fields.length; ifldCnt++) { fieldValue = ""; //columnVal = this.getValuefromAttribute(featureAttribute[fields[ifldCnt].field], false, ""); columnVal = featureAttribute[fields[ifldCnt].field][0]; if (columnVal != null && columnVal != "") fieldValue = columnVal; if (isNaN(fieldValue)) { if (fieldValue.indexOf('\'') != -1 || fieldValue.indexOf('\"') != -1 || fieldValue.indexOf(',') != -1) { if (fieldValue.indexOf('\"') != -1) { fieldValue = fieldValue.replace("\"", "\"\""); } fieldValue = "\"" + fieldValue + "\""; } } if (ifldCnt == 0) csvText += fieldValue; else csvText += "," + fieldValue; } csvText += "\n"; } if (csvText != "") csvText = escape(csvText); csvdatafield.value = csvText; // After value is set for the hidden field submit the form var formCSV = dojo.byId("csvForm"); formCSV.submit(); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; System.Collections.Specialized.NameValueCollection parameters = context.Request.Form; string moduleName = parameters["module"]; ExportHelper objExportCSVHelper = new ExportHelper(); objExportCSVHelper.ExportToCSV(parameters["csvdata"].ToString(), HttpContext.Current, parameters["title"].ToString()); }
public void CSV2Excel(string strCSV, HttpContext current, string strTitle) { current.Response.Clear(); strCSV = removeUniCodeSequenceCharacters(strCSV); strCSV = System.Text.RegularExpressions.Regex.Unescape(strCSV); current.Response.AddHeader("content-disposition", "attachment;filename=" + strTitle +"_"+DateTime.Now.ToString("ddmmyyyyHHMMSS") + ".csv"); current.Response.Charset = ""; current.Response.ContentType = "application/octet-stream"; current.Response.Write(strCSV); current.Response.End(); } //Since we used escape to send text from javascript to Server side we need this function private string removeUniCodeSequenceCharacters(string strWithEscapeSequence) { string strUse = ""; strUse = strWithEscapeSequence.Replace("%20", " "); strUse = strUse.Replace("%2C", ","); strUse = strUse.Replace("%27", "'"); strUse = strUse.Replace("%22", "\""); strUse = strUse.Replace("%3F", "?"); strUse = strUse.Replace("%0A", "\n"); strUse = strUse.Replace("%28", "("); strUse = strUse.Replace("%29", ")"); strUse = strUse.Replace("%26", "&"); strUse = strUse.Replace("%23", "#"); strUse = strUse.Replace("%3A", ":"); strUse = strUse.Replace("%21", "!"); strUse = strUse.Replace("%2D", "-"); strUse = strUse.Replace("%3B", ";"); strUse = strUse.Replace("%2A", "*"); strUse = strUse.Replace("%2B", "+"); strUse = strUse.Replace("%2E", "."); strUse = strUse.Replace("%3C", "<"); strUse = strUse.Replace("%3D", "="); strUse = strUse.Replace("%3E", ">"); strUse = strUse.Replace("%40", "@); return strUse; }
Are you using the python script tabletoexcel.py that i pointed to? if so, here is how i modified it to fit my use. I added Make Feature Layer (or Make Table View) with the Query Expression (the same as you use query task's where clause). then use the result feature layer or table view (in your case would be data store) as the first input for the tabletoexcel.py and published it as a GP service (i also include a zip module to zip the result).
There is a python script in http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=95009B25-1422-2418-7FB5-B8638ECB2FA9. You can easily modify it and use it as a GP Service. I personally used it to convert a query results (FeatureSet) to CSV or .XLS file.
Heming,Before I use the example you provided, I am trying to use the following sample. I have it working, the problem is that only one result is being exported from the data store. I think it has to do with the feature attributes returning only one result. Does an Identify Task return a Feature Set?http://arcscripts.esri.com/details.asp?dbid=16528 function executeIdentifyTask(geom) { //clear the graphics layer map.graphics.clear(); identifyParams.geometry = geom; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams,function(response){ var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,94,204,0.8])); var markerSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([25,50,225,0.3])); var controlItems = []; var surveyItems = []; dojo.forEach(response,function(result){ var feature = result.feature; alert(feature.attributes); if (result.layerName =="surveys"){ showSurveysNameGrid(); feature.setSymbol(polygonSymbol); //searchType="selSurvey"; //for (var i = 0; i < feature.length; i++) { //alert(result.feature); var attributes = feature.attributes; surveyItems.push(attributes); var csvTextSurv = "DOCUMENT_N;TOWNSHIP_RANGE;SECTION\n"; csvTextSurv += attributes["DOCUMENT_N"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; document.getElementById("csvSurv").value = csvTextSurv; map.graphics.add(feature); }
function executeIdentifyTask(geom) { //clear the graphics layer map.graphics.clear(); identifyParams.geometry = geom; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams,function(response){ var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,94,204,0.8])); var markerSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([25,50,225,0.3])); var controlItems = []; var surveyItems = []; dojo.forEach(response,function(result){ var feature = result.feature; alert(feature.attributes); if (result.layerName =="surveys"){ showSurveysNameGrid(); feature.setSymbol(polygonSymbol); //searchType="selSurvey"; //for (var i = 0; i < feature.length; i++) { //alert(result.feature); var attributes = feature.attributes; surveyItems.push(attributes); var csvTextSurv = "DOCUMENT_N;TOWNSHIP_RANGE;SECTION\n"; csvTextSurv += attributes["DOCUMENT_N"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; document.getElementById("csvSurv").value = csvTextSurv; map.graphics.add(feature); }
I am getting close. The problem is that only one result, the last one, from my datagrid is showing up in my text area for export to excel. I think the csv is not getting the full results from the feature selected, for some reason it only gets one. How do I get the full results of the selection ready for csv export? function executeIdentifyTask(geom) { //clear the graphics layer map.graphics.clear(); identifyParams.geometry = geom; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams,function(response){ var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,94,204,0.8])); var markerSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([25,50,225,0.3])); var controlItems = []; var surveyItems = []; dojo.forEach(response,function(result){ var feature = result.feature; if (result.layerName =="surveys"){ showSurveysNameGrid(); feature.setSymbol(polygonSymbol); var attributes = feature.attributes; surveyItems.push(attributes); var csvTextSurv = "DOCUMENT_N;TOWNSHIP_RANGE;SECTION\n"; csvTextSurv += attributes["DOCUMENT_N"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; document.getElementById("csvSurv").value = csvTextSurv; map.graphics.add(feature); }else{ showPointNameGrid(); feature.setSymbol(markerSymbol); var attributes = feature.attributes; controlItems.push(feature.attributes); var csvTextMons = "POINT_NAME;SECTION\n"; csvTextMons += attributes["POINT_NAME"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; } document.getElementById("csvMons").value = csvTextMons; map.graphics.add(feature); }); if(surveyItems.length >0){ showSurveysNameGrid(); var surveysStore = new dojo.data.ItemFileReadStore({data:{identifier:'DOCUMENT_N',items:surveyItems}}); var grid = dijit.byId('grid5'); grid.setStore(surveysStore); } if(controlItems.length >0){ showPointNameGrid(); var controlStore = new dojo.data.ItemFileReadStore({data:{identifier:'POINT_NAME',items:controlItems}}); var grid = dijit.byId('grid4'); grid.setStore(controlStore); } }); } <div id="footerPoints" class="roundedCorners" dojotype="dijit.layout.ContentPane" region="bottom" style=" padding-bottom:5%; height:18%; display:none"> <form action="http://surveyor.slco.org/JSAPIExportToExcel/DojoGridToExcel.asmx/CSV2Excel " method="POST"> <textarea name="csv" id="csvMons" style="width: 500px; height:30px"></textarea> <input type="submit" value="Submit" /> </form> <table dojotype="dojox.grid.DataGrid" data-dojo-id="grid4" id="grid4" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'"> <thead> <tr> <th field="POINT_NAME" width="200px" > Point Name </th> <th field="GRID_ADDRESS" width="200px" > Address </th> <th field='TOWNSHIP_RANGE' width='200px'>Township/Range</th> <th field="SECTION" width="200px" > Section </th> <th fields="POINT_NAME,LONGITUDE_DD,LATITUDE_DD" formatter="makeLink1" width="200px" > Monument Reference Sheet </th> <th field="MON_NOTES" width="200px" > Monument Notes </th> </tr> </thead> </table> </div> <div id="footersurvName" class="roundedCorners" dojotype="dijit.layout.ContentPane" region="bottom" style=" padding-bottom:5%; height:18%; display:none"> <form action="http://surveyor.slco.org/JSAPIExportToExcel/DojoGridToExcel.asmx/CSV2Excel " method="POST"> <textarea name="csv" id="csvSurv" style="width: 500px; height:30px"></textarea> <input type="submit" value="Submit" /> </form> <table dojotype="dojox.grid.DataGrid" data-dojo-id="grid5" id="grid5" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'"> <thead> <tr> <th field="DOCUMENT_NUM" width="200px" > Survey Number </th> <th field="SURVEYOR" width="200px" > Surveyor </th> <th field="ADDRESS_OF_SURVEY" width="200px" > Address </th> <th field='TOWNSHIP_RANGE' width='200px'> Township/Range </th> <th field="SECTION" width="200px" > Section </th> <th fields="subdir,page_id" formatter="makeLink" width="200px" > PDF </th> </tr> </thead> </table> </div>
function executeIdentifyTask(geom) { //clear the graphics layer map.graphics.clear(); identifyParams.geometry = geom; identifyParams.mapExtent = map.extent; identifyTask.execute(identifyParams,function(response){ var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,94,204,0.8])); var markerSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([25,50,225,0.3])); var controlItems = []; var surveyItems = []; dojo.forEach(response,function(result){ var feature = result.feature; if (result.layerName =="surveys"){ showSurveysNameGrid(); feature.setSymbol(polygonSymbol); var attributes = feature.attributes; surveyItems.push(attributes); var csvTextSurv = "DOCUMENT_N;TOWNSHIP_RANGE;SECTION\n"; csvTextSurv += attributes["DOCUMENT_N"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; document.getElementById("csvSurv").value = csvTextSurv; map.graphics.add(feature); }else{ showPointNameGrid(); feature.setSymbol(markerSymbol); var attributes = feature.attributes; controlItems.push(feature.attributes); var csvTextMons = "POINT_NAME;SECTION\n"; csvTextMons += attributes["POINT_NAME"] + ";" + attributes["TOWNSHIP_RANGE"] + ";" + attributes["SECTION"] + "\n"; } document.getElementById("csvMons").value = csvTextMons; map.graphics.add(feature); }); if(surveyItems.length >0){ showSurveysNameGrid(); var surveysStore = new dojo.data.ItemFileReadStore({data:{identifier:'DOCUMENT_N',items:surveyItems}}); var grid = dijit.byId('grid5'); grid.setStore(surveysStore); } if(controlItems.length >0){ showPointNameGrid(); var controlStore = new dojo.data.ItemFileReadStore({data:{identifier:'POINT_NAME',items:controlItems}}); var grid = dijit.byId('grid4'); grid.setStore(controlStore); } }); } <div id="footerPoints" class="roundedCorners" dojotype="dijit.layout.ContentPane" region="bottom" style=" padding-bottom:5%; height:18%; display:none"> <form action="http://surveyor.slco.org/JSAPIExportToExcel/DojoGridToExcel.asmx/CSV2Excel " method="POST"> <textarea name="csv" id="csvMons" style="width: 500px; height:30px"></textarea> <input type="submit" value="Submit" /> </form> <table dojotype="dojox.grid.DataGrid" data-dojo-id="grid4" id="grid4" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'"> <thead> <tr> <th field="POINT_NAME" width="200px" > Point Name </th> <th field="GRID_ADDRESS" width="200px" > Address </th> <th field='TOWNSHIP_RANGE' width='200px'>Township/Range</th> <th field="SECTION" width="200px" > Section </th> <th fields="POINT_NAME,LONGITUDE_DD,LATITUDE_DD" formatter="makeLink1" width="200px" > Monument Reference Sheet </th> <th field="MON_NOTES" width="200px" > Monument Notes </th> </tr> </thead> </table> </div> <div id="footersurvName" class="roundedCorners" dojotype="dijit.layout.ContentPane" region="bottom" style=" padding-bottom:5%; height:18%; display:none"> <form action="http://surveyor.slco.org/JSAPIExportToExcel/DojoGridToExcel.asmx/CSV2Excel " method="POST"> <textarea name="csv" id="csvSurv" style="width: 500px; height:30px"></textarea> <input type="submit" value="Submit" /> </form> <table dojotype="dojox.grid.DataGrid" data-dojo-id="grid5" id="grid5" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'"> <thead> <tr> <th field="DOCUMENT_NUM" width="200px" > Survey Number </th> <th field="SURVEYOR" width="200px" > Surveyor </th> <th field="ADDRESS_OF_SURVEY" width="200px" > Address </th> <th field='TOWNSHIP_RANGE' width='200px'> Township/Range </th> <th field="SECTION" width="200px" > Section </th> <th fields="subdir,page_id" formatter="makeLink" width="200px" > PDF </th> </tr> </thead> </table> </div>
itemStore //data store backing your grid var queryResults = itemStore.query(); var output = ''; dojo.forEach(queryResults, function(result) { output = output + '\n' + result['col1'] + ',' + result['col2'] + ',' + result['col3'] + and so on... }); xhr.post(/*post to some serverside script*/); xhr.onSuccess(/*redirect them to download the file*/);
Thanks again for your help!!Do you know if this script works for a Dojo datagrid?
Hi,Has anyone had luck exporting a dojo datagrid to a csv file? The example above is a bit outdated and I am having trouble getting it to work.Thanks!
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.