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

  • QTP finishing the operation function excel

    ************************************************** **** 'Function: read a value in Excel 'Input parameter: 'StrFilePath: Save Excel file path 'StrExcelSheetName: Excel to read the name in the Sheet 'IntRow: read what their data

  • 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

  • Extraction of local transmission circuits

    #!/usr/bin/perl ############## # Local transport circuit extraction # # # ############## use Cwd; use Data::Dumper; use Spreadsheet::ParseExcel::FmtUnicode; use Spreadsheet::ParseExcel; my ($file_name,$sheet_name,$sheet_num,$row,$col,$cell); ############

  • Read Excel file using as3xls

    Read in the flex excel, I have never found a complete example can be run, where I mainly record the programs I use as3xls solution and provide a simple demo. (In the Adobe Flash Builder 4 tested successfully) Read excel key which 2 points 1: read exc

  • jxl of Excel read. write. Update and insert a picture (with code examples)

    Java Excel is an open source project, through which developers can read Excel document, create a new Excel file, update an existing Excel file and insert pictures and more. Check out the official details and API: http://www.andykhan.com/jexcelapi/ind ...

  • java into the database in Excel

    1 sheet from the Excel file for reading Java Excel API from the local file system, either a file (. Xls), can also be read from the input stream Excel spreadsheets. Read Excel data table first step is to create a Workbook (terminology: workbook), the foll

  • Ruby win32ole achieve xls file into hollow line

    A while ago, with Ruby's win32ole write a script for data analysis and summary to the xls, the need to insert a blank line separating the upper and lower data form. excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open(RESULT

  • Ruby win32ole xls files to achieve the insertion of hollow line

    A while ago, with Ruby's win32ole write a script for data analysis and summary to the xls, the need to insert a blank line separating the upper and lower data form. excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open(RESULT + "\

  • EXCEL file using JAVA operation (JAVA EXCEL API)

    JAVA EXCEL API Introduction Java Excel is an open source project through which Java developers can read Excel document, create a new Excel file, update an existing Excel file. Non-Windows operating system using the API can also be pure Java applicati ...

  • poi Development Kit

    Apache POI is an open source Java to read and write Excel, WORD and other Microsoft OLE2 component documentation projects. Already have Ruby version of the current POI. Apache POI is an open source Java to read and write Excel, WORD and other Microso ...

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