1

I export data from datagrid to Excel and one column with numbers is with error 'numbers stored as text'. I am trying to convert them using following code, but its not working. Could you suggest?

The problem is that then column headers are moved up and data is broken.

  worksheet.Range["E5", "E5"].EntireColumn.TextToColumns();
  worksheet.Columns[5].NumberFormat = "# ##0,00";

Problem shown

3
  • Store numbers not text to begin with. You aren't exporting to Excel with this code, you're using Excel Interop to actually start Excel and set values to fields. Instead of storing text to those values, store numbers - ints, decimals, doubles Commented Dec 12, 2019 at 8:11
  • You didn't post the code that actually sets the values though Commented Dec 12, 2019 at 8:11
  • This link may help you. cell in Excel “Number stored as text” Commented Dec 13, 2019 at 1:58

1 Answer 1

1

This code converts numbers stored in text format to number format. If you want to use it to opposite direction set the fieldinfo to { 1, 2 }.

Range rng = Worksheet.Range["A1:A10""];

rng.TextToColumns(rng, XlTextParsingType.xlDelimited, XlTextQualifier.xlTextQualifierDoubleQuote, Tab: true, FieldInfo: new int[] { 1, 1 }, TrailingMinusNumbers: true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.