vb.net VB.net中的EPPlus
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23517845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EPPlus in VB.net
提问by Krishnak
I'm trying to fill an existing xls file with EPPlus, but i never use it before. I have to search my data in a DB.
我正在尝试用 EPPlus 填充现有的 xls 文件,但我以前从未使用过它。我必须在数据库中搜索我的数据。
After insert data, the user could save the file on his computer, I doesn't know anything about EPPlus so, i made this :
插入数据后,用户可以将文件保存在他的计算机上,我对 EPPlus 一无所知,所以我做了这个:
Dim ExistFile = Server.MapPath("~/Vues/tableau_qualif1.xlsx")
Dim File = New FileInfo(ExistFile)
Dim Connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Formation_2014ConnectionString").ConnectionString)
Dim i = 3
Dim Query = "SELECT * FROM personnes"
Using package As New ExcelPackage(File)
package.Load(New FileStream(ExistFile, FileMode.Open))
Dim workSheet As ExcelWorksheet = package.Workbook.Worksheets("Feuil1")
Try
'Ouverture de la connexion
Connection.Open()
'Définition de la commande et de ses paramètres
Dim Commande As New SqlCommand(Query, Connection)
'Création du SqlDataAdapter et du DataSet (En fonction de la Commande)
Dim Adaptateur As New SqlDataAdapter(Commande)
Dim MonDataSet As New DataSet
Try
'Définition de l'adaptateur
Adaptateur.Fill(MonDataSet, "Personnes")
For Each Ligne As DataRow In MonDataSet.Tables("Personnes").Rows()
workSheet.Cells("A" & i).Value = Ligne("Prenom_personne").ToString() & " " & Ligne("Nom_personne").ToString()
i = i + 1
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Fermeture de la connexion
Connection.Close()
package.Save()
Response.Clear()
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.BinaryWrite(package.GetAsByteArray())
Response.End()
End Using
This code crash at
此代码崩溃于
Response.BinaryWrite(package.GetAsByteArray())
Anyone could help me with this ? Thanks a lot !
任何人都可以帮助我吗?非常感谢 !
采纳答案by Krishnak
My line
我的线路
package.save()
cause my issues, I just remove this line and all work fine !
导致我的问题,我只是删除了这条线,一切正常!

