Hi
I have an UltraGrid with 2 bands. Band 0 contains the summary information of an object and band 1 contains the details infromation of the same object in band 0.
When I export the grid I concatenate band 1 data after band 0. I have achived that however that left a few blank rows between each rows after move band 1 data to band 0. I am wondering how I can remove those blank rows. I don't mind doing that either during exporting the grid or after exporting.
Any advice will be much appreciated!
Thanks
Lan
Hi Lan,
I'm afraid I don't really understand what you are doing. How exactly are you concatenated Band 1 data onto band 0? Where are these empty rows showing up?
Hi Mike
what I am trying to do is below:-
grid display:
band0 header -> Header 1 Header 2 Header 3
band0 data -> data 1 data2 data3
band 1 header Header A Header B Header C
band 1 data data a data b data c
after experting to excel it looks like below
band0 header -> Header 1 Header 2 Header 3 Header A Header B Header C
band0 data -> data 1 data2 data3 data a data b data c
blank row left from moving band 1 headers
blank row left from moving band 1 data
I am trying to get rid of the blank rows left after moving the band 1 data over to band 0 level. I am trying to find a way to remove the blank rows from the spreadsheet using C#. Hope I have made it clearer for you.
So... you only have one child row for each parent row?
How are you changing the export so that it comes out this way in Excel?
There are a couple of ways you could acheive what you want.
One way would be to create a new grid and a new UltraDataSource with a single band and then copy the data into the UltraDataSource which is bound to the new grid. Then you could export this new grid so it would all be one band.
Another option would be to try to handle this using the events of the UltraGridExcelExporter. Events like RowExporting/RowExported and HeaderExporting/HeaderExported all have proeprties on the event args for CurrentRowIndex and CurrentColumnIndex. So you could change these numbers so that the export occurs at a particular place within the excel document. It might be a bit tricky to work out the numbers. I guess you would have to store the row and column index of the last header and the last cell that was exported in the parent row and then use those numbers to place the child row to the right of it.
Yes I have only 1 child row per parent. I have tried to below:
UltraGrid grid = new UltraGrid();
grid.DataSource = data <--single band data
Then pass the grid to UltraGridExcelExporter. However no data got exported. I think by creating an UltraGrid on the fly does not do the job as the grid is not visible.
I have managed to move the cells by using events HeaderExporting and CellExporting( please see code sample below). But after moving the cells I have blank lines left by band 1 data. I cannot figure out a way to remove them. Is there any library in infragistics or .Net would allow me to open up the spreadsheet and remove the blank liines in one go?
Many thanks
private
void excelExporter_CellExporting(object sender, CellExportingEventArgs e)
{
//moving the cell value in band[1] to the same level as band[0]
e.CurrentWorksheet.Rows[e.CurrentRowIndex - RowShiftOnExcelExport].Cells[e.CurrentColumnIndex + ColumnShiftOnExcelExport].Value = e.Value;
//setting the format of the cell to which it has moved to the same format cell before it.
e.CurrentWorksheet.Rows[e.CurrentRowIndex - RowShiftOnExcelExport].Cells[e.CurrentColumnIndex + ColumnShiftOnExcelExport].CellFormat.SetFormatting(
e.CurrentWorksheet.Rows[e.CurrentRowIndex - RowShiftOnExcelExport].Cells[e.CurrentColumnIndex + ColumnShiftOnExcelExport - 1].CellFormat);
e.Cancel =
true;
}
cnlxlw said:Then pass the grid to UltraGridExcelExporter. However no data got exported. I think by creating an UltraGrid on the fly does not do the job as the grid is not visible.
You probably need to add the grid to the form's Controls collection so that it has a BindingContext. Or, you could just set the grid's BindingContext to the form's BindingContext.
cnlxlw said:I have managed to move the cells by using events HeaderExporting and CellExporting( please see code sample below). But after moving the cells I have blank lines left by band 1 data. I cannot figure out a way to remove them. Is there any library in infragistics or .Net would allow me to open up the spreadsheet and remove the blank liines in one go?
There's no way to remove lines. You would have to stop those lines from being created in the first place. You should be able to do this by setting the CurrentRowIndex inside the event of the UltraGridExcelExporter.
hi,
I am facing the same problem .
I have a parent grid having data as
Parent header : Header1 Header2 Header3
Parent data : HData1 HData2 HData 3
Child Header : Childheader1 Childheader2
Child data : data1 data2
data11 data22
I want to display it in excel sheet as :
Header1 Header2 Header3 Childheader1 Childheader2
HData1 HData2 HData3 data1 data2
Can you please give a sample code having the same scenario , as i am unable to fulfill this .
The headers of the Parent grid are getting repeated every time the data of the child grid is displayed along with blank rows.
Please help me in this .
Thanks in advance.
Seema Sharma
I think you will need a new DataView for the export then re-assign the original DataSet as DataSource after the export. If you wrap the Export process inside BeginUpdate() and EndUpdate() then the user will not see that you are replacing the UltraGrid's Datasource.