0

Using Aspose.Cells I need a csv file with my terms wraped between double quotes. For some reason the terms after the first column are surrounded by triple double quotes when saving my csv file, like: """term"""

This is my code:

WorkbookDesigner wd = new WorkbookDesigner();
wd.Workbook.Initialize();
Worksheet sht = wd.Workbook.Worksheets[0];
string value = "term";
value = string.Format("\"{0}\"", value);
sht.Cells[row + rowOffset, column].PutValue(value);
wd.Save(fileLoc, FileFormatType.CSV);

I'm using Aspose.Cells version 4.8.0.0

Rafael
  • 1,099
  • 5
  • 23
  • 47

2 Answers2

0

In CSV, the escape sequence for the quote character is 2 quote characters.

You are writing the value "term" (with quotes). Because of that (your value has quotes), the library will enclose the value with quotes, so you will end up with """term""".

To make it less confusing and more visible, try writing the value: some " term ": blah. This should be printed as:

"some ""term"": blah"

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29
0

If you want to get a CSV file with your term as

"term"

then you should save it in your CSV file as

"""term"""

Please type

"""term"""

in a notepad and save it as .csv file. Now open it in Microsoft Excel and see its value, you will find it is displayed as

"term"

Note: I am working as Developer Evangelist at Aspose

shakeel
  • 1,717
  • 10
  • 14
  • Well the whole point of using Aspose is that I don't need to create a text file and convert it to csv, do you have any other alternatives? – Rafael Jun 22 '15 at 02:24
  • As mentioned by the other user Jeronimo, the escape sequence for the quote character is 2 quote characters. Aspose.Cells is doing the same thing. I have tested it with the following sample code Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets[0]; Cell cell = worksheet.Cells["A1"]; cell.PutValue("\"term\""); workbook.Save("output.csv", SaveFormat.CSV); Now, if you open the output.csv in Microsoft Excel, you will see "term" and if you open it in a notepad, you will see """term""" – shakeel Jun 23 '15 at 08:54
  • So the only difference between your code and mine is SaveFormat.CSV instead of FileFormatType.CSV? – Rafael Jun 23 '15 at 09:30
  • @RafaelDiaz both codes are exactly same and will generate the same CSV file. So there is no difference in your code and my code. – shakeel Jun 25 '15 at 15:01