-
how to use rails to create a word or excel file5
如题,
有没有什么gem能够让数据库中的text生成一个doc的,
数据库中的是用富文本编辑框输入的带有格式的文本,怎样不丢失格式,生成doc,(或者生成excel更方便一点?)。
有没有什么库。
求教~
问题补充:kamama 写道数据库的东西你可以用平常的方式写在一个文件里,然后用win32ole再处理
首先你的应用需要部署在Windows上
require 'win32ole'
#这个可以调用office组件
举个例子
word = WIN32OLE.new('word.application')
word.Visible = false #设置不在前台显示
word.Documents.Open(‘文件路径’)#打开刚才的文件
#下面是设置一些页宽,边距
word.ActiveDocument.PageSetup.PageWidth =419.5
word.ActiveDocument.PageSetup.PageHeight =595.2
word.ActiveDocument.PageSetup.TopMargin =45
word.ActiveDocument.PageSetup.BottomMargin=40
word.ActiveDocument.PageSetup.leftMargin=50
word.ActiveDocument.PageSetup.RightMargin=50
#设置存储模式 有好几种模式,可以参考你的word另存为,这里用第六种
word.ActiveDocument.SaveAs("存储路径,后缀是.doc", 6)
#完事
1.部署在windows上?!这个.....有人这么干么。
如果真这么干了,我在想,数据库中的text如果还包含了<b></b>之类的标签在字符串中,利用上述方法是否可以正确的解析(不止这些,还包含一些编号之类或者其他富文本编辑工具所提供的格式化标签)。
2.那如果不是在windows上呢?一般都会在linux上吧。2011年7月05日 14:05
2个答案 按时间排序 按投票排序
-
采纳的答案
数据库的东西你可以用平常的方式写在一个文件里,然后用win32ole再处理
首先你的应用需要部署在Windows上
require 'win32ole'
#这个可以调用office组件
举个例子
word = WIN32OLE.new('word.application')
word.Visible = false #设置不在前台显示
word.Documents.Open(‘文件路径’)#打开刚才的文件
#下面是设置一些页宽,边距
word.ActiveDocument.PageSetup.PageWidth =419.5
word.ActiveDocument.PageSetup.PageHeight =595.2
word.ActiveDocument.PageSetup.TopMargin =45
word.ActiveDocument.PageSetup.BottomMargin=40
word.ActiveDocument.PageSetup.leftMargin=50
word.ActiveDocument.PageSetup.RightMargin=50
#设置存储模式 有好几种模式,可以参考你的word另存为,这里用第六种
word.ActiveDocument.SaveAs("存储路径,后缀是.doc", 6)
#完事
2011年7月05日 15:00
-
win32组件悲哀的只能在win系统上才能用。
至于text中含有html标签的问题,基本是可以正常的解析的。因为word本身就能保存成为html格式。
至于linux上是否有类似微软office一样的软件,并且该软件也提供了程序可调用的接口我就不清楚了。我一直都用win环境,服务器之前也是win2003server系统,就没了解linux的情况。你如果发现了,麻烦告诉我一声。2011年7月05日 17:47
相关推荐
标题与描述:“如何在Rails中实现RESTful” 在IT领域,尤其是Web开发中,RESTful(Representational State Transfer)架构风格被广泛应用于构建灵活、可扩展的系统。Rails(Ruby on Rails),作为一款流行的Web应用...
You'll learn how to install Postgres on your computer or use a free version of it in the cloud. Table of Contents Chapter 1. Set Up the Environment Chapter 2. Create a Great-Looking Login with ...
这个简单的插件使您能够调用to_xls到Rails的数组集合。 数组元素支持对象:ActiveRecord,Mongid,哈希。 在您的Gemfile中: gem 'to_xls-rails' # Last officially released gem # gem "to_xls-rails", :git => ...
* Rails fundamentals and how to create basic online applications * How to work with HTML controls, use models in Rails applications, and work with sessions * Details on working with databases and ...
Examples use Concerns, Russian Doll caching, and Turbolinks, and the book focuses throughout on the right way to use Rails. Additionally, this edition now works on Ruby 2.0, a new release of Ruby ...
Drawing on their unsurpassed experience and track record, they address the real challenges development teams face, showing how to use Rails 3 to maximize your productivity. Using numerous detailed ...
This book teaches intermediate to advanced web developers how to use both Ajax and Rails to quickly build high-performance, scalable applications without being overwhelmed with thousands of lines of ...
Take a holistic view of full-stack development to create usable, high-performing applications, and learn to use these technologies effectively in a Ruby on Rails environment. Rails is a great tool ...
From the latest Ajax effects to time-saving automation tips for your development process, "Rails Recipes" will show you how the experts have already solved the problems you have. Use generators to ...
With Rails examples, use testing to enable your code to respond better to future change. Plus, see how to handle real-world testing situations. This new edition has been updated to Rails 5.2 and ...
综上所述,《Ruby on Rails Guides_ A Guide to Testing Rails Applications.pdf》是一个全面的资源,无论你是Rails新手还是资深开发者,都能从中学习到如何为Rails应用编写高质量的测试。从理论到实践,从单元测试...
Best practices on how to apply Rails continue to change, and this edition keeps up. Examples use cookie backed sessions, HTTP authentication, and Active Record-based forms, and the book focuses ...
The book also delves into creating a basic "Hello World" application, demonstrating how to set up a simple project and integrate Flex and Rails. #### Installing Everything - **Ruby**: Essential for...