We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Format a cell as Text

How can I ensure a string entered into a cell is treated as text? Is there an opposite to using NumberFormat where I can specify a range can be formatted as Text?

I'm successfully populating spreadsheet with data from a database. The number and type of columns vary so I've created a simple xls file to use as a template which I then fill using markers.

Occasionally an field might contain a string such as '5E1' or '5PM', which excel tries to interpret as a number or a date.

In Excel the only way to overcome the problem is to format a cell as Text before typing in the string, and I've tried formatting all the cells in my template to Text, but after importing the data, it a cell containing '5E1' will have been reformatted as a number, so I think I need to actively do something using XlsIO to force it to treat something as text.

Any ideas would be appreciated

5 Replies

GM Geetha M Syncfusion Team September 16, 2009 01:14 PM UTC

Hi Giles,

I was able to see the problem. I am currently working on this and will get back to you by tomorrow.

Regards,
Geeta


GB Giles Billingsley September 17, 2009 05:13 PM UTC

Thanks. I've now got around this issue by looping through the rows, after I've filled the sheet with data, and setting the '.Text' of the offending cell to the value I want treated as text, and then I can also set '.IgnoreErrorOptions = ExcelIgnoreError.All' to stop the number-as-text green arrow appearing on the cell. It works fine, but it would be nice for all that to happen as part of ApplyMarkers.


GM Geetha M Syncfusion Team September 18, 2009 10:02 AM UTC

Hi Giles,

Thank you for the detials.

You may also set the number format for the variable cell as Text and use insert:copystyles as marker argument. This will copy the styles from the previous row while applying marker.

%Customers.CompanyName;insert:copystyles

You can refer to our documentation in the link below.
http://help.syncfusion.com/ug/asp.net/xlsio/Documents/templatemarkers.htm

Please try this and let me know if you have any questions.

Regards,
Geetha


PR Padma Rajagopal April 1, 2013 02:00 PM UTC

Hi

This solution of setting number format of the cell to text, still wouldn't work. Is there a way of applying "text" format using ApplyMarkers method? I don't want to loop through each cell & setting its "text" property value.

Also, this link doesn't work anymore  - http://help.syncfusion.com/ug_73/xlsio/TemplateMarkers.html

Thanks
Padma


MM Manikandan M Syncfusion Team April 5, 2013 04:40 AM UTC

Hi Padma,


Thank you very much for your patience.

We are afraid that we are not able to reproduce the issue "Setting the number format to 'text' format and then applying the template marker does work" from side. We have created the simplified sample to apply the number format to 'text' and applying the template marker with 'copystyles' option. We have shared the sample below. Please make use of this and let us know if this helps you.

Also we have shared the updated online help link of template marker below.
http://help.syncfusion.com/ug/asp.net/xlsio/default.htm#!Documents/templatemarkers.htm

if you still reproduce the issue, please modify the above sample to reproduce the issue and revert back us with the same. it would help us to investigate further on this.

Please let us know if you need any clarifications.

Thanks,
Manikandan M.


TemplateMarker_484c6e73.zip

Loader.
Live Chat Icon For mobile
Up arrow icon