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
Hi Amy,
Could you try one more time with the following code:
private
void Export_Button_Click(object sender, RoutedEventArgs e){
SaveFileDialog dialog = new SaveFileDialog { Filter = "Excel files|*.xls", DefaultExt = "xls" };bool? showDialog = dialog.ShowDialog();
if (showDialog == true){
using (Stream exportStream = dialog.OpenFile()){
Workbook workbook = new Workbook(WorkbookFormat.Excel97To2003);this.sheet = workbook.Worksheets.Add("Test Sheet");this.currentMergedRow = 0;this.currentMergedColumn = 0;this.PrepareExportToExcel();workbook.Save(exportStream);exportStream.Close();
}
Thanks,George
Hi George,
Problem solved, thanks!
Amy
I still get the same error when I increase the number of rows to say, 5000.
I was playing around with the sample posted here after I got stuck with my own code which is only exporting a small part of my datagrid - not the entire collection.
Could you check if the first line of your Click event handler is :
SaveFileDialog dialog = new SaveFileDialog { Filter = "Excel files|*.xls", DefaultExt = "xls" };bool?
Hi, I tried 1346.excexp.zip example and change line
for
(int i = 0; i < 9; i++) to
for(int i=0;i<4000;i++)
testing for large data. But it gives errorDialogs must be user-initiated.
at line
bool
? showDialog = dialog.ShowDialog();
Same isssue gets in my application
So please anybody give solution for that.
Thanks,
Nandu
Could you try with the project that is proposed as a solution for the following thread:
http://community.infragistics.com/forums/p/40720/227955.aspx#227955
I am also having the same problem in large rows.
And yes George, first line is exactly like yours.