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
230
Excel Copy Paste Sample
posted

hello:

below is my sample for Excel Copy and paste. For some reason, I am unable to generate the Rows for the Sheets Dynamically, please could someone tell why?

 Thank you,

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="massGTINEditPortlet.ascx.cs" Inherits="dcdr.includes.controls.massGTINEditPortlet" %>

<%@ Register Src="~/includes/controls/clipboard.ascx" TagName="Clipboard" TagPrefix="uc1" %>

<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.ExcelExport.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"

Namespace="Infragistics.WebUI.UltraWebGrid.ExcelExport" TagPrefix="igtblexp" %>

<%@ Register Assembly="Infragistics35.WebUI.UltraWebNavigator.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"

Namespace="Infragistics.WebUI.UltraWebNavigator" TagPrefix="ignav" %>

<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"

Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>

<%@ Register Assembly="Infragistics35.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.LayoutControls" TagPrefix="ig" %>

<%@ Register Assembly="Infragistics35.WebUI.UltraWebTab.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.UltraWebTab" TagPrefix="igtab" %>

<%@ Register tagPrefix="igmisc" namespace="Infragistics.WebUI.Misc" assembly="Infragistics35.WebUI.Misc.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" %>

<script type="text/javascript">

function ShowContextMenu(evt){

//Firefox passes event arg as parameter (evt). If that is null, we'll use window.event (Internet Explorer proprietary)

var e=evt?evt:window.event;

 

//Call show menu with menuID

//specify clientX and clientY to get more accurate positioning for this particular layout

igmenu_showMenu("<%=this.CopyPasteMenu.ClientID %>",null,(e.clientX+document.documentElement.scrollLeft)+"px",(e.clientY+document.documentElement.scrollTop)+"px");

 

//Firefox (W3C) - cancel event

if(typeof(e.preventDefault)=="function")e.preventDefault();

//InternetExplorer (Proprietary) - cancel event

e.returnValue=false;

return false;

}

function GridClick(grid,src,button){

if(button!=2){

//Because the WebGrid consumes all mouse events, we need to add

//a listener to determine when a mouse click has occured so we can

//close the popup menu appropriately

igmenu_getMenuById("<%= this.CopyPasteMenu.ClientID %>").dismiss();

}

}

 

function ContextMenuItemClick(menuid,itemid)

{

//Grab a reference to the ContextMenuItem that was clicked on

var item=igmenu_getItemById(itemid);

var curGrid=null;

//We need to know which tab we're on, so we can figure out which

//grid we want to perform the copy/paste operation on.

//Notice we use the asp style tag to emit the ClientID of the tab.

//This makes our code more maintainable in the event that the tab

//id changes, the reference will be updated automatically.

var selTab=igtab_getTabById("<%= this.sheets.ClientID %>").getSelectedIndex();

curGrid=selTab==0?"<%=this.CopyPasteGrid1.ClientID %>":"<%=this.CopyPasteGrid2.ClientID %>";

curGrid=igtbl_getGridById(curGrid);

if(item!=null){

//We'll use the text from the menuitem to decide which operation to perform

switch(item.getText()){

case "Cut":

curGrid.cut();

break;

case "Copy":

curGrid.copy();

break;

case "Paste":

curGrid.paste();

break;

case "Export To Excel":

document.getElementById("ExportToExcelButton").click();

break;

}

}

}

</script>

<uc1:Clipboard ID="Clipboard1" runat="server" />

<table class="shade-white" cellspacing="0" cellpadding="0" width="100%" border="0">

<!-- B /// Title -->

<!-- There should be no reason to modify this section -->

<tr class="shade-purple-dark" valign="top">

<td><img height="11" alt=""

src="<%# RootURL %>/images/corners/top_l_666699.gif" width="11" border="0"

/></td>

<td class="skins-title-purple" valign="middle"><img

height="20" alt="" src="<%# RootURL %>/images/common/clear.gif" width="1"

align="absMiddle" border="0" />

<%# Title %>

</td>

<td align="right"><img height="11" alt=""

src="<%# RootURL %>/images/corners/top_r_666699.gif" width="11" border="0"

/></td>

</tr>

<!-- E /// Title -->

<!-- B /// VertBuffer -->

