Thư viện Ruby miễn phí để Phân tích Tập tin Excel XLSX lớn từ xa
Một Thư viện Ruby mở nguồn mạnh mẽ để Phân tích Tập tin Excel XLSX và XLSM lớn từ xa. Nó hỗ trợ phân tích các tệp và hình ảnh từ xa, ánh xạ tiêu đề và vân vân.
Thư viện Creek là gì?
Trong thế giới xử lý dữ liệu, việc xử lý các tệp Excel lớn có thể là một nhiệm vụ khó khăn, thường dẫn đến nghẽn hiệu năng và tiêu thụ bộ nhớ cao. Creek ra đời, là một thư viện Ruby mã nguồn mở mạnh mẽ được thiết kế để phân tích các tệp Excel lớn với hiệu quả đáng kinh ngạc. Đây là một công cụ hiệu quả để phân tích các tệp Excel lớn. Nó chi tiết các tính năng chính như phân tích luồng, hỗ trợ nhiều loại tệp và tùy chọn sử dụng linh hoạt trong cả các script độc lập và ứng dụng Rails. Nó cung cấp hỗ trợ đầy đủ cho các thao tác cơ bản, phân tích hình ảnh và xử lý tệp từ xa, trở thành nguồn tài nguyên quý giá cho các nhà phát triển muốn tối ưu quy trình xử lý dữ liệu của mình.
Creek là một thư viện Ruby mã nguồn mở mạnh mẽ, hiệu quả và tập trung vào việc phân tích các tệp Excel .xlsx / .xlsm. Đây là một Ruby gem cung cấp cách nhanh chóng và đơn giản để đọc và phân tích các tệp Excel lớn (XLSX và XLSM). Nó sử dụng phân tích luồng, nghĩa là đọc tệp từng phần thay vì tải toàn bộ tệp vào bộ nhớ. Cách tiếp cận này giúp Creek tiêu thụ bộ nhớ cực kỳ hiệu quả và lý tưởng cho các ứng dụng xử lý dữ liệu khổng lồ. Dù bạn đang làm việc trên một script Ruby độc lập hay một ứng dụng Rails, Creek mang lại trải nghiệm tích hợp liền mạch. Nếu dự án của bạn bao gồm các bảng tính lớn, hình ảnh, siêu dữ liệu hoặc tải lên tệp trong Rails, Creek cung cấp nhiều chức năng cần thiết với chi phí tối thiểu.
Bắt đầu với Creek
Cách khuyến nghị để cài đặt thư viện Creek là sử dụng RubyGems. Vui lòng sử dụng lệnh sau để cài đặt suôn sẻ.
Cài đặt Creek qua RubyGems
$ gem install Creek Phân tích các Tập tin Excel lớn bằng Ruby
The cornerstone of open source Creek library is its stream parsing capability. This feature allows you to process large Excel files without worrying about memory overloads. By reading the file in chunks, Creek ensures that your application remains responsive and stable, even when handling files with hundreds of thousands of rows. The most common use case is to open a file and read data from its worksheets. Here is a simple example that demonstrates, how software developers can parse an Excel file via Ruby library.
Cách phân tích các tệp Excel XLSX lớn qua Thư viện Ruby?
require 'creek'
# Open the Excel file
creek = Creek::Book.new 'path/to/your/sample.xlsx'
# Get the first sheet
sheet = creek.sheets[0]
# Loop through rows with cell coordinates
sheet.rows.each do |row|
puts row
# => {"A1"=>"Content 1", "B1"=>nil, "C1"=>"Content 2"}
end
# Loop through rows without cell coordinates
sheet.simple_rows.each do |row|
puts row
# => {"A"=>"Content 1", "B"=>nil, "C"=>"Content 2"}
End
Phân tích & Trích xuất Hình ảnh bằng Thư viện Ruby
While not enabled by default to conserve memory, the Creek library can parse images from your Excel files. By using the with_images method, you can preload and extract images from cells. The images are returned as an array of Pathname objects, making them easy to work with. Here is a simple example that demonstrates, how software developers can parse and extract I mages from an Excel spreadsheet via Ruby Library.
Cách phân tích và trích xuất hình ảnh từ một bảng tính Excel qua Thư viện Ruby?
require 'creek'
book = Creek::Book.new 'presentation.xlsx'
sheet = book.sheets.first
sheet.with_images.rows.each do |row|
row.each do |coord, value|
if value.is_a?(Array)
# this cell has images
puts "Images at #{coord}: #{value.inspect}"
else
puts "#{coord}: #{value}"
end
end
end
# Images at a specific cell
images = sheet.images_at('B2')
if images
images.each do |path|
puts "Found image file: #{path}"
end
else
puts "No image at B2"
end
Phân tích Tập tin Từ xa bằng Thư viện Ruby
Need to parse an Excel file from a URL? The Creek library has you covered. By setting the remote: true option, you can parse files directly from a remote server, eliminating the need to download them first. You can parse files from URLs or paths even if they don’t have .xlsx or .xlsm extensions. The extension check can be skipped. The argument check_file_extension can be provided to bypass extension enforcement. Here is a simple example for parsing Excel files remotely via Ruby library.
Cách phân tích tệp Excel XLSX từ xa qua Thư viện Ruby?
remote_url = 'http://example.com/sample.xlsx'
creek = Creek::Book.new remote_url, remote: true
# ... process the file
Phân tích Tập tin XLSX và XLSM bằng Ruby
The open source ruby library Creek supports both the standard XLSX and the macro-enabled XLSM file formats, providing flexibility for various use cases. This ensures that you can handle a wide range of Excel files without needing multiple libraries.