How to generate a word file programmatically from collected data in iPhone sdk - iphone

I have an iPhone app consisting of a few forms in which I collect data from users. Now at the end of these forms, after user has filled all data, I want that all the collected data is exported and a MS word .doc file is generated. The data too is not simple text. There are headings, tables along with normal text in it. Is there any way I can accomplish this?

Short answer yes, long answer:
You can't do this to create "proper" Word documents, however you should be able to acomplish this on any platform by building the word doc from HTML and saving it with a .doc extension (instead of HTML). You can put anything in there, custom layouts - I'd probably stick to paragraphs and tables and floated elements (like imgs and such).
There may be extra code you will need in the HTML doc (for instance to make it open in page view rather than in HTML view) but you can figure all that out by saving a word doc in HTML format. :) There's also a lot of information on the internet about it if you know where to look.
I did something like this not long ago. I'll see if I can find an example and post it here.
Update
This is the only "custom" stuff I have in my html word doc:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
And this - to make it open in Page view:
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
</w:WordDocument>
</xml><![endif]-->
The rest of it is just standard HTML and CSS (remember to put CSS INSIDE the HTML document in <style> tags - word isn't going to remotely fetch your css files).

If it is acceptable to be connected when you produce your document, you could use an on-line service like the Docmosis cloud service. It can do the mail merge and deliver the document in various formats. It can be called from iOS.
Hope that helps.

Prepare appropriate html file as per required doc format.
Add this line at the top
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
and save html file as .doc format.
It will resolve your problem.
For more formatting options refer this link.
http://sebsauvage.net/wiki/doku.php?id=word_document_generation

Related

How to remove content between two tags on several files

i want to know how to delete all the content between two tags on several files.
Example:
I have 3 files that have the <head> and </head> tags, but they have different content on them, so i want to remove all the content between that two tags with some kind of tool, plugin, etc.
Is there any program, application or plugin that can do that?
Thank you.
In Notepad++
Use RegExp search and
search for
<head>[^<>]+</head>
replace all with
<head></head>
As #domdom mentioned, you can search through all opened documents.

is there any way to output the html from google chrome developer tools?

I have a website that uses javascript to change the HTML dynamically based on input. I use google developer tools to examine the HTML at any particular moment in the lifetime of the page. Is there any way easy way to output the HTML from the elements tab to a file or to the clipboard (so that I can run it thru a validator for debugging)? Control + A does not allow me to select all of the HTML.
You can Copy the <html> element as HTML:
... but you can do this easier at the console:
copy(document.documentElement.outerHTML);
Note that neither of these will copy the doctype. Also this is the serialization of the live DOM which could be totally different than the markup you served. But you know that.

how to create .doc or word file in iphone by code [duplicate]

I have an iPhone app consisting of a few forms in which I collect data from users. Now at the end of these forms, after user has filled all data, I want that all the collected data is exported and a MS word .doc file is generated. The data too is not simple text. There are headings, tables along with normal text in it. Is there any way I can accomplish this?
Short answer yes, long answer:
You can't do this to create "proper" Word documents, however you should be able to acomplish this on any platform by building the word doc from HTML and saving it with a .doc extension (instead of HTML). You can put anything in there, custom layouts - I'd probably stick to paragraphs and tables and floated elements (like imgs and such).
There may be extra code you will need in the HTML doc (for instance to make it open in page view rather than in HTML view) but you can figure all that out by saving a word doc in HTML format. :) There's also a lot of information on the internet about it if you know where to look.
I did something like this not long ago. I'll see if I can find an example and post it here.
Update
This is the only "custom" stuff I have in my html word doc:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
And this - to make it open in Page view:
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
</w:WordDocument>
</xml><![endif]-->
The rest of it is just standard HTML and CSS (remember to put CSS INSIDE the HTML document in <style> tags - word isn't going to remotely fetch your css files).
If it is acceptable to be connected when you produce your document, you could use an on-line service like the Docmosis cloud service. It can do the mail merge and deliver the document in various formats. It can be called from iOS.
Hope that helps.
Prepare appropriate html file as per required doc format.
Add this line at the top
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
and save html file as .doc format.
It will resolve your problem.
For more formatting options refer this link.
http://sebsauvage.net/wiki/doku.php?id=word_document_generation

IE6 changes DOCTYPE to a bad one

I am working with website that has defined following DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
When I access that website in IE6, DOCTYPE is magically changed to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
And.. Ok - it can stay because everything looks fine.. But here is the point - just one page has DOCTYPE changed to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
which I can't stand.
What is the reason of changing XHTML to HTML 4.01 and HTML 4.0 ?
How can I force DOCTYPE in IE6 to XHTML or just HTML 4.01 ?
The reason was unexpected:
HTML comment
placed before <html> tag causes auto change of the page's doctype.
A browser only displays pages, and never modifies the original page.
The only way your question makes sense is if you're doing "save page as" and wondering why the page that IE saved isn't the same as the page it downloaded. In this case I'd expect the browser converts the page into a some sort of internal representation to make it easier to process, and "save page as" converts that internal representation back into HTML; so that it can save a single file (e.g. with embedded CSS rather than a separate CSS file), ensure that the saved file has correct markup (rather than the original potentially un-corrected markup), etc.
If this isn't what you want, go to "view -> page source" and copy & paste that instead.
The only important thing that the doctype does is to force the browser into standards compliance mode. If you don't have a doctype, older browsers will go into Quirks mode; with the doctype (no matter which one you use), the browser will go into Standards mode.
Therefore it really doesn't matter which one you use.
The XHTML doctypes will try to enforce XHTML compliance, but obviously only in browsers that properly support XHTML - IE6 may be problematic here. And of course, specifying XHTML means there's no room for any errors at all, or your page won't be rendered.
Other than that, there's really not much to choose between the various doctypes, so my suggestion is to go with the most up-to-date one possible.... which is the HTML5 doctype.
The HTML5 doctype looks like this:
<!DOCTYPE html>
That's all. Short, simple and to the point. And it does the job for all current browsers (including IE6).
This doesn't mean you have to use any HTML5 features (they obviously won't work IE6 anyway), but it's fully backward compatible, and shouldn't give you any of the weird browser-specific glitches you get with other doctypes.
Hope that helps.

