动态创建excel并自动下载 [英] Dynamically create excel and autmatically download

查看:61
本文介绍了动态创建excel并自动下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< Microsoft.Office.Interop.Excel.Application xlApp;< br /> 
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;< br />
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;< br />
object misValue = System.Reflection.Missing.Value;< br />
xlApp = new Microsoft.Office.Interop。 Excel.ApplicationClass();< br />
xlWorkBook = xlApp.Workbooks.Add(misValue);< br />
< br />
xlWorkSheet =(Microsoft.Office .Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);< br />
xlWorkSheet.Cells [1,1] =http://csharp.net-informations.com;< br />
< br />
xlWorkBook.SaveAs(csharp-Excel.xls,Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,misValue,misValue,misValue,misValue,Microsoft。 Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,misValue,misValue,misValue,misValue,misValue);< br />
xlWorkBook.Close(true,misValue,misValue);< br />
xlApp.Quit();







这是我的C#按钮代码。我只是想按钮点击自动执行此excel文件下载。此代码仅生成excel文件。以及如何添加下载代码。我不知道。例如,我们在谷歌浏览器中下载任何内容,然后单击项目开始下载。和浏览器下载文件底部显示。怎么做,请帮帮我

谢谢

Advance

解决方案

处理完Excel动作后您可以将文件保存在服务器所需的位置(记下路径)

之后您可以使用此 asp-net-excel-file-download-on-button-click [ ^ ]用于将文件下载到浏览器。

<Microsoft.Office.Interop.Excel.Application xlApp;<br />
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;<br />
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;<br />
            object misValue = System.Reflection.Missing.Value;<br />
            xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();<br />
            xlWorkBook = xlApp.Workbooks.Add(misValue);<br />
<br />
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);<br />
            xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";<br />
<br />
            xlWorkBook.SaveAs("csharp-Excel.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);<br />
            xlWorkBook.Close(true, misValue, misValue);<br />
            xlApp.Quit();




here is my C# button code. i just want to do this excel file download automatiacally on button click. this code generate excel file only.And how to add download code. i dont know. Example we download anything in google chrome then click the item start download. and bottom of the browser download file show. how to do this,, Please help me
thanks in
Advance

解决方案

After process the Excel Actions you can save the file in the server in desired location (note down the path)
after that you can use this asp-net-excel-file-download-on-button-click[^] for downloading the files to the browser.


这篇关于动态创建excel并自动下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