Parseexcel Ruby used to read Excel

Read Excel file with Ruby

This guide documents, to ensure demonstration of a reading excel file with ruby example.

1. Parseexcel installed plug-ins

Parseexcel is a ruby-side plug-ins excel analytic perl. Gem install process can be simple to implement, are as follows:

gem install parseexcel

If you just should not gem network installation, then please use your car or mine quickly from here to download the installation package tar.

$ ruby install.rb config
$ ruby install.rb setup
($ su)
# ruby install.rb install 

Well, now, please bear in mind because we are a gem to install the library, call us at the console with a script function parseexcel time-rubygems want to add the parameters, so that we can use this gem library.

2. Parseexcel use

In fact, Parseexcel the use of the design is simple and clear. The call is easy to put your point.
2.1 read excel file

Spreadsheet::ParseExcel.parse( The Excel file name without the path  ")

This command will return an excel file of the existence of the quote, then we should also be sure that we should be read in that form.
2.2 determine the excel form

worksheet = workbook.worksheet(0)

Be here that the first form, of course, can use iterative traversal cycle, or excel in all forms of documents.

2.3 traverse the rows and columns excel read data

Supporting worksheet object is pretty simple and convenient way to traverse all Biandantang ranks are as follows:

worksheet.each { |row|
  if row != nil
  row.each { |cell|
    if cell != nil
      contents = cell.to_s('latin1')
      puts "Row: #{j} Cell: #{i} #{contents}"
    i = i+1
  j = j +1

2.4 read data unit

cell.to_s('latin1') # Reads a string
cell.to_s('latin1') # Read the float values
cell.to_i           # Read int value           # Read a time value
cell =    # Read specific values  

This is perhaps the introduction, do not quite understand it does not matter, complete the following examples look clear.

3. A basic script to read excel file using the example of

require 'parseexcel'

# From the command line to open the Excel file name
workbook = Spreadsheet::ParseExcel.parse(ARGV[0])

# Get the first form
worksheet = workbook.worksheet(0)

# Walk the line
worksheet.each { |row|
  if row != nil
  # Loop through the cells that line
  row.each { |cell|
    if cell != nil
      # Get the cell content type string
      contents = cell.to_s('latin1')
      puts "Row: #{j} Cell: #{i}> #{contents}"
    i = i+1

4. The implementation of the script
The use of the script, add-rubygems want the attention of the parameters in order to load the class library parseexcel, the implementation of the command is as follows:

ruby -rubygems excelparse.rb myfile.xls

Myfile.xls for one of the current directory, it is necessary to read the excel file name

分类:Ruby 时间:2009-05-14 人气:2519
blog comments powered by Disqus


  • ruby: read and write excel files 2010-04-28

    Sponsored Links: NSPP Internet marketing platform in the form by mail or blog to promote your products Test, the volume of data often form into excel, the test output data written back to the table, so that input and output easier to manage, and clar

  • Ruby and check the format into excel 2010-08-29

    This quote is the last chapter in the Rails project import export excel excel excel sister utility rails subsequent analysis, to introduce a plug into excel in ruby Plug importex Installation gem install importex Or use the rails plugin ./script/plug

  • ruby export excel chart 2011-06-01

    #!/usr/bin/ruby -w require 'writeexcel' workbook ='chart.xls') worksheet = workbook.add_worksheet chart = workbook.add_chart(:type => 'Chart::Scatter') # Configure the chart. chart.add_series( :categories => '=Sheet1!$A$2:$A$7', :val

  • Let Ruby On Rails into the enterprise development - export form to Excel 2009-03-20

    ROR architecture will form under the Export to Excel is currently the best option seems to be the only SpreadSheet. If using Microsoft's COM components can also be mediated, but very slow, but can not be cross-platform transplantation. Spreadsheet ad

  • ruby read excel data 2010-07-08

    Windows platform require 'win32ole' require 'fileutils' working_path = "" working_path.concat(Dir.getwd).concat('/') excel_file ='Excel.Application') workbook = + ARGV[0]) worksheet = workbook

  • roo in ruby excel in the handling and operation 2010-08-29

    Roo excel in dealing with this gem, and for a long time, and strong vitality, the author is still updating, such as support for ruby1.9 Personally think that it is necessary in this album, and to this record a gem, Installation #1.8 Version gem sourc

  • rails export excel using the standard plug-in spreadsheet 2009-05-17

    This article is the introduction of basic knowledge of spreadsheet, the plug-ins can read and generate excel file If you want to see more complex examples, click here If you want to see more simple examples of analytic excel document, click here If y

  • ruby gem SpreadSheet usage 2010-06-29

    (Official website link is invalid... So put here, not every gem server ...) GUIDE.txt Path: GUIDE.txt Last Update: Tue Jun 29 10:13:23 +0800 2010 Getting Started with Spreadsheet This guide is meant to Get you started using Spreadsheet . By the End o

  • the use of ruby gem SpreadSheet 2010-06-29

    (Official website link is invalid... So put here, not every gem server ...) GUIDE.txt Path: GUIDE.txt Last Update: Tue Jun 29 10:13:23 +0800 2010 Getting Started with Spreadsheet This guide is meant to Get you started using Spreadsheet . By the End o

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.035 (s). 13 q(s)