Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Monday, July 27, 2009

在excel中转换unix timestamp

A1 = 1248255194
=(A1+8*3600)/86400+70*365+19

在excel中没有直接的函数可以将一个unix时间截,转换为一个可阅读的时间格式,
这个公式可以用来转换显示时间,转换出来的还是一个数字,需要调整其显示格式,选择一个日期格式。

Wednesday, May 13, 2009

Write excel tool for ruby

require 'rubygems'
require 'writeexcel'

# Create a new Excel Workbook
workbook = Spreadsheet::WriteExcel.new('ruby.xls')

# Add worksheet(s)
worksheet = workbook.add_worksheet
worksheet2 = workbook.add_worksheet

# Add and define a format
format = workbook.add_format
format.set_bold
format.set_color('red')
format.set_align('right')

# write a formatted and unformatted string.
worksheet.write(1, 1, 'Hi Excel.', format) # cell B2
worksheet.write(2, 1, 'Hi Ruby.') # cell B3

# write a number and formula using A1 notation
worksheet.write('B4', 3.14159)
worksheet.write('B5', '=SIN(B4/4)')

# write to file
workbook.close

Thursday, August 16, 2007

用Ruby spreadsheet/excel 生成Excel文档(附问题)

require "rubygems"
require "spreadsheet/excel"
include Spreadsheet

workbook = Excel.new("test.xls")

format = Format.new
format.color = "green"
format.bold = true

worksheet = workbook.add_worksheet
worksheet.write(0, 0, "Hello", format)
worksheet.write(1, 1, ["Matz","Larry","Guido"])

workbook.close

这是doc里的例子,但是format并不能应用到"Hello"这个格子上,需要用format = workbook.add_format(:color => "green", :bold => true)才能真正生效,有知道原因的朋友可以回帖知会一下,谢谢。
PS: 这个lib只能生成,读取用parseexcel这个lib。