gridview データを Excel ファイルにエクスポートしています。正常にエクスポートされていますが、小さなエラーが 1 つあります。グリッドビューでは、1 つの列に特殊文字が含まれており、正常に印刷されていません。
エクスポートするコード:
Private Sub exportToExcel(ByVal exportFull As Boolean)
'------------------------------------------------------------------------------------------------------------
Response.Clear()
Response.Buffer = True
Dim fileName As String = "Replacement_" + Convert.ToString(DateTime.Now.Day) + "_" + Convert.ToString(DateTime.Now.Month) + "_" + Convert.ToString(DateTime.Now.Year) + ".xls"
Response.AddHeader("content-disposition", "attachment;filename=" + fileName)
Response.Charset = "UTF-8"
Response.ContentType = "application/vnd.ms-excel"
Dim strWrite As New StringWriter()
Dim htmlWrite As New HtmlTextWriter(strWrite)
Dim htmlfrm As New HtmlForm()
'------------------------------------------------------------------------------------------------------------
'Hide button columns from the grid to avoid them to export to excel file.
grdReplacementList.HeaderRow.Style.Add("background-color", "#FFFFFF")
grdReplacementList.HeaderRow.Cells(1).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(2).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(3).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(4).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(5).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(6).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(7).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(8).Style.Add("background-color", "#A4A4A4")
grdReplacementList.HeaderRow.Cells(9).Style.Add("background-color", "#A4A4A4")
grdReplacementList.Columns(grdReplacementList.Columns.Count - 1).Visible = False
grdReplacementList.Columns(0).Visible = False
If (Not exportFull) Then
For i As Integer = 0 To grdReplacementList.Rows.Count - 1
Dim row As GridViewRow = grdReplacementList.Rows(i)
If row.RowType = DataControlRowType.DataRow Then
Dim chkProperty As CheckBox = DirectCast(row.Cells(0).FindControl("chkReplacementItem"), CheckBox)
If (Not chkProperty.Checked) Then
row.Visible = False
Else
row.Visible = True
row.BackColor = System.Drawing.Color.White
End If
End If
Next
End If
'------------------------------------------------------------------------------------------------------------
grdReplacementList.Parent.Controls.Add(htmlfrm)
htmlfrm.Attributes("runat") = "server"
htmlfrm.Controls.Add(grdReplacementList)
htmlfrm.RenderControl(htmlWrite)
Response.Write(strWrite.ToString())
Response.Flush()
Response.[End]()
End Sub
#End Region
出力:
Address: Component: Replaced/Installed: Replacement Due: Last Stock Survey: Appointment Status: Appointment Date: Total:
41 St Katherines Court Dodman's Close Bathroom 1950 2034 To be Arranged - £7,000
41 St Katherines Court Dodman's Close Bathroom 1984 2034 To be Arranged - £7,000
41 St Katherines Court Dodman's Close Bathroom 1984 2034 To be Arranged - £7,000
最後の列は £ を印刷していますが、「£」のみを印刷したいのですが、何が間違っているのか教えてください。