private function exportToExcel():void { var featureCollection:ArrayCollection = myFeatureLayer.graphicProvider as ArrayCollection; var exportSet:Array = []; for each (var graphic:Graphic in featureCollection){ if (myMap.extent.intersects(graphic.geometry)) { exportSet.push(graphic.attributes); } } exportData = new ArrayCollection(exportSet); sheet = new Sheet(); var dataProviderCollection:ArrayCollection = ssoDataGrid.dataProvider as ArrayCollection; var rowCount:int = dataProviderCollection.length; sheet.resize(rowCount + 1,ssoDataGrid.columnCount); var columns:Array = ssoDataGrid.columns; var i:int = 0; for each (var field:DataGridColumn in columns){ fields.push(field.dataField.toString()); sheet.setCell(0,i,field.dataField.toString()); i++; } for(var r:int=0; r < rowCount; r++) { var record:Object = dataProviderCollection.getItemAt(r); /*insert record starting from row 2 else headers will be overwritten*/ insertRecordInSheet(r+1,sheet,record); } var xls:ExcelFile = new ExcelFile(); xls.sheets.addItem(sheet); var bytes: ByteArray = xls.saveToByteArray(); var fr:FileReference = new FileReference(); fr.save(bytes,"SSO_Table_Export.xls"); } private function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void { var colCount:int = ssoDataGrid.columnCount; for(var c:int; c < colCount; c++) { var i:int = 0; for each(var field:String in fields){ for each (var value:String in record){ if (record[field].toString() == value) sheet.setCell(row,i,value); } i++; } } } <esri:FeatureLayer id="myFeatureLayer" mode="snapshot" outFields="[ADDRESS,NEIGHBORHOOD,EST_SPILL_START_DATE,EST_SPILL_END_DATE,EST_SPILL_START_TIME,EST_SPILL_END_TIME,SPILL_VOLUME_GAL,CAUSE,CORRECTIVE_ACTION]" definitionExpression="{updateDefExp}" selectionColor="cyan" url="http://ntts10/ArcGIS/rest/services/Maps/sso_spill_type/MapServer/0"/>Solved! Go to Solution.
for each (var value:String in record){ var rvalue:String = (record[field] != null) ? String(record[field]) : ""; if (rvalue == value) { sheet.setCell(row,i,value); } }sheet.setCell(0,i,field.headerText.toString());sheet.setCell(0,i,field.dataField.toString());
yourArrayCollection.removeItemAt(yourArrayCollection.getItemIndex(itemToRemove));
for each(var fldName:String in myFeatureLayer.outFields){
fields.push(fldName);
for each (var field:DataGridColumn in columns){
if(field.dataField.toString() == fldName){
sheet.setCell(0,i,field.headerText.toString());
i++;
break;
}
}
}
//Create function to export attribute data to excel
private function exportToExcel():void
{
var featureCollection:ArrayCollection = myFeatureLayer.graphicProvider as ArrayCollection;
var exportSet:Array = [];
for each (var graphic:Graphic in featureCollection){
if (myMap.extent.intersects(graphic.geometry))
{
exportSet.push(graphic.attributes);
}
}
exportData = new ArrayCollection(exportSet);
sheet = new Sheet();
var dataProviderCollection:ArrayCollection = ssoDataGrid.dataProvider as ArrayCollection;
var rowCount:int = dataProviderCollection.length;
sheet.resize(rowCount + 1,ssoDataGrid.columnCount);
var columns:Array = ssoDataGrid.columns as Array;
columns.splice(8,1);
var i:int = 0;
for each(var fldName:String in myFeatureLayer.outFields){
fields.push(fldName);
for each (var field:DataGridColumn in columns){
if(field.dataField.toString() == fldName){
sheet.setCell(0,i,field.headerText.toString());
i++;
break;
}
}
}
for(var r:int=0; r < rowCount; r++)
{
var record:Object = dataProviderCollection.getItemAt(r);
/*insert record starting from row 2 else
headers will be overwritten*/
insertRecordInSheet(r+1,sheet,record);
}
//Create headers array to overwrite in correct format
var headers:Array = ["Address","Neighborhood","Start Date","End Date","Start Time","End Time","Spill Volume (Gal)","Cause","Corrective Action"];
//Loop to set headers on Xls sheet
for (var h:int=0; h<9; h++)
{
sheet.setCell(0,h,headers);
}
//Excel export code
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes: ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference();
fr.save(bytes,"SSO_Export.xls");
}
private function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void
{
var colCount:int = ssoDataGrid.columnCount;
for(var c:int; c < colCount; c++)
{
var i:int = 0;
for each(var field:String in fields){
for each (var value:String in record){
if (record[field].toString() == value)
sheet.setCell(row,i,value);
}
i++;
}
}
} //Create function to export attribute data to excel
private function exportToExcel():void
{
var featureCollection:ArrayCollection = myFeatureLayer.graphicProvider as ArrayCollection;
var exportSet:Array = [];
for each (var graphic:Graphic in featureCollection){
if (myMap.extent.intersects(graphic.geometry))
{
exportSet.push(graphic.attributes);
}
}
exportData = new ArrayCollection(exportSet);
sheet = new Sheet();
var dataProviderCollection:ArrayCollection = ssoDataGrid.dataProvider as ArrayCollection;
var rowCount:int = dataProviderCollection.length;
sheet.resize(rowCount + 1,ssoDataGrid.columnCount - 1);
var columns:Array = ssoDataGrid.columns as Array;
columns.splice(8,1);
var i:int = 0;
for each(var fldName:String in myFeatureLayer.outFields){
fields.push(fldName);
}
for(var r:int=0; r < rowCount; r++)
{
var record:Object = dataProviderCollection.getItemAt(r);
/*insert record starting from row 2 else
headers will be overwritten*/
insertRecordInSheet(r+1,sheet,record);
}
//Create headers array to match Attribute Table
var headers:Array = ["Address","Neighborhood","Start Date","End Date","Start Time","End Time","Spill Volume (Gal)","Cause","Corrective Action"];
//Loop to set headers on Xls sheet
for (var h:int=0; h<9; h++)
{
sheet.setCell(0,h,headers);
}
//Excel export code
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes: ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference();
fr.save(bytes,"SSO_Export.xls");
}
//Function to call for inserting records into Xls sheet
private function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void
{
var colCount:int = ssoDataGrid.columnCount - 1;
for(var c:int; c < colCount; c++)
{
var i:int = 0;
for each(var field:String in fields){
for each (var value:String in record){
if (record[field].toString() == value)
sheet.setCell(row,i,value);
}
i++;
}
}
} for each (var value:String in record){ var rvalue:String = (record[field] != null) ? String(record[field]) : ""; if (rvalue == value) { sheet.setCell(row,i,value); } }