-1

I am wring a csv file with some program.

I am facing a issue when I open it in the excel file and for some column if it exceeds the value more than 256 it automatically truncate it.

I learnt that by default the excel has number format TO 'GENERAL' if I could set it to 'TEXT' then it wouldn't truncate any part.

So is there any programmatic way which can set the number format from GENERAL to TEXT.

1 Answers1

0

is a plain text format. You can't embed meta-data such as column handling into that file format.

If you don't want to truncate the column, then you'll need to truncate it yourself when you write out the file:

 var csvFileBuffer = new StringBuilder();

 var columns = new List<string>();

 csvFileBuffer.AppendLine(
     string.Join(
         ",",
         columns.Select(s => 
              //truncate column header (change logic as appropriate)
              s.Substring(0, 255))));

That said, there may be an option you can set in which will change the default column type for a csv file. However, that would be a question for SuperUser.com

The other option is to write out to a native excel file format, such as xlsx. There are a number of tools you can use to this, such as the Open Xml Sdk.

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123