Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...