首页 新闻 会员 周边 捐助

Ext.net导出Excel

0
悬赏园豆:30 [已关闭问题] 关闭于 2015-11-13 14:43

Ext.net导出Excel表格,急

<div>
            <ext:Viewport runat="server" Layout="FitLayout">
                <Items>
                    <ext:Panel runat="server" ID="AccidentPanel" Layout="BorderLayout" BodyCls="bordernone">
                        <Items>
                            <ext:FormPanel runat="server" ID="SearchForm" Region="North" BodyCls="formstyle">
                                <Items>
                                    <ext:Panel runat="server" BodyCls="bordernone" Layout="HBoxLayout">
                                        <Items>
                                           
                                            <ext:DateField runat="server" ID="BeginDate" FieldLabel="事故日期" Format="yyyy-MM-dd" MarginSpec="5 3" LabelWidth="70" Flex="4" />
                                            <ext:DateField runat="server" ID="EndDate" FieldLabel="-------" Format="yyyy-MM-dd" MarginSpec="5 3" LabelWidth="50" Flex="4" />
                                            
                                            <ext:TextField runat="server" ID="srhName" FieldLabel="当事人姓名" LabelWidth="80" MarginSpec="5 3" Flex="4" />
                                            <ext:TextField runat="server" ID="srhSFZ" FieldLabel="身份证" LabelWidth="60" MarginSpec="5 3" Flex="4" />
                                            <ext:TextField runat="server" ID="srhCheHao" FieldLabel="车牌号" LabelWidth="60" MarginSpec="5 3" Flex="3" />
                                        </Items>
                                    </ext:Panel>
                                            
                                       
                                    <ext:Panel runat="server" BodyCls="bordernone" Layout="HBoxLayout">
                                        <Items>
                                            <ext:TextField runat="server" ID="AccNo" FieldLabel="事故编号" LabelWidth="70" MarginSpec="5 3" Flex="4" />

                                            <%--<ext:Combobox runat="server" ID="AccType" FieldLabel="单车事故类型" MarginSpec="5 3" LabelWidth="90" Flex="4" />                
                                            <ext:ComboBox runat="server" ID="AccType2" FieldLabel="车辆间事故类型" MarginSpec="5 3" LabelWidth="110" Flex="4" />--%>

                                            <ext:TextField runat="server"  ID="DieHurtNum" FieldLabel="死亡人数" MarginSpec="5 3" LabelWidth="70" Flex="2" />

                                            <%--<ext:NumberField runat="server" ID="EndHurtNum" FieldLabel="~" MarginSpec="5 3" LabelWidth="10" Flex="1" />    
                                                                                       --%>
                                            <ext:Button runat="server" Text="查询" Icon="Magnifier" MarginSpec="5 3" Width="50" Flex="2" Handler="App.AccidentStore.reload()" />
                                            <ext:Button runat="server" Text="新建" ID="AddAcc" Icon="New" MarginSpec="5 3" Width="60" Flex="2" Handler="NewAccident()" />
                                            <ext:Button runat="server" Text="打印" ID="Print" MarginSpec="5 3" Width="50" Flex="2" />
                                            <ext:Button runat="server" Text="导出" ID="Export"  AutoPostBack="true"  MarginSpec="5 3" Width="50" Flex="2" Handler="ToExcel()"/>
                                        </Items>
                                    </ext:Panel>
                                </Items>
                            </ext:FormPanel>
                            
                            <ext:GridPanel runat="server" ID="AccidentGrid" Region="Center">
                                
                                <Store>
                                    <ext:Store runat="server" ID="AccidentStore" OnReadData="AccidentStore_ReadData" AutoLoad="false">
                                        <AutoLoadParams>
                                            <ext:StoreParameter Name="start" Value="0" Mode="Raw"></ext:StoreParameter>
                                            <ext:StoreParameter Name="limit" Value="20" Mode="Raw"></ext:StoreParameter>
                                        </AutoLoadParams>
                                        <Parameters>
                                        </Parameters>
                                        <Proxy>
                                            <ext:PageProxy />
                                        </Proxy>
                                        <Model>
                                            <ext:Model runat="server">
                                                <Fields>
                                                    <ext:ModelField Name="AccID" />
                                                    <ext:ModelField Name="AccidentNo" />
                                                    <ext:ModelField Name="Time" Type="Date" />
                                                    <ext:ModelField Name="Place" />
                                                   <%-- <ext:ModelField Name="AccidentTypeID" />
                                                    <ext:ModelField Name="AccidentTypeID2" />--%>
                                                    <ext:ModelField Name="HowSeriousID" />
                                                    <ext:ModelField Name="HurtNum" />
                                                    <ext:ModelField Name="DeadNum" />
                                                    <ext:ModelField Name="PoliceNo" />
                                                    <ext:ModelField Name="PoliceName" />
                                                    <ext:ModelField Name="DeptName" />
                                                </Fields>
                                            </ext:Model>
                                        </Model>
                                    </ext:Store >
                                </Store>
                                <ColumnModel>
                                    <Columns>
                                        <ext:Column runat="server" Text="id" Hidden="true" Flex="2" DataIndex="AccID" Align="Center" />
                                        <ext:Column runat="server" Text="事故编号" Flex="2" DataIndex="AccidentNo" Hidden="true"/>
                                        <ext:DateColumn runat="server" Text="发生时间" Format="yyyy-MM-dd HH:mm" Flex="2" DataIndex="Time" Align="Center"/>
                                        <ext:Column runat="server" Text="发生地点" Flex="4" DataIndex="Place" Align="Center" />
                                        <ext:Column runat="server" Text="单车事故类型" Flex="2" DataIndex="AccidentTypeID" Hidden="true" />
                                        <ext:Column runat="server" Text="车辆间事故类型" Flex="2" DataIndex="AccidentTypeID2"  Hidden="true"/>
                                        <ext:Column runat="server" Text="严重程度" Flex="2" DataIndex="HowSeriousID"  Align="Center"/>
                                        <ext:Column runat="server" Text="死亡人数" Flex="2" DataIndex="DeadNum"  Align="Center"/>
                                        <ext:Column runat="server" Text="受伤人数" Flex="2" DataIndex="HurtNum"  Align="Center"/>
                                        <ext:Column runat="server" Text="办案人员" Flex="2" DataIndex="PoliceName"  Align="Center"/>
                                        <ext:Column runat="server" Text="所属部门" Flex="2" DataIndex="DeptName"  Align="Center"/>
                                    </Columns>
                                </ColumnModel>
                                <Listeners>
                                    <ItemDblClick Handler="showDetails(record)" />
                                </Listeners>
                                <BottomBar>
                                    <ext:PagingToolbar runat="server" />
                                </BottomBar>
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>
        </div>
