Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. When string in a cell has double quotes those appear in Excel after export. How do I remove them?

When string in a cell has double quotes those appear in Excel after export. How do I remove them?

Scheduled Pinned Locked Moved ASP.NET
helpquestiondatabasetutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11369001
    wrote on last edited by
    #1

    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

    U Richard DeemingR 2 Replies Last reply
    0
    • U User 11369001

      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

      U Offline
      U Offline
      User 11369001
      wrote on last edited by
      #2

      I still need help with this one please

      1 Reply Last reply
      0
      • U User 11369001

        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

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        You 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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups