Hi
I'm facing a problem that I have to export the data from two ultra web grids to one single excel sheet in a workbook.
can anybody help me in solving this.
Regards.
There are a bunch of overrides on the Export method. The one you'll want to use in particular is Export(grid, worksheet, startrow, startcolumn)
In order to use this method, you'll want to create a new workbook, which can be done by leveraging the Infragistics.Excel library.
Hope this helps,
-Tony
If you take a look at the samples included with NetAdvantage, you'll see under WebGrid -> Spreadsheet support there's a sample that exports 2 grids into two separate worksheets in a single excel file. This should be a good place for you to get started.
Here's the important code -
protected void ExportToExcel(object sender, EventArgs e) { Infragistics.Excel.Workbook workbook = new Infragistics.Excel.Workbook(); workbook.Worksheets.Add("Sheet1"); workbook.Worksheets.Add("Sheet2"); this.CopyPasteGrid1.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.No; this.UltraWebGridExcelExporter1.Export(this.CopyPasteGrid1, workbook); for (int i = 0; i < this.CopyPasteGrid1.Columns.Count; i++) { workbook.Worksheets[0].Columns[i].Width = 2000; } this.CopyPasteGrid2.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.No; workbook.ActiveWorksheet = workbook.Worksheets[1]; this.UltraWebGridExcelExporter1.Export(this.CopyPasteGrid2, workbook); for (int i = 0; i < this.CopyPasteGrid2.Columns.Count; i++) { workbook.Worksheets[1].Columns[i].Width = 2000; } workbook.ActiveWorksheet = workbook.Worksheets[0]; }
Tony
Exactly my scenario is the same what you are describing.
The same was done by me and I found the data getting erased everytime of new export.
whereas I'm not able to get the property "ActiveWorksheet".
workbook.ActiveWorksheet = workbook.Worksheets[0];
I'm using the version 8.
Any how I got a solution : merging two grids into one grid and exporting that grid.
Thanks for your continuous reply Tony.
regards.
Ceenu,
Infragistics.Excel.Workbook workbook = new Infragistics.Excel.Workbook();
workbook.Worksheets.Add("Sheet1");
this.UltraWebGridExcelExporter1.Export(this.UltraWebGrid1, workbook);
The code above produces an Excel document with the grid data exported two times (I had 10 rows in my grid).
I see notes about a bug BR09194 which may be related to the issue you're describing, but it was fixed approximately 3 years ago in the following versions:
6.1.20061.26 CLR 1.x / 2.0, 5.3.20053.1079 CLR 1.x / 2.0, 5.2.20052.1063, 5.1.20051.1092
I'm doing the same.
but grid one is getting exported. then I'm setting the row & column numbers.
and exporting the second grid. resulting is the second grid only can be visible where other is getting erased.
you just please go through the following.
The Export method is overloaded, with one of the overloads allowing you to specify the workbook and the start row/end row. You can use the code snippet above, but for the second Export, rather than adding a new Worksheet and changing the ActiveWorksheet, simply use the overloaded Export method where you supply the start row and column for the export.