0

I've inherited a project at work recently that was written by one of our less skilled interns. It's fairly straightforward in theory; it just needs to export some data from a server to a CSV file for a vendor.

The problem is that our vendor needs to have all fields, not just ones with commas in them, encapsulated in quotes. Aspose Cells seems to have some form of automatic encapsulation on fields with commas, but not all fields.

The original programmer made their own method that applies quotes to all fields before exporting, but the file ends up with triple quotes around all fields. To counter this, they wrote another function that re-opens the file and replaces all triple quotes with a single.

I know that there are delimiter options for text files, but I can't find anything about changing the encapsulation in Aspose.

So my question is, are they other ways to handle this that are better than making two passes like it does currently?

Update: Aspose has responded to my post on their forum and they say they will be adding a property to the TxtSaveOptions class to support this functionality. I'll update again if/when that happens with specifics.

Logarr
  • 2,120
  • 1
  • 17
  • 29
  • At what point in the sequence are quotes added? If you can see where Apose adds quotes, simply earmark those fields as ones which should not be wrapped, then encapsulate the rest of the fields... – Chris Jun 12 '12 at 17:17
  • Aspose adds the quotes during the actual save process. Based on what I see on their forums it auto-encapsulates any string field, so any quotes I add will result in a triple quote situation. – Logarr Jun 12 '12 at 17:28

1 Answers1

1

In Aspose.Cells for .NET v7.2.2 they have added a new property to TxtSaveOptions called AlwaysQuoted.

Here's a sample of how to use this property during the save:

var options = new TxtSaveOptions(SaveFormat.CSV) {AlwaysQuoted = true};
workBook.Save(@"C:\Export Location\"), options);

Setting the property to true will encapsulate all fields, regardless of content. The default setting is to mimic the CSV standard as Excel would.

Logarr
  • 2,120
  • 1
  • 17
  • 29