Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
565
UltraGridExcelExporter
posted

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...

Parents
  • 469350
    Suggested Answer
    Offline posted

    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;
            }

Reply Children