Hi,
I discovered an export to Excel is failing in a specific case when using a multiband grid. It's too specific to explain, but my attached sample project demonstrates the problem.
If you run my program and export the grid data to Excel, the rows containing 'Item 1.1.2' and below are placed two cells too far to the right (they should start in column A).
I know the layout is doing unusual things like adding dummy columns in the first band and hiding the column headers of the other bands, but this creates the visual result the product owner requires.
I ran your sample and I see what you are describing. But the behavior you seem to expect is not correct.
The child rows are supposed to be intended.
There appears to be a bug here, but the bug is that the "Category 1.1" and "Item 1.1.1" are NOT being indented properly. This seems to be caused by the hiding of the column headers for those bands.
Now for the good news. This bug was fixed a long time ago. I tested your sample with v11.2 and it works fine.
But, that's probably small consolation, since the intended behavior is apparently not what you want, anyway. So, if you want to flatten the list so every row exports to the "A" column in Excel, you could achieve that in a couple of ways. Here's the workaround I'd use:
void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e) { foreach (UltraGridBand band in e.Layout.Bands) { band.Indentation = 0; } }
Thanks for the workaround!The product owner told me that indentation of the child bands would in fact be a better solution, but I don't see how the column headers match up with the data of those child bands in that case (we would need to upgrade to v11.2 first of course).
TorX said:The product owner told me that indentation of the child bands would in fact be a better solution, but I don't see how the column headers match up with the data of those child bands in that case (we would need to upgrade to v11.2 first of course).
Sorry... I don't understand what you mean. The workaround I posted here works in both versions and there is no problem with the column headers - especially since you aren't showing any except the ones on the root level.
Mike Saltzman said:you aren't showing any except the ones on the root level.
Yes, but (because of design choices) the column headers of the root level are used for the rows in the child bands as well. That's the reason the dummy columns were created, and the headers of the other bands were hidden.
UltraGrid reuses columns for child bands, but this is not how it is exported to Excel (after the fix, without the workaround). So the 'trick' we've applied to use the column headers of the root band, is not possible for exporting. But perhaps I can use the BeginExport event to show the column headers of the child bands again, so we can have indentation (in Excel!) and have the data in the right columns.
I'm still not following you at all. What "dummy columns" are you referring to? I don't see any in the sample you posted here.
I have no idea what you are talking about. The workaround I provided here produces exactly the same results in both versions - one set of column headers for the root-level rows and then no column headers on the child rows. And the columns all line up. So... what's the problem you are trying to solve?
Well, I did mention it in my first reply. :)
Thanks again!
TorX said:the product owner would like to see indentation in Excel after all
Ah, okay. That was the key piece I was missing.
Yes, you could just use the BeginExport event and set ColHeadersVisible to true on the export layout so that the column headers display in the export and not on the screen.
I mean the columns 'Description' and 'Score' I add to the root band in SetLayout. Those properties do not exist in Category, that's why I call them dummy columns.
First of all, as I mentioned the work around works great in v10.3. So we are going to use that for now. However, in hindsight the product owner would like to see indentation in Excel after all. So when we update Infragistics in the future, we can remove the workaround and have the correct indentation in Excel.
However, this will mean that the subcategory name will be in column B (= 'description' in the root band) and the item name will be in column C (= 'score' of the root band). Furthermore, the headers (in Excel row #1) 'description' and 'score' don't make sense anymore. But I think I can fix it by showing the column headers for the child bands (and removing those dummy columns), so each band gets their own column headers.
If you still don't understand it, then never mind... I will cross that bridge when I come to it.