0

I am having issues with the special CSV interpreter (no idea what its called) on iPad mobile browser.

iPad appears to reserve the character " as reserved or special. When this character appears the string is treated as a literal instead of seperated as a CSV.

INPUT:

1111,64-1111-11,Some Tool 12", 112233

Give the input above, the CSV mobile-safari display shows ([] represents a column)

[1111] [64-1111-11] [Some Tool 12, 112233]

Note that the " is missing. Also note that 112233 is not in its own column like it should be.

Question 2:
How can I get the CSV display tool in safari to not treat a six digit number as a phone number?

1234567

Shows up as a hyperlink and asks to "Add Contact" when I click it. I do not want the hyperlink.


UPDATE
iPad is ignoring the escape character (or backslash is not the escape character) for double quotes in CSV files. I am looking at the hex version of the file and I have

\" or 5C 22 (in hex with UTF-8 encoding).

Unfortuntely, the iPad displays the backslash and still treats " as a special character, thereby corrupting my data formatting. Anybody know how I can possibly use " on iPad CSV?

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • What is it that you are trying to do with CSV files? – Moshe Jun 24 '11 at 19:41
  • @Moshe - There is a button on a webpage that exports a grid to a CSV file. On the desktop the button exports to excel (windows only). On the iPad they are just supposed to display on screen. – P.Brian.Mackey Jun 24 '11 at 19:43

1 Answers1

1

With regards the quotes, have you tried escaping them in the output?

EDIT: conventional escaping doesn't work for CSV files, my apologies. Most specifications state the following:

Fields that contain a special character (comma, newline, or double quote), must be enclosed in double quotes.

So, testing this on your CSV snippet, a file formatted like this:

1111,64-1111-11,"Some Tool 12""", 112233

or even like this:

1111,64-1111-11,Some Tool 12"""", 112233

… opens in Mobile Safari OK. How good or bad that looks in Excel you'd need to check.

Moving to the second issue, to prevent Mobile Safari from presenting numbers as phone numbers, add this to your page's head element:

<meta name="format-detection" content="telephone=no" />
Ben
  • 7,548
  • 31
  • 45
  • @Ben Poole - What is the escape character? Second, how can I use an escape character without messing up Internet Explorer's interpretation? – P.Brian.Mackey Jun 24 '11 at 16:03
  • Typically you have to "escape" things like quotes in order for parsers to work properly. Normally, escaping quotes is done with a backslash like so: `\"` – Ben Jun 24 '11 at 17:32
  • @Ben Poole - I added `\\` preceding the double quotes, but it still treats the double quotes as if there was no escape. It displays the escape character as well. There is something on the internet regarding "smart quotes" on iPad and how they are difficult to manage and cannot be disabled. I wonder if this is what I am experiencing...? – P.Brian.Mackey Jun 24 '11 at 19:05
  • Smart quotes are something else, don't worry about that. I checked some CSV specs, and a backslash doesn't cut it for escaping double-quotes—I led you up the garden path there, sorry. I've updated my answer as there's a different way of dealing with double quotes. – Ben Jun 24 '11 at 19:51
  • @Ben Poole - `"""` is not working either. Still treats quotes as a special character. Also, this solution does not work with iPad and Desktop Excel csv interpretation. – P.Brian.Mackey Jun 28 '11 at 16:41
  • Escaping the **full field** works OK in Mobile Safari (see my answer), but YMMV in Excel and co. It's not ideal I agree: possible issue to report for iOS? – Ben Jun 28 '11 at 17:55
  • @Ben Poole - You are right. It takes 4 quotes to display 1 quote. `""""` works. This is a catch22 - I can only get this to work in Excel or iPad. So hm...yea I guess I'll just write this two different ways. Use javascript to detect the OS and escape accordingly. – P.Brian.Mackey Jun 28 '11 at 18:33
  • I'm beginning to wonder if this is Safari reading the file or this Quickoffice program I have installed. – P.Brian.Mackey Jun 28 '11 at 19:14
  • Nevermind. not quickoffice. Safari presents an option to "Open with Quickoffice" while displaying the CSV – P.Brian.Mackey Jun 28 '11 at 19:24
  • Yes, with things like CSV files, Mobile Safari will offer an option to open them in an app, and that app changes depending on what you have installed on your device. It will be how the file is rendered by Safari therefore, rather than how the target app processes it. – Ben Jun 28 '11 at 20:48