Parseexcel Ruby used to read Excel

sponsored links
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|
  j=0
  i=0
  if row != nil
  row.each { |cell|
    if cell != nil
      contents = cell.to_s('latin1')
      puts "Row: #{j} Cell: #{i} #{contents}"
    end
    i = i+1
  }
  j = j +1
  end
}


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  
cell.date           # Read a time value  
cell = row.at(3)    # 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|
  j=0
  i=0
  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}"
    end
    i = i+1
  }
  end
}


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
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb
Tags:

Related Posts of Parseexcel Ruby used to read Excel

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

  • ruby: read and write excel files

    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 clarity U

  • Ruby and check the format into excel

    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/plugin in

  • ruby export excel chart

    #!/usr/bin/ruby -w require 'writeexcel' workbook = WriteExcel.new('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

    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 adv

  • ruby read excel data

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

  • roo in ruby excel in the handling and operation

    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版 gem sources -a h

  • rails export excel using the standard plug-in spreadsheet

    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 you wa

  • ruby gem SpreadSheet usage

    (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

    (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 of it,

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries