We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Found a problem in ExportdataTable - here ist the corrected version

/// /// Exports worksheet data into a DataTable /// /// /// Row of the first cell from where DataTable should be exported /// /// /// Column of the first cell from where DataTable should be exported /// /// Maximum number of rows to export /// Maximum number of columns to export /// DataTable with worksheet data public DataTable ExportDataTable( int firstRow, int firstColumn, int maxRows, int maxColumns ) { if( firstRow < 1 || firstRow > DEF_MAX_ROW_ONE_INDEX ) throw new ArgumentOutOfRangeException( "firstRow" ); if( firstColumn < 1 || firstColumn > DEF_MAX_COLUMN_ONE_INDEX ) throw new ArgumentOutOfRangeException( "firstColumn" ); DataTable result = new DataTable( this.Name ); // Declare DataColumn and DataRow variables. DataColumn dataColumn; DataRow dataRow; maxColumns = Math.Min( maxColumns, DEF_MAX_COLUMN_ONE_INDEX - firstColumn + 1 ); maxRows = Math.Min( maxRows - 1, DEF_MAX_ROW_ONE_INDEX - firstRow + 2 ); for( int i = 0; i < maxColumns; i++ ) { dataColumn = new DataColumn(); dataColumn.DataType = System.Type.GetType( "System.String" ); dataColumn.ColumnName = Range[ firstRow, firstColumn + i ].Text; result.Columns.Add( dataColumn ); // maxRows--; } firstRow++; for( int i = 0; i < maxRows; i++ ) { dataRow = result.NewRow(); for( int j = 0; j < maxColumns; j++ ) { dataRow[ j ] = Range[ firstRow + i, firstColumn + j ].Text; } result.Rows.Add( dataRow ); } return result; }

1 Reply

AD Administrator Syncfusion Team July 28, 2004 12:17 PM UTC

Hi Preier, Thanks for reporting this issue. We have already fixed the problem with the ExportDataTable method and have also added an overload for exporting any given range into a DataTable. All the changes will be included in the version 2.0.6.x. Thanks. Best regards, Stephen. > /// > /// Exports worksheet data into a DataTable > /// > /// > /// Row of the first cell from where DataTable should be exported > /// > /// > /// Column of the first cell from where DataTable should be exported > /// > /// Maximum number of rows to export > /// Maximum number of columns to export > /// DataTable with worksheet data > public DataTable ExportDataTable( int firstRow, int firstColumn, int maxRows, int maxColumns ) > { > if( firstRow < 1 || firstRow > DEF_MAX_ROW_ONE_INDEX ) > throw new ArgumentOutOfRangeException( "firstRow" ); > > if( firstColumn < 1 || firstColumn > DEF_MAX_COLUMN_ONE_INDEX ) > throw new ArgumentOutOfRangeException( "firstColumn" ); > > DataTable result = new DataTable( this.Name ); > > // Declare DataColumn and DataRow variables. > DataColumn dataColumn; > DataRow dataRow; > > maxColumns = Math.Min( maxColumns, DEF_MAX_COLUMN_ONE_INDEX - firstColumn + 1 ); > maxRows = Math.Min( maxRows - 1, DEF_MAX_ROW_ONE_INDEX - firstRow + 2 ); > > for( int i = 0; i < maxColumns; i++ ) > { > dataColumn = new DataColumn(); > dataColumn.DataType = System.Type.GetType( "System.String" ); > dataColumn.ColumnName = Range[ firstRow, firstColumn + i ].Text; > result.Columns.Add( dataColumn ); > // maxRows--; > } > > firstRow++; > > for( int i = 0; i < maxRows; i++ ) > { > dataRow = result.NewRow(); > > for( int j = 0; j < maxColumns; j++ ) > { > dataRow[ j ] = Range[ firstRow + i, firstColumn + j ].Text; > } > > result.Rows.Add( dataRow ); > } > > return result; > }

Loader.
Live Chat Icon For mobile
Up arrow icon