Excel Export: How to set cell format to "Text"?

2
How do I set exported Excel cell format, from "General", to "Text"? I have cell values with numeric string data (e.g., "0123456789"). When I open the exported Excel file, I want Excel to display the cell format type as "Text". If left as type "General", the Excel export seems to turn the value into scientific notation and/or drops the leading zero. What I've tried: 1. oSheet.Item(iRowIterator, iColumnIterator).NumberFormat = ExcelFormatType.Text 2. oSheet.Item(iRowIterator, iColumnIterator).NumberFormat = "Text" Results: 1. Sets NumberFormat to string "2"; Excel export shows format type = "Number" and value displayed as "0123456789.00" 2. Sets NumberFormat to string "Text"; Excel export shows format type = "Number" and value displayed as "0123456789.00" Thank you
 
asked 11/13/2018 7:13:05 PM
  It appears using setter "Text" instead of setter "Value" works (note: it seems to work even if NumberFormat left as default "General"): oSheet.Item(iRowIterator, iColumnIterator).Text = "0123456789" When I open the exported Excel file, it shows the Cell format as "General", but it displays as I want, with green triangle warning "The number in this cell is formatted as text or is preceded by an apostrophe". iokevins 11/13/2018 7:36:28 PM
add a comment

0 Answers

Your Answer

Not the answer you're looking for? Browse other questions tagged excel or ask your own question.