如何使用C#创建Excel工作表 [英] How to Create a Excel Sheet Using C#
本文介绍了如何使用C#创建Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#
推荐答案
在按钮单击事件中创建Excel工作表。希望此链接可以帮助您 http://stackoverflow.com/questions/16705651/how-to-create- a-new-worksheet-in-excel-file-c [ ^ ]
或此链接使用C#创建Excel文档 [ ^ ]
如果这不起作用,请告诉我们,我们随时为您提供帮助。
谢谢
Ganesh
Hope this links might helps you http://stackoverflow.com/questions/16705651/how-to-create-a-new-worksheet-in-excel-file-c[^]
or this link too Using C# to Create an Excel Document[^]
If this does n't works let us know, we are here to help you.
Thanks
Ganesh
添加此命名空间
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
将此代码写入您想要的地方
Add this Namespaces
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Write this Code where you want
Dim Path As String = Server.MapPath("SendRequest\" + Filename)
Dim FileInfor As New FileInfo(Path)
Dim stringWriter As New StringWriter()
Dim htmlWrite As New HtmlTextWriter(stringWriter)
Dim directory__1 As String = Path.Substring(0, Path.LastIndexOf("\"))
If Not Directory.Exists(directory__1) Then
Directory.CreateDirectory(directory__1)
End If
Dim vw As New System.IO.StreamWriter(Path, True)
stringWriter.ToString().Normalize()
vw.Write(stringWriter.ToString())
vw.Flush()
vw.Close()
WriteAttachment(FileInfor.Name, "application/vnd.ms-excel", stringWriter.ToString())
添加此功能
Add this Function also
Public Shared Sub WriteAttachment(ByVal FileName As String, ByVal FileType As String, ByVal content As String)
Dim Response As HttpResponse = System.Web.HttpContext.Current.Response
Response.ClearHeaders()
Response.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
Response.ContentType = FileType
Response.Write(content)
Response.[End]()
End Sub
这篇关于如何使用C#创建Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文