ASP.Net Web窗体生成的Excel文件下载到本地PC和服务器不 [英] ASP.Net webform generated Excel File to local PC and not server
问题描述
从有关生成Excel文件的问题上之后,我需要能够在本地创建文件,而Web窗体应用程序所在的远程Web服务器上。这是没有什么我已经经历过,所以我发现很难问什么。我使用的WebForms在VS2010用C#。 eanderson 指着我的方向
Simplexcel 通过的迈克尔葡萄汁这似乎这样的伎俩,但在服务器上生成的文件(或者我应该说'尝试',因为它是不允许的!)。
Following on from a question about generating Excel files, I need to be able to create the file locally while the webform app is located on the remote web server. This is not anything I've dealt with before, so I am finding it difficult exactly what to ask. I am using WebForms on VS2010 with c#. eanderson pointed me in the direction of Simplexcel by Michael Stum which seems to do the trick but the file is generated on the server (or should I says 'tries to' as it is not permitted!!!).
推荐答案
您应该能够做一些类似的生成和下载 Excel工作表
。
You should be able to do something similar to this to generate and download the Excel Sheet
.
protected void generateExcelSheet_click(object sender, EventArgs e)
{
// Create Excel Sheet
var sheet = new Worksheet("Hello, world!");
sheet.Cells[0, 0] = "Hello,";
sheet.Cells["B1"] = "World!";
var workbook = new Workbook();
workbook.Add(sheet);
// Save
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=MyExcelSheet.xls");
workbook.Save(Response.OutputStream, CompressionLevel.Maximum);
Response.End();
}
在 designer.aspx
:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FileDownload.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnExcel" runat="server" Text="Download Excel Sheet" onclick="generateExcelSheet_click" />
</form>
</body>
</html>
我的基础上的这个教程。
这篇关于ASP.Net Web窗体生成的Excel文件下载到本地PC和服务器不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!