Comments (7)
Can you provide a fully working example that outputs the double value with a prepended ' ? The following works fine for me, with no prepended '
void Main()
{
var values = new List<Foo>{
new Foo { Id = 1, DoubleValue = 48.897736484133866 },
new Foo { Id = 2, DoubleValue = 0.1000294643384941 },
};
var csv = new CsvWriter(Console.Out, CultureInfo.InvariantCulture);
csv.WriteRecords(values);
}
public class Foo
{
public int Id { get; set; }
public double DoubleValue { get; set; }
}
from csvhelper.
void Main()
{
await using var memoryStream = new MemoryStream();
await using var streamWriter = new StreamWriter(memoryStream);
using var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture);
csvWriter.Configuration.RegisterClassMap<RowMap>();
var csvRows = new List<Row>() { new Double(1076.5525217894019), new Double(37071.25726283525) }
csvWriter.WriteRecords(csvRows);
await streamWriter.FlushAsync();
var csvArray = memoryStream.ToArray();
return new Response(csvArray, "heat-loss.csv");
}
public class Row
{
public double Double { get; }
public Row(double double){
Double = double;
}
}
public sealed class RowMap : ClassMap<Row>
{
Map(m => m.Double).Name("Double")
}
I'm sorry if this not quite working (I've got a lot of work to be getting on with today), but this is roughly how it is in our system. We are using v 30.0.1
from csvhelper.
I wasn't setup to return new Response
so I just wrote the MemoryStream
to a FileStream
. I still can't recreate the prepended ' that you are getting. There has to be something else going on here.
async void Main()
{
await using var memoryStream = new MemoryStream();
await using var streamWriter = new StreamWriter(memoryStream);
using var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture);
csvWriter.Context.RegisterClassMap<RowMap>();
var csvRows = new List<Row>() { new Row(1076.5525217894019), new Row(37071.25726283525) };
csvWriter.WriteRecords(csvRows);
await streamWriter.FlushAsync();
using (FileStream file = new FileStream(@"C:\Temp\heat-loss.csv", FileMode.Create, FileAccess.Write))
{
memoryStream.WriteTo(file);
}
}
public class Row
{
public double Double { get; }
public Row(double value)
{
Double = value;
}
}
public sealed class RowMap : ClassMap<Row>
{
public RowMap()
{
Map(m => m.Double).Name("Double");
}
}
from csvhelper.
@AltruCoder Try using a negative value - it is adding the escape character ' because the negative value starts with - (I have a feeling they may be using InjectionOptions = InjectionOptions.Escape)
from csvhelper.
@ajorkowski I do see where you can get the ' character if the value is negative and you set InjectionOptions = InjectionOptions.Escape
. The problem is @JackMcBride98 made no mention of either of those things being the case.
from csvhelper.
Is this still an issue?
from csvhelper.
Not as far as I'm aware
from csvhelper.
Related Issues (20)
- [Feature] Deserialise into named tuple
- Custom Type Converter page should include an example of using type converter constructor arguments
- Microsoft.Bcl.AsyncInterfaces dependency issue HOT 9
- Unexpected behaviour when using multiple character newline HOT 2
- Add ability to read empty string as 0 (or other default value) for non-nullable types
- Skip rows from csv file arbitrary rows HOT 4
- CsvDataReader - cant read with columnName when using custom SchemaTable HOT 3
- CountBytes does not correctly count bytes when IgnoreBlankLines is enabled. HOT 1
- Incorrect array length determination in ByteArrayConverter.HexStringToByteArray
- Build error - HOT 3
- New compatibility issue regression due to `System.Linq.Async` inclusion HOT 5
- Microsoft.Bcl.AsyncInterfaces dependency error on System.Threading.Tasks.Extensions HOT 4
- ConfigurationException: 'Types that inherit IEnumerable cannot be auto mapped' when using custom class based on DynamicObject (NOT ExpandoObject) which also implements IDictionary HOT 3
- Missing "Product Version" in CsvHelper.dll HOT 1
- Column Name not displaying Using Mapping HOT 1
- Just thrown new exception by choice.
- Unexpected `InvalidCastException` in `TypeConverter<>` with nullable structs and value types HOT 2
- List<T>.ToAsyncEnumerable not accessible anymore after upgrade to CSVHelper 31.0.2 (.NET 8) HOT 5
- Set Custom Headers that derives from the property value. HOT 7
- Eliminate the columns if empty HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csvhelper.