蓝瑟黄昏的主页 蓝瑟黄昏 | 初学一级 | 园豆:176
提问于:2015-11-02 16:08
< >
分享
所有回答(3)
-1

导出Excel,跟是不是ext.net 没关系吧,可以用npoi做Excel导出,

秋壶冰月 | 园豆:5903 (大侠五级) | 2015-11-03 12:59

Nopi没用

支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-03 14:03

npoi没用过

支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-03 14:03

@蓝瑟黄昏: 没用过,可以试试,园内好多关于npoi博文呀

支持(0) 反对(0) 秋壶冰月 | 园豆:5903 (大侠五级) | 2015-11-03 20:49

@秋壶冰月: 今天试了下,npoi直接不会用  找到的都是代码  应该是直接套进去   gridpanel不能直接用

支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-04 15:50

@蓝瑟黄昏:npoi在后台用的,将npoi的dll文件加载你项目,还是很简单的

支持(0) 反对(0) 秋壶冰月 | 园豆:5903 (大侠五级) | 2015-11-04 15:52

@秋壶冰月: 这么说太空泛  有详细点的教程或文章吗

支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-05 09:00

@蓝瑟黄昏: http://www.cnblogs.com/lwme/archive/2011/11/18/npoi_excel_import_export.html

支持(0) 反对(0) 秋壶冰月 | 园豆:5903 (大侠五级) | 2015-11-05 09:10
Response.Clear();
            Response.Buffer = true;
            Response.Charset = "utf-8";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("导出" + System.DateTime.Now.Date.ToString("yyyyMMdd")) + ".xls");
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为简体中文

            Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
            this.EnableViewState = false;
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            
            this.AccidentGrid.RenderControl(oHtmlTextWriter);
            Response.Write(oStringWriter.ToString());
            Response.End();

 

@秋壶冰月: 研究了下  貌似和我的不合适我菜鸟,不会用这个啊,找了个代码,不过导出的是乱码

支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-06 11:01
0

aspx.cs文件:

protected void AccidentStore_Submit(object sender, StoreSubmitDataEventArgs e)
{
string format = this.FormatType.Value.ToString();

XmlNode xml = e.Xml;

this.Response.Clear();

switch (format)
{
case "xls":
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("../XSL/Accident.xsl"));
xtExcel.Transform(xml, null, Response.OutputStream);
break;
}
this.Response.End();
}

aspx:

    js:

var exportData = function (format) {
App.FormatType.setValue(format);
var store = App.AccidentGrid.store;

store.submitData(null, { isUpload: true });
};

  调用:

<ext:Button runat="server" Text="导出" ID="Export" Icon="PageExcel" MarginSpec="5 3" Width="60" Flex="2" Handler="exportData('xls')" />

form中:

 <ext:Hidden ID="FormatType" runat="server" />

蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-13 14:39

忘了个文件Accident.xsl

<xsl:stylesheet version="1.0"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:user="urn:my-scripts"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> 
 
<xsl:template match="/">
  <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <xsl:apply-templates/>
  </Workbook>
</xsl:template>


<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>
        
          <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'事故编号'" />
          </Data>
        </Cell>
        <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'发生时间'" />
          </Data>
        </Cell>
<Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'发生地点'" />
          </Data>
        </Cell>
          <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'严重程度'" />
          </Data>
        </Cell>
        <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'死亡人数'" />
          </Data>
        </Cell>
        <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'受伤人数'" />
          </Data>
        </Cell>
        <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'办案人员'" />
          </Data>
        </Cell>
        <Cell>
            <Data ss:Type="String">
          <xsl:value-of select="'所属部门'" />
          </Data>
        </Cell>
      </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>


</xsl:stylesheet>
支持(0) 反对(0) 蓝瑟黄昏 | 园豆:176 (初学一级) | 2015-11-13 15:02
0

试试PageOffice插件吧

贝塔ZQ | 园豆:256 (菜鸟二级) | 2017-05-15 11:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册