Click here to Skip to main content
14,735,210 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

i'm getting a error like this Error #2101. So what does it mean.
I have written a code like mentioned below.

<mx:Button id="expToExlOpenTkt"
                            icon="@Embed('assets/excel.gif')"
                            fillAlphas="[1.0, 1.0]" 
                            fillColors="[#E2E2E2, #E2E2E2]"
                        click="DataGridExporter.callExportADGToCSV(adg,'OpenTickets')"
                        toolTip="Export Data" width="28"/>



So please help me in this.........

*******************************************************************************************************

/**
	_________________________________________________________________________________________________________________

	DataGridExporter is a util-class to export DataGrid's data into different format.	
	@class DataGridExporter (public)
	@author Manoranjan Singh 
	__________________________________________________________________________________________________________________

*/
package com.scottlogic.charts
{
	
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	
	import mx.collections.IViewCursor;
	import mx.controls.AdvancedDataGrid;
	import mx.controls.Alert;
	import mx.controls.DataGrid;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
	import mx.controls.dataGridClasses.DataGridColumn;
	
	public class DataGridExporter
	{

		public static function exportCSV(dg:DataGrid, csvSeparator:String="\t", lineSeparator:String="\n"):String
		{
			var data:String = "";
			var columns:Array = dg.columns;
			var columnCount:int = columns.length;
			var column:DataGridColumn;
			var header:String = "";
			var headerGenerated:Boolean = false;
			var dataProvider:Object = dg.dataProvider;
			var rowCount:int = dataProvider.length;
			var dp:Object = null;

			var cursor:IViewCursor = dataProvider.createCursor ();
			var j:int = 0;
			//loop through rows
			while (!cursor.afterLast)
			{
				var obj:Object = null;
				obj = cursor.current;
				
				//loop through all columns for the row
				for(var k:int = 0; k < columnCount; k++)
				{
					column = columns[k];

					//Exclude column data which is invisible (hidden)
					if(!column.visible)
					{
						continue;
					}
					
					data += "\""+ column.itemToLabel(obj)+ "\"";

					if(k < (columnCount -1))
					{
						data += csvSeparator;
					}
					//generate header of CSV, only if it's not genereted yet
					if (!headerGenerated)
					{
						header += "\"" + column.headerText + "\"";
						if (k < columnCount - 1)
						{
							header += csvSeparator;
						}
					}			
				}
				
				headerGenerated = true;

				if (j < (rowCount - 1))
				{
					data += lineSeparator;
				}

				j++;
				cursor.moveNext ();
			}
			
			//set references to null:
			dataProvider = null;
			columns = null;
			column = null;
		
			return (header + "\r\n" + data);
			
		}	
		public static function exportADGToCSV(dg:AdvancedDataGrid, csvSeparator:String="\t", lineSeparator:String="\n"):String
		{
			
			var data:String = "";
			var header:String = "";
			try{
			var columns:Array = dg.columns;
			var columnCount:int = columns.length;
			var column:AdvancedDataGridColumn;
			var headerGenerated:Boolean = false;
			var dataProvider:Object = dg.dataProvider;
			var rowCount:int = dataProvider.length;
			var dp:Object = null;

			var cursor:IViewCursor = dataProvider.createCursor();
			var j:int = 0;
			//loop through rows
			while (!cursor.afterLast)
			{
				var obj:Object = null;
				obj = cursor.current;
				
				//loop through all columns for the row
				for(var k:int = 0; k < columnCount; k++)
				{
					column = columns[k];

					//Exclude column data which is invisible (hidden)
					if(!column.visible)
					{
						continue;
					}
					
					data += "\""+ column.itemToLabel(obj)+ "\"";

					if(k < (columnCount -1))
					{
						data += csvSeparator;
					}
					//generate header of CSV, only if it's not genereted yet
					if (!headerGenerated)
					{
						header += "\"" + column.headerText + "\"";
						if (k < columnCount - 1)
						{
							header += csvSeparator;
						}
					}			
				}
				
				headerGenerated = true;

				if (j < (rowCount - 1))
				{
					data += lineSeparator;
				}

				j++;
				cursor.moveNext ();
			}
			
			//set references to null:
			dataProvider = null;
			columns = null;
			column = null;
		
			}catch(error:Error){
				Alert.show("error in exportADGToCSV..."+error.message.toString());
			}
			return (header + "\r\n" + data);
			
		}
		private static const EXPORT_CSV_URL:String = "ExportToExcelServlet";
		private static var downloadFileRef:FileReference = null;
		
		public static function callExportCSV(dataGridFromFlex:DataGrid):void
		{
			var csvData:String = exportCSV(dataGridFromFlex,"\t","\n");
			var console:String = csvData;
			if (csvData.length > 0)
			{
				downloadCSV (csvData);
			}
		}
		
		public static function callExportADGToCSV(dataGridFromFlex:AdvancedDataGrid,fileLabelName:String):void
		{
			var csvData:String = exportADGToCSV(dataGridFromFlex,"\t","\n");
			var console:String = csvData;
			if (csvData.length > 0)
			{
				downloadAdgCSV(csvData,fileLabelName);
			}
		}
		
		public static function downloadCSV(csvData:String):void
		{
			if (downloadFileRef == null)
			{
				downloadFileRef = new FileReference();
			}
			var request:URLRequest = new URLRequest();
			request.url = EXPORT_CSV_URL;
			request.method = URLRequestMethod.POST;
			request.data = new URLVariables("csvdata=" + csvData);
			downloadFileRef.download(request,"Report.xls");
		} 
		
		public static function downloadAdgCSV(csvData:String,fileLabelName:String):void
		{
			if (downloadFileRef == null)
			{
				downloadFileRef = new FileReference();
			}
			try{
				var currentDateAndTime:Date = new Date(); 
				var request:URLRequest = new URLRequest();
				request.url = EXPORT_CSV_URL;
				request.method = URLRequestMethod.POST;
				request.data = new URLVariables("csvdata=" + csvData);
				downloadFileRef.download(request,fileLabelName+".xls");
			}catch(error:Error){
				Alert.show("error in downloadCSV...."+error.message);
			}
		} 
	}
}




So please help me......

Above i have shared code for downloading a file to xls file.
Posted
Updated 14-Feb-12 0:27am
v2
Comments
rohitVasu 15-Feb-12 2:34am
   
Please help me how to fix this issue

1 solution

Have you even tried finding this out yourself, don't want to be mean but try this

1) Go to www.google.com or www.bing.com
2) type in "flex Error #2101" and press return

it would have taken you less time than copy/pasting your code into the question you created

and they say people can't write software anymore....

regards,
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900