Text surrounded by quotes

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.


What we’re wondering is how to encapsulate ALL fields during a save to CSV in quotes. Not just fields that contain commas or quotes, but all fields.

If you manually encapsulate fields that do not contain those characters Aspose will place extra quotes around those fields, rather than see that they’re already encapsulated and ignore them.

Is it possible to either disable the automatic encapsulation, or to change it so it does it for every field?

Hi,


Aspose.Cells follows MS Excel standards for generating CSV files. You may manually check it in MS Excel. If you find any difference, please create your desired sample CSV file manually in MS Excel and attach it here. Also, attach the file generated by Aspose.Cells with sample code. We will check how to create your desired CSV file using Aspose.Cells.

Thank you.

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.


An outside vendor will be collecting these files and importing the data into their system. One of the requirements they’ve given us is that all fields are surrounded by "s not just fields with commas or quotes in them. I don’t exactly see why they need it that way, but they do.

There’s a workaround in place for this problem, but its quite messy and runs rather slowly compared to my other Aspose.Cells using programs. If there’s some other format that I can use to have more control over the quotes, and be able to just change the extension to “.csv” that should be good enough.

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;


How can use this can you please provide me some sample or example ?

Greatly Appreciate Thanks
Hi,

In the new versions/fixes e.g v7.3.0.6: Aspose.Cells for .NET v7.3.0.6 you have to use QuoteType property, see the following sample code below.

Sample code:

Workbook workbook = new Workbook("e:\\test2\\quoteTest.xlsx");
TxtSaveOptions options = new TxtSaveOptions(SaveFormat.TabDelimited);
options.QuoteType = TxtValueQuoteType.Always;
workbook.Save("e:\\test2\\quotedTest.txt", options);


Thank you.