Shows Id when i Export Grid to Excel

  1. #1

    Shows Id when i Export Grid to Excel

    Hi,

    I have a little problem. Following this example, I have created a grid to export to Excel. The grid doesnt have an Id column, but when I create my Excel file, this Id column appears on it like this:
    Click image for larger version. 

Name:	Captura1.PNG 
Views:	5 
Size:	17.3 KB 
ID:	25270
    Click image for larger version. 

Name:	Captura2.PNG 
Views:	2 
Size:	22.4 KB 
ID:	25271

    ¿Is there a way a remove the id column from Excel?

    Thank you very much

    edit: Here is the grid code:

    <ext:GridPanel runat="server" ID="gridnotas"  ColumnWidth="0.7" Height ="230" MarginSpec="20 0 0 0" Frame="false">
                                                        <Store>
                                                            <ext:Store runat="server" ID="StoreNotas"
                                                                OnReadData="RefreshNotasProceso"
                                                                OnSubmitData="SubmitNotasProceso"
                                                                RemoteSort="true">
                                                                <Model>
                                                                    <ext:Model runat="server">
                                                                        <Fields>
                                                                            <ext:ModelField Name="Id" />
                                                                            <ext:ModelField Name="Modelo" />
                                                                            <ext:ModelField Name="Color" />
                                                                            <ext:ModelField Name="Talla" />
                                                                            <ext:ModelField Name="T36" />
                                                                            <ext:ModelField Name="T37" />
                                                                            <ext:ModelField Name="T38" />
                                                                            <ext:ModelField Name="T39" />
                                                                            <ext:ModelField Name="T40" />
                                                                            <ext:ModelField Name="T41" />
                                                                            <ext:ModelField Name="T42" />
                                                                            <ext:ModelField Name="T43" />
                                                                            <ext:ModelField Name="T44" />
                                                                            <ext:ModelField Name="T45" />
                                                                            <ext:ModelField Name="T46" />
                                                                            <ext:ModelField Name="T47" />
                                                                        </Fields>
                                                                    </ext:Model>
                                                                </Model>
                                                            </ext:Store>
                                                        </Store>
                                                        <ColumnModel runat="server">
                                                            <Columns>
                                                                <ext:Column runat="server" Text="Modelo" DataIndex="Modelo" Width="100" Align="Center"/>
                                                                <ext:Column runat="server" Text="Color" Width="100" DataIndex="Color" Align="Center"/>
                                                                <ext:Column runat="server" Text="Talla" DataIndex="Talla" Width="150" Align="Center"/>
                                                                <ext:Column runat="server" Text="36" DataIndex="T36" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="37" DataIndex="T37" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="38" DataIndex="T38" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="39" DataIndex="T39" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="40" DataIndex="T40" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="41" DataIndex="T41" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="42" DataIndex="T42" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="43" DataIndex="T43" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="44" DataIndex="T44" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="45" DataIndex="T45" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="46" DataIndex="T46" Width="65" Align="Center"/>
                                                                <ext:Column runat="server" Text="47" DataIndex="T47" Width="65" Align="Center"/>
                                                            </Columns>
                                                        </ColumnModel>
                                                    </ext:GridPanel>
    Last edited by PascuV; Jun 17, 2019 at 9:28 AM. Reason: add code
  2. #2
    ¿Is there a solution?

    Thank you very much.
  3. #3
    Hi.
    I dont have the time to write a full code answer (and test it for you) for you but the simple answer is as such. yes this is possible.
    Excel.xsl uses XSL language specification. The for-each tag that is iterating to build the CELLS, so just exclude the ID in the loop. Now i didn't test this code but just wrote it freehand but it should lead you down the correct path to solve your problem.

    Good Luck!
    /Z

    CURRENT CODE
          <Row>
            <xsl:for-each select="*[position() = 1]/*">
              <Cell>
                  <Data ss:Type="String"><xsl:value-of select="local-name()" /></Data>
              </Cell>
            </xsl:for-each>
          </Row>
    PROPOSED CODE
    
          <Row>
            <xsl:for-each select="*[position() = 1]/*[local-name() != 'id']">">
              <Cell>
                  <Data ss:Type="String"><xsl:value-of select="local-name()" /></Data>
              </Cell>
            </xsl:for-each>
          </Row>
  4. #4
    Hi Z,

    Thank you very much for your help, but unfortunately your code is not working, it only hides the "id" header as shown below:



    The ext-48-X cells keep showing.

    Here is my XSL code, if it helps:

    <xsl:template match="/*">
        <Worksheet>
          <xsl:attribute name="ss:Name">
            <xsl:value-of select="local-name(/*/*)" />
          </xsl:attribute>
          <Table x:FullColumns="1" x:FullRows="1">
            <Row>
              <xsl:for-each select="*[position() = 1]/*[local-name() != 'id']">
                <Cell>
                  <Data ss:Type="String">
                    <xsl:value-of select="local-name()" />
                  </Data>
                </Cell>
              </xsl:for-each>
            </Row>
            <xsl:apply-templates/>
          </Table>
        </Worksheet>
      </xsl:template>
    
    
      <xsl:template match="/*/*">
        <Row>
          <xsl:apply-templates/>
        </Row>
      </xsl:template>
    
    
      <xsl:template match="/*/*/*">
        <Cell>
          <Data ss:Type="String">
            <xsl:value-of select="." />
          </Data>
        </Cell>
      </xsl:template>
    Last edited by PascuV; Jul 09, 2019 at 9:09 AM.
  5. #5
    Create a column with dataindex="Id" and make it visible=false. It must exist.
    Then give each column an id value. make sure the one for the id matches the one u exclude in the xsl
    /Z
  6. #6
    No way.

    GridPanel code:
    <ext:GridPanel runat="server" ID="GridMensual"  ColumnWidth="0.75" Height ="280" MarginSpec="20 0 0 0" Frame="false">
                                                        <Store>
                                                            <ext:Store runat="server" ID="StoreMensual"
                                                                OnSubmitData="SubmitGridMensual"
                                                                RemoteSort="true"
                                                                PageSize="10">
                                                                <Model>
                                                                    <ext:Model runat="server">
                                                                        <Fields>
                                                                            <ext:ModelField Name="id" Type="Int" />
                                                                            <ext:ModelField Name="Mes" />
                                                                            <ext:ModelField Name="Enero" />
                                                                            <ext:ModelField Name="Febrero" />
                                                                            <ext:ModelField Name="Marzo" />
                                                                            <ext:ModelField Name="Abril" />
                                                                            <ext:ModelField Name="Mayo" />
                                                                            <ext:ModelField Name="Junio" />
                                                                            <ext:ModelField Name="Julio" />
                                                                            <ext:ModelField Name="Agosto" />
                                                                            <ext:ModelField Name="Septiembre" />
                                                                            <ext:ModelField Name="Octubre" />
                                                                            <ext:ModelField Name="Noviembre" />
                                                                            <ext:ModelField Name="Diciembre" />
    
    
                                                                        </Fields>
                                                                    </ext:Model>
                                                                </Model>
                                                            </ext:Store>
                                                        </Store>
                                                        <ColumnModel runat="server">
                                                            <Columns>
                                                                <ext:Column runat="server" Text="id" DataIndex="id" Width="100" Align="Center"  Filterable="false" Visible="false"/>
                                                                <ext:Column runat="server" Text="Mes" DataIndex="Mes" ID="Mes" Width="100" Align="Center"/>
                                                                <ext:Column runat="server" Text="Enero" DataIndex="Enero" ID="Enero" Width="100" Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Febrero" DataIndex="Febrero" ID="Febrero"  Width="100" Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Marzo" DataIndex="Marzo" Width="100" ID="Marzo"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Abril" DataIndex="Abril" Width="100" ID="Abril"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Mayo" DataIndex="Mayo" Width="100" ID="Mayo"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Junio" DataIndex="Junio" Width="100"  ID="Junio"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Julio" DataIndex="Julio" Width="100" ID="Julio"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Agosto" DataIndex="Agosto" Width="100" ID="Agosto"  Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Septiembre" DataIndex="Septiembre" Width="100" ID="Septiembre"  Align="Center"  Filterable="false"/>
                                                                <ext:Column runat="server" Text="Octubre" DataIndex="Octubre"  ID="Octubre" Width="100" Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Noviembre" DataIndex="Noviembre" ID="Noviembre"  Width="100" Align="Center" Filterable="false"/>
                                                                <ext:Column runat="server" Text="Diciembre" DataIndex="Diciembre"  ID="Diciembre"  Width="100" Align="Center"  Filterable="false"/>
                                                                
                                                            </Columns>
                                                        </ColumnModel>
                                                            <BottomBar>
                                                            <ext:PagingToolbar runat="server" HideRefresh="True">
                                                            </ext:PagingToolbar>
                                                        </BottomBar>
                                                    </ext:GridPanel>
    XSL code:
      <xsl:template match="/*">
        <Worksheet>
          <xsl:attribute name="ss:Name">
            <xsl:value-of select="local-name(/*/*)" />
          </xsl:attribute>
          <Table x:FullColumns="1" x:FullRows="1">
            <Row>
              <xsl:for-each select="*[position() = 1]/*[local-name() != 'id']">
                <Cell>
                  <Data ss:Type="String">
                    <xsl:value-of select="local-name()" />
                  </Data>
                </Cell>
              </xsl:for-each>
            </Row>
            <xsl:apply-templates/>
          </Table>
        </Worksheet>
      </xsl:template>
    Result:


    As you can see, the id header disappears and the other headers are moved to the left.

Similar Threads

  1. Replies: 2
    Last Post: May 10, 2019, 10:29 PM
  2. Export to Excel for Dynamic Grid panel
    By kavitha in forum 2.x Help
    Replies: 0
    Last Post: Jan 22, 2014, 10:33 AM
  3. Export the grid to excel
    By Mr.Techno in forum 1.x Help
    Replies: 34
    Last Post: Aug 23, 2013, 11:39 AM
  4. how to export selected columns from a grid to excel
    By deepu s nair in forum 2.x Help
    Replies: 0
    Last Post: Feb 05, 2013, 12:09 PM
  5. Excel Export in Grid
    By BLOZZY in forum 1.x Help
    Replies: 0
    Last Post: Oct 09, 2011, 11:37 AM

Posting Permissions