Hello,
When I use the Silverlight 'Export to Excel' funcitonality, I am able to export the basic data
But, when I format that data (such as using Group By functionality) and then export, my excel worksheet contains no data, only the Column headers.
Is this a known issue or am I doing something incorrectly?
Thank you, --Chris
Stefana,
I have take the code directly from the C# tab on the Infragistics Silverlight Sample Browser at: http://labs.infragistics.com/silverlight/lobsamples/2009.2/
The only differnce is that my code references my Infragistics datagrid with it's Group By functionality turned on
<
igGrid:XamWebGrid.GroupBySettings>
private void TestExcel_Click(object sender, RoutedEventArgs e) {
Workbook dataWorkbook = new Workbook(); Worksheet sheetOne = dataWorkbook.Worksheets.Add("Data Sheet");
//Freeze header row sheetOne.DisplayOptions.PanesAreFrozen = true; sheetOne.DisplayOptions.FrozenPaneSettings.FrozenRows = 1;
// Build Column List sheetOne.DefaultColumnWidth = 5000; sheetOne.Columns[1].Width = 8500; sheetOne.Columns[3].Width = 10000; int currentColumn = 0; foreach (Column column in this.dataGrid.Columns) { if (column.Visibility == Visibility.Visible) { this.SetCellValue(sheetOne.Rows[0].Cells[currentColumn], column.HeaderText); currentColumn++; } }
// Export Data From Grid int currentRow = 1; foreach (Row row in this.dataGrid.Rows) { int currentCell = 0; foreach (Cell cell in row.Cells) { if (cell.Column.Visibility == Visibility.Visible) { this.SetCellValue(sheetOne.Rows[currentRow].Cells[currentCell], cell.Value); currentCell++; } } currentRow++; }
this.SaveExport(dataWorkbook); }
private void SetCellValue(WorksheetCell cell, object value) { cell.Value = value; cell.CellFormat.ShrinkToFit = ExcelDefaultableBoolean.True; cell.CellFormat.VerticalAlignment = VerticalCellAlignment.Center; cell.CellFormat.Alignment = HorizontalCellAlignment.Center; }
private void SaveExport(Workbook dataWorkbook) { SaveFileDialog dialog = new SaveFileDialog { Filter = "Excel files|*.xls", DefaultExt = "xls" };
bool? showDialog = dialog.ShowDialog(); if (showDialog == true) { using (Stream exportStream = dialog.OpenFile()) { dataWorkbook.Save(exportStream); exportStream.Close(); }
} }
Hi Chris,
Unfortunately what you are trying to do (using Grid GroupBy and then export to Excel) is not currently supported.
We will have this in mind and include this fuature in the following Releases.
Stefana
I am attaching a simple application, showing how you can partly workaround the issue with ExcelExporter and Grid GroupBy.
If you have any questions, do not hesitate to ask me.
Hello Chris,
Your solution work perfect. But
What do we have to do in order to extract the header column with group???
Thanks.
Gilles P.