Remove leading and trailing apostrophes in Excel export

Remove leading and trailing apostrophes in Excel export

kkittell518kkittell518 Posts: 25Questions: 8Answers: 0
{
                extend: 'excel',
                exportOptions: { orthogonal: 'export' }
}

In one of my columns, I may have values such as Farmer's Composit or 'Farmer's Special' or Farmer. A user has asked if when it is exported to Excel that the leading and trailing apostrophes are stripped off. I can't get rid of all apostrophes. I'm already using orthogonal for export (kind of fuzzy what it's actually doing for me), and I wondered if there's something I can put into the extend excel so that I'd just get Farmer's Special and not 'Farmer's Special' on export.

Test case, go to https://npgsweb.ars-grin.gov/gringlobal/search click on "advanced search" and in plant name, type farmer's.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406
    edited March 2023 Answer ✓
    exportOptions: {
        format: {
            body: function ( data, row, column, node ) {
                return something;
                //replace html tags with one space
                // return data.replace(/<[^>]*>/g, ' ');
            }
        }
    }
    

    Just replace "something" with something that makes sense. Like in here for example:
    https://stackoverflow.com/questions/42408126/how-can-i-remove-last-and-first-apostrophe-from-string

  • kkittell518kkittell518 Posts: 25Questions: 8Answers: 0

    Thanks.

  • kkittell518kkittell518 Posts: 25Questions: 8Answers: 0
    extend: 'excel',
                      exportOptions: {
                          format: {
                              body: function (data, row, column, node) {
                                  if (column === 18) {
                                      return '';
                                  }
                                  else {
                                      //replace leading and trailing ' for cultivars, and remove html tags
                                      return data.replace(/^'|'$/g, '').replace(/<[^>]*>/g, '');
                                  }
                              }
                          }
                      }
    

    This works perfectly in Chrome and Edge, but not in Firefox. In Firefox, it returned col 18, replaced html (worked) but did not replace leading and trailing '
    Anyone have any idea why this is so?

Sign In or Register to comment.