<!-- Vertical buffer to allow for sufficient spacing from the title and the content - should not be modified -->

<tr>

<td class="PortletBorderLeftRight" colspan="3"><img

height="1" alt="" src="<%# RootURL %>/images/common/clear.gif" width="1"

border="0" /></td>

</tr>

<!-- E /// VertBuffer -->

<!-- B /// ContentContainer -->

<tr valign="top">

<td class="PortletBorderLeft" width="3"><img height="1"

alt="" src="<%# RootURL %>/images/common/clear.gif" width="3" border="0"

/></td>

<td><br />

<!-- B /// Content -->

<!-- B /// MessageArea -->

<ul>

<asp:repeater id="rptMessages" runat="server" enableviewstate="False">

<itemtemplate>

<li class="error">

<%# DataBinder.Eval(Container.DataItem, "Text") %>

</li>

</itemtemplate>

</asp:repeater></ul>

<!-- E /// MessageArea -->

<!-- B /// DataList -->

<!-- /// ReVisit ClientSideEvents //<div class="view" oncontextmenu="BLOCKED SCRIPTShowContextMenu(event)">-->

 

<div class="view" oncontextmenu="BLOCKED SCRIPTShowContextMenu(event)">

<igtab:UltraWebTab Width="840px" runat="server" ID="sheets" CssClass="igwtMainBlack2k7" ImageDirectory="<%# RootURL %>/includes/css/office2007black/WebTabs/" TabOrientation="BottomLeft" ThreeDEffect="False">

<Tabs>

<igtab:Tab Text="Sheet1">

<Style Height="16px" Font-Size="x-small" CssClass="text" />

<ContentTemplate>

<igtbl:UltraWebGrid runat="server" ID="CopyPasteGrid1" Width="100%" Style="float:left;">

<Bands>

<igtbl:UltraGridBand>

<AddNewRow View="NotSet" Visible="NotSet">

</AddNewRow>

</igtbl:UltraGridBand>

</Bands>

<DisplayLayout SelectTypeCellDefault="extended" RowSelectorsDefault="yes" AllowRowNumberingDefault="Continuous" AllowSortingDefault="No" BorderCollapseDefault="Separate" CellClickActionDefault="CellSelect" Name="CopyPasteGrid1" RowHeightDefault="20px"

SelectTypeRowDefault="Extended" Version="4.00" ViewType="Flat" AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AllowUpdateDefault="Yes" HeaderClickActionDefault="Select" SelectTypeColDefault="Single" TableLayout="Fixed" >

<ClientSideEvents MouseUpHandler="GridClick" ClipboardError="Grid_OnClipboardError" />

<GroupByBox>

<BandLabelStyle BackColor="#6372D4" ForeColor="White">

</BandLabelStyle>

<Style CssClass="igwgGrpBoxBlack2k7"></Style>

</GroupByBox>

<GroupByRowStyleDefault BackColor="#F4FBFE">

</GroupByRowStyleDefault>

<ActivationObject BorderColor="204, 237, 252" BorderWidth="1px" BorderStyle="Solid">

<BorderDetails WidthLeft="0px" WidthRight="0px" />

</ActivationObject>

<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">

<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />

</FooterStyleDefault>

<RowStyleDefault BackColor="Window" Height="19px">

<Padding Left="6px" />

<BorderDetails ColorLeft="230, 230, 230" StyleLeft="Solid" WidthLeft="1px" WidthTop="1px" StyleTop="solid" ColorTop="#f1f1f1" />

</RowStyleDefault>

<FilterOptionsDefault>

<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">

</FilterHighlightRowStyle>

<FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Width="200px">

<Padding Left="2px" />

</FilterDropDownStyle>

</FilterOptionsDefault>

<RowSelectorStyleDefault BackColor="White" BackgroundImage="none">

</RowSelectorStyleDefault>

<SelectedRowStyleDefault BackColor="#E0F1F9" BackgroundImage="<%# RootURL %>/App_Themes/Aero/row_selected_bg.jpg" BorderStyle="None" BorderWidth="0px" CustomRules="background-repeat: repeat-x;">

<Padding Left="7px" />

</SelectedRowStyleDefault>

<HeaderStyleDefault BackgroundImage="<%# RootURL %>/App_Themes/Aero/grid_header_selected_bg.jpg" BorderStyle="None" Cursor="Hand" Font-Bold="True" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="X-Small" ForeColor="#555555" Height="23px" HorizontalAlign="Center">

<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />

<Padding Left="5px" />

</HeaderStyleDefault>

<Images>

<CollapseImage Url="<%# RootURL %>/App_Themes/Aero/ig_treeArrowMinus.png" />

<FixedHeaderOnImage Url="<%# RootURL %>/App_Themes/Aero/ig_tblFixedOn.gif" />

<ExpandImage Url="<%# RootURL %>/App_Themes/Aero/ig_treeArrowPlus.png" />

<CurrentRowImage Url="<%# RootURL %>/App_Themes/Aero/ig_CurrentRow.gif" />

<FixedHeaderOffImage Url="<%# RootURL %>/App_Themes/Aero/ig_tblFixedOff.gif" />

</Images>

<SelectedHeaderStyleDefault BackgroundImage="<%# RootURL %>/App_Themes/Aero/grid_header_selected_bg.jpg">

</SelectedHeaderStyleDefault>

<EditCellStyleDefault CssClass="EditStyle" Height="19px" BackColor="White" BorderStyle="None" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="9pt">

</EditCellStyleDefault>

<FrameStyle BackColor="White" Width="100%" BorderColor="#E6E6E6" BorderStyle="Solid" BorderWidth="1px" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="X-Small">

</FrameStyle>

<Pager>

<Style CssClass="igwgPgrBlack2k7"></Style>

</Pager>

<AddNewBox Hidden="False">

<Style CssClass="igwgAddNewBoxBlack2k7"></Style>

</AddNewBox>

</DisplayLayout>

</igtbl:UltraWebGrid>

</ContentTemplate>

</igtab:Tab>

<igtab:Tab Text="Sheet2">

<Style height="16px" Font-Size="x-small" CssClass="text" />

<ContentTemplate>

<igtbl:UltraWebGrid runat="server" ID="CopyPasteGrid2" Width="100%">

<Bands>

<igtbl:UltraGridBand>

<AddNewRow View="NotSet" Visible="NotSet">

</AddNewRow>

</igtbl:UltraGridBand>

</Bands>

<DisplayLayout SelectTypeCellDefault="extended" RowSelectorsDefault="yes" AllowRowNumberingDefault="Continuous" AllowSortingDefault="No" BorderCollapseDefault="Separate" CellClickActionDefault="CellSelect" Name="CopyPasteGrid2" RowHeightDefault="20px"

SelectTypeRowDefault="Extended" Version="4.00" ViewType="Flat" AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AllowUpdateDefault="Yes" HeaderClickActionDefault="Select" SelectTypeColDefault="Single" TableLayout="Fixed">

<ClientSideEvents MouseUpHandler="GridClick" ClipboardError="Grid_OnClipboardError" />

<GroupByBox>

<BandLabelStyle BackColor="#6372D4" ForeColor="White">

</BandLabelStyle>

<Style CssClass="igwgGrpBoxBlack2k7"></Style>

</GroupByBox>

<GroupByRowStyleDefault BackColor="#F4FBFE">

</GroupByRowStyleDefault>

<ActivationObject BorderColor="204, 237, 252" BorderWidth="1px" BorderStyle="Solid">

<BorderDetails WidthLeft="0px" WidthRight="0px" />

</ActivationObject>

<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">

<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />

</FooterStyleDefault>

<RowStyleDefault BackColor="Window" Height="19px">

<Padding Left="6px" />

<BorderDetails ColorLeft="230, 230, 230" StyleLeft="Solid" WidthLeft="1px" WidthTop="1px" StyleTop="solid" ColorTop="#f1f1f1" />

</RowStyleDefault>

<FilterOptionsDefault>

<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">

</FilterHighlightRowStyle>

<FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Width="200px">

<Padding Left="2px" />

</FilterDropDownStyle>

</FilterOptionsDefault>

<RowSelectorStyleDefault BackColor="White" BackgroundImage="none">

</RowSelectorStyleDefault>

<SelectedRowStyleDefault BackColor="#E0F1F9" BackgroundImage="<%# RootURL %>/App_Themes/Aero/row_selected_bg.jpg" BorderStyle="None" BorderWidth="0px" CustomRules="background-repeat: repeat-x;">

