Module: XLSXDrone

Defined in:
lib/xlsx_drone/sheet.rb,
lib/xlsx_drone/workbook.rb,
lib/xlsx_drone/exceptions.rb,
lib/xlsx_drone/xlsx_drone.rb,
lib/xlsx_drone/native_binding.rb

Overview

Namespace (protector) of the library.

Defined Under Namespace

Modules: LogicError, NativeBinding, TransientFailure, UserError Classes: Sheet, Workbook

Class Method Summary collapse

Class Method Details

.open(path) ⇒ XLSXDrone::Workbook

Opens an XLSX file, should be closed after working with him. Can raise several exceptions.

Parameters:

  • path (String)

Returns:

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xlsx_drone/xlsx_drone.rb', line 7

def self.open(path)
  # check that the *path* is always a #String
  raise XLSXDrone::LogicError::ClientError::MalformedParams, "A #String is expected." if(!path.is_a?(String))
  # reserve memory for an xlsx_workbook struct
  xlsx_workbook_mpointer = FFI::MemoryPointer.new(1, XLSXDrone::NativeBinding::XLSXWorkbookT.size, false)
  if(XLSXDrone::NativeBinding.xlsx_open(File.absolute_path(path), xlsx_workbook_mpointer) == 1)
    # everything went ok
    XLSXDrone::Workbook.new(xlsx_workbook_mpointer)
  else
    # something went wrong
    case XLSXDrone::NativeBinding.xlsx_get_xlsx_errno()
      when -2
        raise NoMemoryError
      when -3
        raise XLSXDrone::LogicError::InternalError::CantDeployFile, "Can't deploy #{path}. Check that the file isn't already opened.unl"
      when -4
        raise XLSXDrone::LogicError::InternalError::XMLParsingError, "The XLSX may be corrupted or it belongs to a version unsupported by this library."
    end
  end
end