OK.. I give up.. I can get a basic export working, but I'd like to add a few rows before the export to show Client Name, Job, Address, etc.. 2 hours now and I have nothing working! I've checked the on line examples and they are, to be nice, pathetic...
I assume this is handled on the _BeginExport Method.. Where from there. anything I try using the BeginExportEventAgrs parameter get me nothing...
Also, my formatting of Int columns in my grid is correct (comma where applicible), but these formats DO NOT come over to Excel. Do I have to reformat all my cells?
I like your stuff, but you frustrate the hell out of me..
Thanks...
Hi,
mgnatowski said: OK.. I give up.. I can get a basic export working, but I'd like to add a few rows before the export to show Client Name, Job, Address, etc.. 2 hours now and I have nothing working! I've checked the on line examples and they are, to be nice, pathetic... I assume this is handled on the _BeginExport Method.. Where from there. anything I try using the BeginExportEventAgrs parameter get me nothing...
The BeginExport event (and almost all of the events of the UltraGridExcelExporter) gives you a CurrentRowIndex and CurrentColumnIndex, as well as the CurrentWorksheet.
So if you want to add a line or two at the top before the grid exports, there's nothing to it. What you do is use the CurrentWorksheet and set the values on the cells. So let's say I wanted to add a line to the top of my worksheet where the first three cells say "A", "B", and "C". I would do this:
private void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e) { e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].Value = "A"; e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex + 1].Value = "B"; e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex + 2].Value = "C"; e.CurrentRowIndex++; }
Notice that I increment the CurrentRowIndex. This way, the grid starts exporting on the next row. If you add two rows, just add 2 to the CurrentRowIndex.
mgnatowski said:Also, my formatting of Int columns in my grid is correct (comma where applicible), but these formats DO NOT come over to Excel. Do I have to reformat all my cells?
DotNet Formats and Excel formats are not the same. So the grid can't just take the Format property of your column and translate it into Excel for you. What you have to do is handle the InitializeColumn event. The event gives you the format applied to the grid column and you just set the format on the excel column (on the event args).
Depending on the format, you can often just do this:
private void ultraGridExcelExporter1_InitializeColumn(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.InitializeColumnEventArgs e) { e.ExcelFormatStr = e.FrameworkFormatStr; }
HI,
I tried adding a header text to the Excel in BeginExport method. But in HeaderRowExporting event, the rowindex becomes 0 and it is overriding the row i added. The same proble in RowExporting event. do i hav to give e.CurrentRowIndex++ in each event??
Did you use exactly the same code I did?
In exactly the same event?
Are you sure you incremented the CurrentRowIndex?
My code works fine for me when I used it. So if it's not working for you, then something else is wrong in your code. Maybe you are changing the CurrentRowIndex again in some later event?
i did this. i have added this code in al events. but the grouped header is overriding the first row. i do know how to stop this from happening..
Using BeginExport, adding some rows into the Excel Worksheet before the grid exports should be pretty simple.
private void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e) { // Get the current row. WorksheetRow worksheetRow = e.CurrentWorksheet.Rows[e.CurrentRowIndex]; // Write some text into the first two cells of the row. worksheetRow.Cells[e.CurrentColumnIndex].Value = "0, 0"; worksheetRow.Cells[e.CurrentColumnIndex + 1].Value = "1, 0"; // Incrememet the current row index so that the grid export begins after the // text we added above. e.CurrentRowIndex++; }
i have given it in both BeginExport and RowExporting. But still it is not working. is there any event for grouping.?any other option?
The HeaderRowExporting will event will not help you here, because the first row is a GroupByRow, not a Header. Header refers to column or group (not OutlookGroupBy) headers.
HeaderRowExporting will not be fired before the GroupByRow exports.
You need to do this in the BeginExport or maybe the BeforeRowExported event.