Hi !
What does the excelExport actuqally export ? the datasource of the grid or the content of the displayed grid ?
Why the following code does not work ? - it generates an empty file -
UltraGrid ugl = new UltraGrid(); ugl.SetDataBinding(ds, "reportDataset"); UltraGridExcelExporter exel = new UltraGridExcelExporter(); exel.Export(ugl,"E:\\excel.xls"); ugl.Dispose(); exel.Dispose();
UltraGrid ugl = new UltraGrid();
ugl.SetDataBinding(ds, "reportDataset");
UltraGridExcelExporter exel = new UltraGridExcelExporter();
exel.Export(ugl,"E:\\excel.xls");
ugl.Dispose();
exel.Dispose();
The exported Excel file is created based on the grid, not the data source. It's WYSIWYG - the Excel file will pick up the appearances and layout of the grid, as much as possible.
The code you have here probably doesn't work because DataBinding in DotNet requires a BindingContext and since you are creating your grid in code and you never add it to a container of any kind, it has no context.
I think if you check, you will find that your grid has no rows in it, even if your data source does. To fix this, just set the BindingContext on the grid to a new BindingContext or to the BindingContext of the form (assuming you have a form). Do this before you set the grid's DataSource.
Thanks!
I don't have an actual grid. I was thinking that maybe I could use UltraExcelExporter to export a dataset, by loading it into a ultragrid created at runtime.
Yes, you could do that. You just have to make sure that when you create your Grid in code that you assign it a BindingContext. Otherwise, it will not be able to generate any data from the DataSource. The easiest thing to do is set the grid's BindingContext to the BindingContext of the form (if you are using a form) or just a new BindingContext before you set it's DataSource.