How do I surround my text columns in quotes when exporting to csv. All 3 columns are text.
var i = workbook.Worksheets.Add();
var worksheet = workbook.Worksheets[i];
worksheet.Cells[“A” + j].PutValue(DETAIL_DATA_TYPE);
worksheet.Cells[“B” + j].PutValue(details.RoutingNumber);
worksheet.Cells[“C” + j)].PutValue(details.CustomerId);
workbook.Save(Path.Combine(filepath, fileName), SaveFormat.CSV);
Thank you,
Marcie
Hi,
Thanks for your posting and considering Aspose.Cells for .NET.
If your text contains an apostrophe ", then your text will be surrounded by " ", otherwise not.
Please see the code below and the output csv file screenshot as shown in notepad.
C#
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//A1 and B1 contains " character
//so their values will be surrounded by quotes
worksheet.Cells[“A1”].PutValue(“Hello"Aspose”);
worksheet.Cells[“B1”].PutValue(“Hi"Aspose”);
workbook.Save(@“F:\Shak-Data-RW\Downloads\output.csv”);
Screenshot:
I have some clarification for what was really being asked by the OP.
Hi,
I understand that Aspose.Cells mimics Excel, which is great since it’s built around working with Excel files. The files I’m getting are exactly like how Excel would create them, but these files are not going to be read into Excel.
Hi,
We will add a property in TxtSaveOptions to support your need.
Your issue has been logged as CELLSNET-40746.
The issues you have found earlier (filed as CELLSNET-40746) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Hi,
For this requirement, please use the new property:
TxtSaveOptions.AlwaysQuoted = true;
With this setting the values in exported csv will all be quoted.
TxtSaveOptions.AlwaysQuoted = true;