如何从 iPhone sdk 中收集的数据以编程方式生成 word 文件 [英] How to generate a word file programmatically from collected data in iPhone sdk

查看:30
本文介绍了如何从 iPhone sdk 中收集的数据以编程方式生成 word 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iPhone 应用程序,其中包含一些我从用户那里收集数据的表单.现在在这些表格的末尾,在用户填写完所有数据后,我希望导出所有收集的数据并生成一个 MS word .doc 文件.数据也不是简单的文本.里面有标题、表格和普通文本.有什么办法可以做到这一点吗?

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?

推荐答案

简答是,长答:

你不能这样做来创建适当的"Word 文档,但是您应该能够通过从 HTML 构建 word doc 并将其保存为 .doc 扩展名(而不是 HTML)来在任何平台上完成此操作.您可以在其中放置任何内容,自定义布局 - 我可能会坚持使用段落和表格以及浮动元素(例如 imgs 等).

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

您可能需要在 HTML 文档中添加额外的代码(例如,在页面视图中打开它而不是在 HTML 视图中打开),但您可以通过将 word 文档保存为 HTML 格式来解决所有这些问题.:) 如果你知道去哪里找,互联网上也有很多关于它的信息.

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.

这是唯一的自定义"我的 html word 文档中的内容:

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]--> 

其余的只是标准的 HTML 和 CSS(记住将 CSS 放在 HTML 文档的 <style> 标签中 - word 不会远程获取您的 css 文件).

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

这篇关于如何从 iPhone sdk 中收集的数据以编程方式生成 word 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