4
I am exporting a list to excel, it occurs that in one of the fields, "fiscal note number content" and very large, excel tries to format it, generating special characters.
Is there any way to select the note field and format it?
I’m doing like this:
var data = new[]{
new{ Name="OS", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761322031313787" },
new{ Name="Shyam", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761455322031313322031313" },
new{ Name="Mohan", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761322031313" },
new{ Name="Sohan", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761322031313" },
new{ Name="Karan", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761322031313" },
new{ Name="Brij", Email="[email protected]", ChaveNF="8715421643464674616464646476464646464646761322031313" }
};
private static void CovertToExcel<T>(List<T> data)
{
using (TextWriter output = File.CreateText(@"C:\Users\Public\RelDCL.xls"))
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.DisplayName); // header
output.Write("\t");
}
output.WriteLine();
foreach (T item in data)
{
foreach (PropertyDescriptor prop in props)
{
output.Write(prop.Converter.ConvertToString(prop.GetValue(item)));
output.Write("\t");
}
output.WriteLine();
}
}
}

Show an example
– Leandro Angelo
@Leandroangelo, see an example list with a Chavenf value field
– Harry
okay,
ChaveNFis the typestringcorrect? of what special characters you are talking about that appear in excel?– Leandro Angelo