|I need help to fix an issue where when data from web application is exported to Excel by clicking a button export to excel, if the data in a cell contains double quotes, that data should be displayed without the double quotes visible.
Also I want preceding zeros not to be removed e.g. 081 should not be exported to Excel as 81. This is why I have the line of code sw.Write("=""" & row(column).ToString().Trim() & """" & vbTab)
Previously I made a change to the application code in VB so that the output exports text fields with formulas (="") to force Excel to treat those values as a string. This has been working except some instances where the output actually displays the formula characters (="") within the cell as text, rather than as hidden formulas. It appears when a cell contains text with an actual double quotes that is when after export to Excel is done, those quotes appear in Excel. I need help to figure out if there is a way to suppress those.
For example. A cell with the following data Allows the user the abilities to Add, View, Modify and Delete Notes on the Notes Tab of the Case Record. "View" allows the user to view the Notes Tab of the Case Record.
When this is exported to Excel the data is displayed as follows ="Allows the user the abilities to Add, View, Modify and Delete Notes on the Notes Tab of the Case Record. "View" allows the user to view the Notes Tab of the Case Record. I do not want to quotes to appear in Excel.
On the other hand, a cell with the following data Maintain Victim Classification Types. when this is exported to Excel there are no visible quotes. It displays as Maintain Victim Classification Types.
Here is my VB code that needed changing
Protected Sub WriteToExcelFile(dt As DataTable)
If Not dt Is Nothing Then
Dim sw As New StringWriter()
For Each datacol As DataColumn In dt.Columns
sw.Write(datacol.ColumnName + vbTab)
Dim row As DataRow
For Each row In dt.Rows
Dim column As New DataColumn()
For Each column In dt.Columns
If Not row(column.ColumnName) Is Nothing Then
sw.Write("=""" & row(column).ToString().Trim() & """" & vbTab)
sw.Write(String.Empty + vbTab)
Response.ContentType = "application/vnd.ms-excel"
System.Web.HttpContext.Current.Response.SuppressContent = True
modified 25-Feb-20 10:56am.
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.