终于能够解决我的问题..非常感谢使用 Excelv 作为新的 ExcelPackage()
Dim ws As ExcelWorksheet = Excelv.Workbook.Worksheets.Add(fileName)
Dim rowCount As Integer = 1
For Each rw As DataRow In dddd.Rows
'excelData.Columns.RemoveAt(0);
rowCount += 1
For i As Integer = 1 To dddd.Columns.Count
' Add the header the first time through
If rowCount = 2 Then
'ws.Row(1).Style.Fill.BackgroundColor.SetColor(Color.Azure)
ws.Row(1).Style.Font.Bold = True
'ws.Row(1).Style.Fill.BackgroundColor.SetColor(Color.AliceBlue)
' ws.Row(1).Style.Color = "#FFFFFF"
If dddd.Columns(i - 1).ColumnName = ("ID") Then
'ws.Cells(1, i).Value = dddd.Columns(i - 1).ColumnName
ElseIf dddd.Columns(i - 1).ColumnName = ("Plant_Description") Then
ws.Cells(1, i).Value = "Plant"
ElseIf dddd.Columns(i - 1).ColumnName = ("Report_No") Then
ws.Cells(1, i).Value = "Scrap Number"
ElseIf dddd.Columns(i - 1).ColumnName = ("Req_Emp_Name") Then
ws.Cells(1, i).Value = "Originator"
ElseIf dddd.Columns(i - 1).ColumnName = ("ScrapItem_Desc") Then
ws.Cells(1, i).Value = "Item"
ElseIf dddd.Columns(i - 1).ColumnName = ("Info_ID") Then
ws.Cells(1, i).Value = "NO"
ElseIf dddd.Columns(i - 1).ColumnName = ("Itemdesc") Then
ws.Cells(1, i).Value = "ItemDesc"
ElseIf dddd.Columns(i - 1).ColumnName = ("Part_No") Then
ws.Cells(1, i).Value = "Part No"
ElseIf dddd.Columns(i - 1).ColumnName = ("quantity") Then
ws.Cells(1, i).Value = "Quantity"
ElseIf dddd.Columns(i - 1).ColumnName = ("STD_Cost") Then
ws.Cells(1, i).Value = "UnitPrice"
ElseIf dddd.Columns(i - 1).ColumnName = ("Total_Cost") Then
ws.Cells(1, i).Value = "UnitTotal"
ElseIf dddd.Columns(i - 1).ColumnName = ("Close_DateTime") Then
ws.Cells(1, i).Value = "Close Date"
ElseIf dddd.Columns(i - 1).ColumnName = ("Doc_Create_Date") Then
ws.Cells(1, i).Value = "Submit Date"
Else
ws.Cells(1, i).Value = dddd.Columns(i - 1).ColumnName
End If
End If
ws.Column(i).AutoFit()
'ws.Column("ID").Hidden = True
'THIS IS THTE PROBLEM
'Dim hyperlink As String = "<a href='~/Documents/DownloadFile.aspx?id=" + rw("ID").ToString() + "'>" + rw("ID").ToString() + "</a>"
'ws.Cells(i, 7).Hyperlink = New Uri(hyperlink, UriKind.RelativeOrAbsolute)
'ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
'Dim hyperlink As String = [String].Format("http://{0}/Documents/DownloadFile.aspx?id={1}", Page.Request.Url.Host, rw("ID").ToString())
'ws.Cells(rowCount, i).Hyperlink = New Uri(hyperlink, UriKind.Absolute)
'ws.Cells(rowCount, i).Value = rw("Drawing Id")
If dddd.Columns(i - 1).ColumnName.ToString() = "Month" Then
'var hyperlink = String.Format("Http://" + Page.Request.Url.Host + "/Documents/DownloadFile.aspx?id={0}", rw["DocPk"].ToString());
Dim hyperlink = [String].Format("your url" + "{0}", rw("ID").ToString())
ws.Cells(rowCount, i).Hyperlink = New Uri(hyperlink, UriKind.RelativeOrAbsolute)
ws.Cells(rowCount, i).Style.Font.UnderLine = True
ws.Cells(rowCount, i).Style.Font.Color.SetColor(System.Drawing.Color.Blue)
ws.Cells(rowCount, i).Value = rw("Month")
Else
If dddd.Columns(i - 1).ColumnName = ("ID") Then
ElseIf dddd.Columns(i - 1).ColumnName = ("Plant_Description") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("Report_No") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("Req_Emp_Name") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("ScrapItem_Desc") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("Info_ID") Then
ws.Cells(rowCount, i).Value = Convert.ToInt32(rw(i - 1).ToString())
ElseIf dddd.Columns(i - 1).ColumnName = ("Itemdesc") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("Part_No") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("quantity") Then
ws.Cells(rowCount, i).Value = Convert.ToDecimal(rw(i - 1).ToString())
ElseIf dddd.Columns(i - 1).ColumnName = ("STD_Cost") Then
ws.Cells(rowCount, i).Value = Convert.ToDecimal(rw(i - 1).ToString())
ElseIf dddd.Columns(i - 1).ColumnName = ("Total_Cost") Then
ws.Cells(rowCount, i).Value = Convert.ToDecimal(rw(i - 1).ToString())
ElseIf dddd.Columns(i - 1).ColumnName = ("Close_DateTime") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
ElseIf dddd.Columns(i - 1).ColumnName = ("Doc_Create_Date") Then
ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
Else
ws.Cells(1, i).Value = dddd.Columns(i - 1).ColumnName
End If
'ws.Cells(rowCount, i).Value = rw(i - 1).ToString()
End If
Next
Next
Dim Result As New MemoryStream()
Excelv.SaveAs(Result)
Response.ClearContent()
Response.OutputStream.Write(Result.GetBuffer(), 0, Result.GetBuffer().Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Dim byteArray As Byte() = Result.ToArray()
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx")
Response.AddHeader("Content-Length", byteArray.Length.ToString())
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.BinaryWrite(byteArray)
Response.[End]()
End Using