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

RadGrid ExcelML Export - Add a property to WorkSheetOptions

4 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 11 Jul 2011, 11:37 PM
When exporting a Radgrid using ExcelML format, how can I set a property that is not defined in the WorkSheetOptionsElement?  For example, within the WorkSheetOptions XML, there can be a property named Zoom that allows you to set the Zoom of the Worksheet.  Can these be added using the InnerElements.Add Method and if so, how?

<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <VerticalResolution>0</VerticalResolution>
   </Print>
   <Zoom>75</Zoom>
   <Selected/>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>18</ActiveRow>
     <ActiveCol>4</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>

4 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 18 Jul 2011, 05:58 PM
Hello Chris,

Indeed, this is a good question. Here is a sample code that shows how to create a class that inherits from ElementBase and implements the desired functionality:

Create ZoomElement
public class ZoomElement : Telerik.Web.UI.GridExcelBuilder.Abstract.ElementBase
{
    int _zoomValue;
    public ZoomElement(int zoomValue)
    {
        _zoomValue = zoomValue;
    }
 
    protected override string EndTag
    {
        get { return "</Zoom>"; }
    }
 
    protected override string StartTag
    {
        get { return "<Zoom>" + _zoomValue.ToString(); }
    }
}

Instantiate the element and add it to the InnerElements collection:
protected void RadGrid1_ExcelMLWorkBookCreated(object sender, Telerik.Web.UI.GridExcelBuilder.GridExcelMLWorkBookCreatedEventArgs e)
{
    ZoomElement zoomElement = new ZoomElement(20);
    e.WorkBook.Worksheets[0].WorksheetOptions.InnerElements.Add(zoomElement);
}

I hope this helps.

Best regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Chris
Top achievements
Rank 1
answered on 18 Jul 2011, 06:50 PM
Daniel,

Creating a ZoomElement class was also how I solved the issue.  I was hoping the functionality was already built in to GridExcelBuilder.  Is there a plan to incorporate more settings in a future release?

Also, your example is missing an override for RenderChildElements which is required to insert the value between the tags.
public class ZoomElement : Telerik.Web.UI.GridExcelBuilder.Abstract.ElementBase
{
    private int _zoom;
 
    public ZoomElement(int value)
    {
        _zoom = value;
    }
    protected override string StartTag { get { return "<Zoom>"; } }
    protected override string EndTag { get { return "</Zoom>"; } }
    protected override void RenderChildElements(System.Text.StringBuilder sb)
    {
        base.RenderChildElements(sb);
        sb.Append(_zoom);
    }
}

Regards,

Chris
0
Daniel
Telerik team
answered on 18 Jul 2011, 08:39 PM
Hello Chris,

I confirm that we plan to add more features to the ExcelML code in future releases.
If you run my code-snippet you will notice that it all works correctly. I omitted the RenderChildElements method for simplicity purposes.

Regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Chris
Top achievements
Rank 1
answered on 18 Jul 2011, 09:08 PM
Daniel,

I overlooked your concatenation in the start tag. :)

Thanks for the info.

Regards,

Chris
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Chris
Top achievements
Rank 1
Share this question
or