<Padding Left="7px" />

</SelectedRowStyleDefault>

<HeaderStyleDefault BackgroundImage="<%# RootURL %>/App_Themes/Aero/grid_header_bg.jpg" BorderStyle="None" Cursor="Hand" Font-Bold="True" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="X-Small" ForeColor="#555555" Height="23px" HorizontalAlign="Center">

<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />

<Padding Left="5px" />

</HeaderStyleDefault>

<Images>

<CollapseImage Url="<%# RootURL %>/App_Themes/Aero/ig_treeArrowMinus.png" />

<FixedHeaderOnImage Url="<%# RootURL %>/App_Themes/Aero/ig_tblFixedOn.gif" />

<ExpandImage Url="<%# RootURL %>/App_Themes/Aero/ig_treeArrowPlus.png" />

<CurrentRowImage Url="<%# RootURL %>/App_Themes/Aero/ig_CurrentRow.gif" />

<FixedHeaderOffImage Url="<%# RootURL %>/App_Themes/Aero/ig_tblFixedOff.gif" />

</Images>

<SelectedHeaderStyleDefault BackgroundImage="<%# RootURL %>/App_Themes/Aero/grid_header_selected_bg.jpg">

</SelectedHeaderStyleDefault>

<EditCellStyleDefault CssClass="EditStyle" Height="19px" BackColor="White" BorderStyle="None" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="9pt">

</EditCellStyleDefault>

<FrameStyle BackColor="White" Width="100%" BorderColor="#E6E6E6" BorderStyle="Solid" BorderWidth="1px" Font-Names="Trebuchet MS,Verdana,Arial,sans-serif" Font-Size="X-Small">

</FrameStyle>

<Pager>

<Style CssClass="igwgPgrBlack2k7"></Style>

</Pager>

<AddNewBox Hidden="False">

<Style CssClass="igwgAddNewBoxBlack2k7"></Style>

</AddNewBox>

</DisplayLayout>

</igtbl:UltraWebGrid>

</ContentTemplate>

</igtab:Tab>

</Tabs>

<DefaultTabStyle CssClass="igwtTabNormalBlack2k7" Height="22px">

</DefaultTabStyle>

<HoverTabStyle CssClass="igwtTabHoverBlack2k7">

</HoverTabStyle>

<RoundedImage FillStyle="LeftMergedWithCenter" HoverImage="igwt_tab_hover.jpg" LeftSideWidth="14"

NormalImage="none" RightSideWidth="14" SelectedImage="igwt_tab_selected.jpg" />

<SelectedTabStyle CssClass="igwtTabSelectedBlack2k7">

</SelectedTabStyle>

</igtab:UltraWebTab>

<asp:Button runat="Server" ID="ExportToExcelButton" Text="Export to Excel" OnClick="ExportToExcel" CssClass="exportButton" />

</div>

<igtblexp:UltraWebGridExcelExporter ID="UltraWebGridExcelExporter1" runat="server" DownloadName="Workbook1.xls" ExportMode="Download" >

</igtblexp:UltraWebGridExcelExporter>

 

<ignav:UltraWebMenu TopAligment="left" TopItemSpacing="Compact" ID="CopyPasteMenu" runat="server" WebMenuStyle="XPClient" WebMenuTarget="PopupMenu" CssClass="ContextMenu" EnableViewState="False">

<MenuClientSideEvents ItemClick="ContextMenuItemClick" />

<SeparatorStyle CustomRules="background-repeat:repeat-x;" BackgroundImage="<%# RootURL %>/css/office2007black/webmenu/igMenuSeparator.jpg" />

<Items>

<ignav:Item Text="Cut">

<Images><DefaultImage Url="<%# RootURL %>/css/office2007black/webhtmleditor/cut.gif" AlternateText="Cut" />

</Images>

</ignav:Item>

<ignav:Item Text="Copy">

<Images><DefaultImage Url="<%# RootURL %>/css/office2007black/webhtmleditor/copy.gif" AlternateText="copy" />

</Images>

</ignav:Item>

<ignav:Item Text="Paste">

<Images>

<DefaultImage Url="<%# RootURL %>/css/office2007black/webhtmleditor/paste.gif" AlternateText="paste" />

