When string in a cell has double quotes those appear in Excel after export. How do I remove them?
-
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)
'This method exports the resulting query datatable to an instance of Excel using StringWriter
If Not dt Is Nothing Then
Dim sw As New StringWriter()
'Loop through the column names and output those first
For Each datacol As DataColumn In dt.Columns
sw.Write(datacol.ColumnName + vbTab)
Next
Dim row As DataRow
'Loop through the datatable's rows
For Each row In dt.Rows
'Newline between the previous row and the next row
sw.Write(vbNewLine)
Dim column As New DataColumn()
'Loop through each column and write the cell the the stringwriter
For Each column In dt.Columns -
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)
'This method exports the resulting query datatable to an instance of Excel using StringWriter
If Not dt Is Nothing Then
Dim sw As New StringWriter()
'Loop through the column names and output those first
For Each datacol As DataColumn In dt.Columns
sw.Write(datacol.ColumnName + vbTab)
Next
Dim row As DataRow
'Loop through the datatable's rows
For Each row In dt.Rows
'Newline between the previous row and the next row
sw.Write(vbNewLine)
Dim column As New DataColumn()
'Loop through each column and write the cell the the stringwriter
For Each column In dt.ColumnsI still need help with this one please
-
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)
'This method exports the resulting query datatable to an instance of Excel using StringWriter
If Not dt Is Nothing Then
Dim sw As New StringWriter()
'Loop through the column names and output those first
For Each datacol As DataColumn In dt.Columns
sw.Write(datacol.ColumnName + vbTab)
Next
Dim row As DataRow
'Loop through the datatable's rows
For Each row In dt.Rows
'Newline between the previous row and the next row
sw.Write(vbNewLine)
Dim column As New DataColumn()
'Loop through each column and write the cell the the stringwriter
For Each column In dt.ColumnsYou have already posted this in the C# forum: How do I remove double quotes from Excel cell when data is exported to Excel in VB code? - C# Discussion Boards[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer