I am trying to get certain rows to format as a percent while the default formatting is currency. We are using Infragistics NetAdvantage 2006 Volume 2 CLR 2.0 and .Net 2.0. Below is the code I have tried (including a commented out attempt.
protected void UltraWebGridExcelExporter1_EndExport(object sender, Infragistics.WebUI.UltraWebGrid.ExcelExport.EndExportEventArgs e){ for (int j = 1; j < 7; j++) e.CurrentWorksheet.Columns[j].CellFormat.FormatString = CurFormat;
//int rowCount = (e.CurrentWorksheet.Rows as ICollection<Infragistics.Excel.WorksheetRow>).Count; int rowCount = e.CurrentWorksheet.Rows[((ICollection<Infragistics.Excel.WorksheetRow>)e.CurrentWorksheet.Rows).Count - 1].Index + 1; string headerValue;
for (int j = 1; j < rowCount; j++) { headerValue = Convert.ToString( e.CurrentWorksheet.Rows[j].Cells[0].Value);
if (headerValue.Contains("%")) { for (int jj = 1; jj < 7; jj++) e.CurrentWorksheet.Rows[j].Cells[jj].CellFormat.FormatString = PerFormat; } }}
The error I last got is pasted below:
Error Message: Unable to cast object of type 'Infragistics.Excel.WorksheetRowCollection' to type 'System.Collections.Generic.ICollection`1[Infragistics.Excel.WorksheetRowCollection]'.
Any suggestions or help in finding out the solution would be greatly appreciated.
Ok, but that still leaves me where I started. The two versions of getting the row count (total number of rows) are not working. Any tips to get that working?
Also figured out how to check the version of the dll since that should give you more information. The dll is:
Infragistics2.Excel.v6.2.dll
Oh, I think you're right. I believe the collection did not implement ICollection<T> until version 7.2. Unfortunately, if you cannot upgrade to a later version, I don't think there is anything that can be done other than iterating all rows with a for loop.
That is what I was thinking it should be. I am still getting the error mentioned above though. Below is my version of the foreach (just do to namespace differences)
foreach (Infragistics.Excel.WorksheetRow r in e.CurrentWorksheet.Rows)
Here is the full error:
foreach statement cannot operate on variables of type 'Infragistics.Excel.WorksheetRowCollection' because 'Infragistics.Excel.WorksheetRowCollection' does not contain a public definition for 'GetEnumerator' ...
Thank you for trying to help me by the way. hopefully we can figure something out.
Try something like this:
foreach (WorksheetRow row in e.CurrentWorksheet.Rows){ // ...}