I have a WPF that reads an excel file and removes hidden characters and writes the data as pipe delimited to a text file. Works pretty good. Now I am trying to keep the cell formatting that excel has. For test purposes I have a zip code field in excel. The cell has value 047300134 and a custom format of 00000-0000. I would like the data written to be 04730-0134. The only process I saw that using String.Format. Here is how I tried to code it.
dfCellFormat = range[NumRow, lngColCnt].DisplayFormat;
strNumberFormat = dfCellFormat.NumberFormat;
strCellData = Convert.ToString(values[NumRow, lngColCnt]);
strNumberFormat = "{0:" + strNumberFormat.Replace("0","#") + "}";
strCellData = String.Format(strNumberFormat, strCellData);
The result is just 047300134, the format is not applied.
Is there a way to accomplish what I am trying to do?
Thank you