Hi,
I have few clarifications related to Infragistics.Documents.Excel component.
1)How can we insert blank rows in excel using Infragistics2)How can we use Group by clause i.e. how to do group by functionality for given rows ex: i have to apply group by to rows from 2 to 9 some thing like this3)How can i apply conditonal formatting for a specified range
Please help me in these concepts.Thanks in Advance.
You can group consecutive rows and columns by setting their OutlineLevels to the same number. As for the other features, they are currently not supported. You can submit feature requests for these.
Thanks for quick replay.
Can you please provide an examle for grouping.And for others untill feature is available is there any alternative which can be done?
Thanks
You can do something like this to group rows:
Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets.Add("Sheet1"); // Group rows 5 thru 10 for (int i = 4; i < 10; i++) worksheet.Rows[i].OutlineLevel = 1; // Make a sub-group of rows 7 and 8 worksheet.Rows[6].OutlineLevel = 2; worksheet.Rows[7].OutlineLevel = 2; workbook.Save("Book1.xls");
To insert a blank row, I think the only way to do it right now would be to look at the populated rows in reverse and move their data one row down until you hit the row that needed to be inserted. You would also need to fix up any formulas that were referencing cells or regions in the rows which were shifted down.
There is currently no way to use conditional formatting that I can think of.
Sorry i dint get the logic for inserting rows could please give an example like grouping rows which you gave.
It is not easy to do. I will give you code for copying the rows in reverse, but updating formulas which referenced moved cells is a very advanced task and I can't provide code here that would cover all cases:
Workbook workbook = Workbook.Load("Source.xls"); Worksheet worksheet = workbook.Worksheets[0]; IWorksheetCellFormat blankFormat = workbook.CreateNewWorksheetCellFormat(); // Insert a blank row at row 3 const int InsertionIndex = 2; // Gather up the rows to move down in reverse order Stack<WorksheetRow> rowsToShiftDown = new Stack<WorksheetRow>(); foreach (WorksheetRow row in worksheet.Rows) { if (row.Index < InsertionIndex) continue; rowsToShiftDown.Push(row); } // Moved the rows down while (rowsToShiftDown.Count != 0) { WorksheetRow sourceRow = rowsToShiftDown.Pop(); WorksheetRow destinationRow = worksheet.Rows[sourceRow.Index + 1]; // Copy the row formatting to the row below destinationRow.CellFormat.SetFormatting(sourceRow.CellFormat); foreach (WorksheetCell sourceCell in sourceRow.Cells) { WorksheetCell destinationCell = destinationRow.Cells[sourceCell.ColumnIndex]; // Move the value to the cell below destinationCell.Value = sourceCell.Value; sourceCell.Value = null; // Move the cell format to the cell below destinationCell.CellFormat.SetFormatting(sourceCell.CellFormat); sourceCell.CellFormat.SetFormatting(blankFormat); } // Clear out the row formatting on the source row sourceRow.CellFormat.SetFormatting(blankFormat); } workbook.Save("Book1.xls");