DevExpress asp.net에서 Excel을 내보내면 자동으로 번개 문제가 발생합니다. 기본값은 aspx 페이지로 저장됩니다.

8899 단어 DevExpress
현재 곡선 구국 전략을 채택하고 있다.
MVC를 이용해서...
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="FriendLinkID" Theme="Default" EnableTheming="True">

                <Columns>

                    <dx:GridViewDataTextColumn FieldName="FriendLinkID" ReadOnly="True" VisibleIndex="0">

                        <EditFormSettings Visible="False" />

                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataTextColumn FieldName="LinkName" VisibleIndex="1">

                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataTextColumn FieldName="LinkSrc" VisibleIndex="2">

                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataTextColumn FieldName="Contact" VisibleIndex="3">

                    </dx:GridViewDataTextColumn>

                    <dx:GridViewDataDateColumn FieldName="PublishData" VisibleIndex="4">

                    </dx:GridViewDataDateColumn>

                </Columns>

            </dx:ASPxGridView>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Pengbg_DataConnectionString %>" 

                SelectCommand="SELECT * FROM [Friendlink]"></asp:SqlDataSource>

            <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" GridViewID="ASPxGridView1" runat="server"></dx:ASPxGridViewExporter>

            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

 
 protected void Button1_Click(object sender, EventArgs e)

        {

            var fileName = new Random().Next().ToString();

            var fullPath = @"C:\" + fileName + ".xls";

            using (var fs = new FileStream(fullPath, FileMode.CreateNew, FileAccess.Write))

            {

                ASPxGridViewExporter1.WriteXls(fs);

            }

            Response.Redirect("Default1?path=" + fullPath);

        }
 public class Default1Controller : Controller

    {

        //

        // GET: /Default1/



        public ActionResult Index(string path)

        {

            String newfileName = DateTime.Now.ToString("yyyyMMddHHmmssff");

            return File(System.IO.File.ReadAllBytes(path), "application/vnd.ms-excel", HttpUtility.UrlEncode(string.Format("{0}.xls", newfileName)));

        }



    }

원리는 추측, 조정 중...

좋은 웹페이지 즐겨찾기