This is a migrated thread and some comments may be shown as answers.

Best practice to export to excel

6 Answers 128 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 21 Nov 2009, 01:50 PM
Hi,
I got problems with the extra spaces that is generated when exporting to excel.
I have read your guidlines when exporting to excel but I can't get it right.
As you see in the print screen of VS, my textboxes are perfect aligned but still it generates "a lot" of empty rows! :(

What should I do?
(using 2009 Q3 3.2.9.1113)


/Mattias

6 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 23 Nov 2009, 05:30 PM
Hello Mattias,

The problem you are facing is due to the fact that you are using separate Textbox items to make the table layout. As single items do not depend on each other, the reporting tool cannot 'realize' that if one Textbox item grows, then the rest should grow as well so that there is only one row . For this purpose you have to use the Table report item through which you define the exact layout you are after. Hope this helps.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mattias
Top achievements
Rank 1
answered on 24 Nov 2009, 10:02 AM
Thank you Steve, that helped very much! :)

Another question:
Previously I set some values code behind in detail_itemdatabound event like this:
       private void detail_ItemDataBound(object sender, System.EventArgs e) 
        { 
            Telerik.Reporting.Processing.DetailSection detail = (Telerik.Reporting.Processing.DetailSection)sender; 
            Telerik.Reporting.Processing.IDataObject row = detail.DataObject; 
            Improvement improvement = (Improvement)row.RawData; 
 
            Telerik.Reporting.Processing.TextBox textBoxUnit = (detail.Items["textBoxUnit"as Telerik.Reporting.Processing.TextBox); 
            Telerik.Reporting.Processing.TextBox textBoxStatus = (detail.Items["textBoxStatus"as Telerik.Reporting.Processing.TextBox); 
 
            textBoxUnit.Value = UnitService.GetParentUnits(improvement.Unit.ID) + improvement.Unit.Name; 
            string statusColor = ImprovementService.GetImprovementStatusColor(improvement.Status); 
            textBoxStatus.Style.BackgroundColor = Color.FromName(statusColor); 
            
        } 

How can I move this code to the new layout of using table?
I saw that a table has an itemdatabound event as well but I cant figure out how to grab the DataObject from the datasource like I do above with the detailsection.

Can you help me out on this one?

Regards,
Mattias


0
Steve
Telerik team
answered on 24 Nov 2009, 05:00 PM
Hi Mattias,

The Table item is a separate data region, so it is bound separately and does not depend on the report's datasource. Similarly to the report, it has a NeedDataSource event, which would be fired if it has no datasource set and you can bind the table there to your desired objects.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mattias
Top achievements
Rank 1
answered on 26 Nov 2009, 09:47 PM
Hi Steve,

Previously I was binding to the reports needdatasource event and made some modifikations in the detailsections itemdatabound event (my example).

Now, I have moved everything to a table and I am binding the table in the tables needdatasource.
But I need to grab one specific item in my IList<T> and for that the tables itemdatabound event should be the place to do it. Right?
Something like this is what I am after:
private void table1_ItemDataBound(object sender, System.EventArgs e)  
{  
            Telerik.Reporting.Processing.TableRow tableRow = (Telerik.Reporting.Processing.TableRow)sender;  
            Telerik.Reporting.Processing.IDataObject dataRow = tableRow.DataObject;  
            Improvement improvement = (Improvement)dataRow.RawData;  
  
            Telerik.Reporting.Processing.TextBox textBoxUnit = (tableRow.Items["textBoxUnit"as Telerik.Reporting.Processing.TextBox);  
            Telerik.Reporting.Processing.TextBox textBoxStatus = (tableRow.Items["textBoxStatus"as Telerik.Reporting.Processing.TextBox);  
  
            textBoxUnit.Value = UnitService.GetParentUnits(improvement.Unit.ID) + improvement.Unit.Name;  
            string statusColor = ImprovementService.GetImprovementStatusColor(improvement.Status);  
            textBoxStatus.Style.BackgroundColor = Color.FromName(statusColor);  
             
}  

Problem 1 with this code is that: the sender is not a TableRow
Problem 2: If it was a TableRow, it has no DataObject.RawData

/Mattias

0
Accepted
Steve
Telerik team
answered on 27 Nov 2009, 01:11 PM
Hello Mattias,

The Table report item is not a mere grid of cells and has a very complex internal structure. The Report Designer does a great deal of work to simplify common tasks, but the underlying table code is far from trivial to work with programatically.
Anyway there are several ways to approach this such as:
  • custom user function that would return the data from your methods. You can reference UserFunctions directly in the TextBox expressions like so: "=MyCustomUserFunction(fields_as_args_here_if_any)"
  • TextBox_ItemDataBound - this event would be fired when the table item has already been databound and you can access the DataObject/RawData i.e.:

    private void textBoxUnit_ItemDataBound(object sender, EventArgs e)
            {
                Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)sender;
                object myItem = txt.DataObject["Item"];
                txt.Value = myItem;
            }
  • Table_ItemDataBound - it is possible to locate the items here as well, but as you know for each definition item, would be created several processing items which are the report definition merged with the data from the data source. So the Find method would return an array of objects which you would have to cycle in order to apply value. Thus, we recommend using "parent" events only in cases whenever the value you would set to a child item depends on the value of another databound child item, otherwise it only complicates the code.

Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mattias
Top achievements
Rank 1
answered on 28 Nov 2009, 03:22 PM
Thanks Steve for the examples of different approaches!
I'll go with the textbox's itemdatabound event.

/Mattias
Tags
General Discussions
Asked by
Mattias
Top achievements
Rank 1
Answers by
Steve
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or