Making Word document embedded in a web page editable or read-only

I'm embedding some Word documents into our web page using iframe like this:
<iframe src="ftp://ftp.example.com/www/uploads/Image/test.doc" width="100%" height="400">
Alternative
</iframe>
The problem is that the embedded Word control allows the user to edit the documents and shows an icon to save them, but doesn't actually save anything. Is it possible to setup Word to save edits back to the FTP server? If not, is there someway we can make the document read-only so the user doesn't get the idea that they can make changes? We're using IE7 and Word 2003.
(I just asked a related question about getting Word to save to a FTP server: Possible for Word to edit documents directly off an web server without Sharepoint?)
You can use ActiveX component like EDraw OfficeView or UltraOffice to embbed office and give you few control against the save and edit the document. You can also send it back to server for save.
There are a number of solutions to your problem, the easiest in my oppinion is a commercial app: https://crocodoc.com/. Developers have unlimited preview time but production use requires a license, don't know if thats an option in your case? To get this working in IE7 you will also need http://html5boilerplate.com/ together with http://code.google.com/p/html5shiv/.
Not sure if this solution will remain free but it is at the moment: https://cloudconvert.org/page/api. They provide an api to convert documents to html, you could write a script to convert docs to html on upload and then store html to show on site.
Another good option is http://www.phpdocx.com/ they have a conversion plugin to convert docx to HTML, pdf and such.
As for making your existing solution read only, i read somewhere you can do it with the method below but i am unable to test as i am on a mac and currently have no access to a machine with IE right now.
<object id="msword" width="100%" height="100%" classid="clsid:67F2A879-82D5-4A6D-8CC5-FFB3C114B69D" data='[insert document name].doc'>
<PARAM NAME="src" VALUE="file:////[insert full document path here].doc" >
<PARAM NAME="readonly" value=true>
</object>
Hope these suggestions help you with your project!
I would recommend converting the file to an mht file. this will provide cleaner lines when shown in the browser and prevent the user from editing or saving the file.