Checking if XLS or DOC is able to open in Mac

nothing wrong with shell command at all… i can make use of that… look for microsoft.word and microsoft.excel in the shell result.

thanks Dave…

and don’t forget NUMBERS can open XLS and PAGES can open DOC (so can TextEdit I believe)

the doc and xls document is not really real doc and xls files. Instead it is html file with the extension change and with information as content=“text/html” change to application/msword or application/vnd.ms-excel. it is to enabled my html report to able to open in excel and word.

I try opening my xls in html format using Apple Numbers and all i see is the html code instead of the spreadsheet.

[quote=27088:@Norman Palardy]Why bother ?
Really … if you have an excel file use f.Launch & the users preferred app will open it. (They could actually designate to open all Excel files with Numbers for instance)[/quote]

I understand he wants the option to be disabled or invisible if the file can’t be opened by the system.

[quote=27259:@Richard Duke]the doc and xls document is not really real doc and xls files. Instead it is html file with the extension change and with information as content=“text/html” change to application/msword or application/vnd.ms-excel. it is to enabled my html report to able to open in excel and word.

I try opening my xls in html format using Apple Numbers and all i see is the html code instead of the spreadsheet.[/quote]

You don’t have an xls in html format, you have a text file with HTML code and an xls extension. I know this sounds like nitpicking but calling that file “an xls file” is what’s provoked quite a bit of confusion. It isn’t an XLS file any more than renaming an mp4 with a TXT extension makes it a text file.

The old HTML Table with .XLS extension. This horrible, horrible hack has been so abused (and recommended) over the years I no longer fight it. It’s really, really, bad form, though and in the end it gives more errors than it’s worth, on the long run. It goes against what extensions and formats are supposed to be and takes advantage of an actual bug in Excel (where Excel will ignore the file extension and just intepret the contents).

One of the biggest problems with the approach is that HTML tables are not true Excel tables, so formats (dates, decimals, etc.) are lost and when converting into actual XLS some cells don’t behave normally (numbers treated like text, etc).

I assume you don’t have an option here to use real excel files, but perhaps you can check the contents of the file and decide if it’s an HTML table then Excel should be used and, if not, give an error (insteaf of letting Numbers or LibreOffice or Mariner Spreadsheet open it).

Launch Services through declares or MBS plugin doing the same seem to be the only way

https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-SW4

ok… i should have say that in the first place, Eduardo.

The problem i encounter when saving the html as doc or xls extension and opening them is when i open a html with images, which show up fine in htmlviewer (which has been scaled) will show up in doc or xls as the original size image making the whole thing look really weird and alignment go really crazy. But for report with just text, it show up just find. And if you want to make sure number show up probably on the left aligned, i put an extra nbsp after the number.

While officially it is XML and not HTML… please find and read Microsofts own EXCEL documents…
It is entirely possible to create a “legal” 100% Excel compatible document in TEXT format (ie. XML)
but it really should contain the proper header and tag information.

I have processes at work where “Excel” spreadsheets are created on a UNIX computer (database server) by writing them as XML, this is then passed to a WIndows Application server where a call is made to an EXCEL API to simply “resave” the XML into XLS format, after which they are distributed to clients around the country who have no issue treating them as if EXCEL itself had created them. I create 300+ sheets in about an hour…each sheet (or workbook) sometimes exceeding 100,000 lines.

the feature i have is just to export the html report in htmlviewer to be view in excel or word. So don’t think my application need to be making a real Word or Excel document.

You could use

LaunchServicesDefaultRoleHandlerForContentTypeMBS(“com.microsoft.word.doc”, 2)

to find out the role handler for a word document.

Than you can find the application file:

LaunchServicesFindApplicationForInfoMBS("",“com.microsoft.word”,"")

[quote=27287:@Dave S]While officially it is XML and not HTML… please find and read Microsofts own EXCEL documents…
It is entirely possible to create a “legal” 100% Excel compatible document in TEXT format (ie. XML)
but it really should contain the proper header and tag information.[/quote]

This is correct, but there’re so many sites recommending to take advantage of Excel’s bug in accepting an HTML table and it’s so easy to create and style them, that people base entire workflows in this and then have a huge problem when they turn out to be less than optimal.

In our case, a solution that used this was introducing minute errors because numbers and dates aren’t properly interpreted so thousands separator may be recognized like a decimal (or not at all) and dates in dd/mm may be recognized as mm/dd (depends on the local regional settings).

It took me months to replace all routines that saved HTML tables with an XLS extension into proper XLS or XLSX (the XML format) files, but so many weird bugs disappeared it was well worth it.

You could export them as the format they are, .html, and have the user open them in either a web browser, excel or word (all of which can open .html files).

Sadly, no browser on any platform is able to do what mime types should be able to do, which is define both a format and a handler. If they could, you should be able to to “text-html/msword” on an .html file and have it open in Word.

Heck you can even get some code that writes the XML format for free on my web site :stuck_out_tongue:

It probably needs an update since it writes a fairly old xml format

[quote=27326:@Christian Schmitz]You could use

LaunchServicesDefaultRoleHandlerForContentTypeMBS(“com.microsoft.word.doc”, 2)

to find out the role handler for a word document.

Than you can find the application file:

LaunchServicesFindApplicationForInfoMBS("",“com.microsoft.word”,"")[/quote]

why do i need to do the LaunchServicesDefaultRoleHandlerForContentTypeMBS(“com.microsoft.word.doc”, 2) first before doing the LaunchServicesFindApplicationForInfoMBS("",“com.microsoft.word”,"")??