</Images>

</ignav:Item>

<ignav:Item Separator="true" >

</ignav:Item>

<ignav:Item Text="Export To Excel">

<Images>

<DefaultImage Url="./excelicon.gif" AlternateText="Export To Excel" />

</Images>

</ignav:Item>

</Items>

<ItemStyle CssClass="ContextMenuItem" />

<HoverItemStyle CssClass="ContextMenuItemHover" />

<ExpandEffects ShadowColor="LightGray" />

</ignav:UltraWebMenu>

 

 

<!-- E /// DataList -->

<!-- B /// Buttons -->

<!-- E /// Buttons -->

<!-- E /// Content --></td>

<td class="PortletBorderRight" width="3"><img alt="" border="0" width="1" height="1" src="<%# RootURL %>/images/common/clear.gif" /></td>

</tr>

<!-- E /// ContentContainer -->

<!-- B /// BottomColSizer -->

<!-- Cap the container and provide column sizing - should not be modified -->

<tr valign="bottom">

<td width="11"><img height="11" alt=""

src="<%# RootURL %>/images/corners/bottom_l_line_666699.gif" width="11"

border="0" /></td>

<td class="PortletBorderBottom"><img height="1" alt=""

src="<%# RootURL %>/images/common/clear.gif" width="1" border="0"

/></td>

<td align="right" width="11"><img alt="" border="0" width="11" height="11" src="<%# RootURL %>/images/corners/bottom_r_line_666699.gif" /></td>

</tr>

<!-- E /// BottomColSizer --></table>

<script type="text/C#" runat="server">

protected void ExportToExcel(object sender, EventArgs e)

{

Infragistics.Excel.Workbook workbook = new Infragistics.Excel.Workbook();

workbook.Worksheets.Add("Sheet1");

workbook.Worksheets.Add("Sheet2");

this.CopyPasteGrid1.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.No;

this.UltraWebGridExcelExporter1.Export(this.CopyPasteGrid1, workbook);

for (int i = 0; i < this.CopyPasteGrid1.Columns.Count; i++)

{

workbook.Worksheets[0].Columns[i].Width = 2000;

}

this.CopyPasteGrid2.DisplayLayout.ColHeadersVisibleDefault = ShowMarginInfo.No;

workbook.ActiveWorksheet = workbook.Worksheets[1];

this.UltraWebGridExcelExporter1.Export(this.CopyPasteGrid2, workbook);

for (int i = 0; i < this.CopyPasteGrid2.Columns.Count; i++)

{

workbook.Worksheets[1].Columns[i].Width = 2000;

}

workbook.ActiveWorksheet = workbook.Worksheets[0];

}

protected void Page_Load(object sender, EventArgs e)

{

//this.WebPanel1.Visible = WebSamplesCS.Config.ShowDescription;

if (!this.IsPostBack)

{

int max_rows = 28;

int max_cols = 16;

String alphabet = "abcdefghijklmnopqrstuvwxyz";

for (int j = 0; j < max_cols; j++)

{

this.CopyPasteGrid1.Columns.Add("Col" + j, alphabet[j % 26].ToString().ToUpper());

this.CopyPasteGrid2.Columns.Add("Col" + j, alphabet[j % 26].ToString().ToUpper());

}

for (int i = 0; i < max_rows; i++)

{

this.CopyPasteGrid1.Rows.Add();

this.CopyPasteGrid2.Rows.Add();

}

this.CopyPasteGrid1.Rows[0].Cells[0].Text = "Sample";

this.CopyPasteGrid1.Rows[0].Cells[1].Text = "Data";

}

}

</script>

 

  • 13438
    Suggested Answer
    posted

    Hello Sushma

    I know it has been a while since you asked this question  but in case you still need assistance I will be glad to provide an answer. I could not create a sample based on your code sniped due to many undefined css classes referenced in not attached files. Please always provide a small runnable sample and attach it as archive in order to provide you better support. However please refer to the following forum thread where a similar answer has been asked - http://community.infragistics.com/forums/p/37686/282422.aspx#. You can also check the following blog regarding copy-paste functionality - http://community.infragistics.com/blogs/alex_kartavov/archive/2010/02/09/copy-paste-from-excel-to-webdatagrid.aspx