Skip to content

Commit

Permalink
PR comments set 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed May 5, 2022
1 parent fa48a1f commit 9c74155
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 14 additions & 3 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Io/Excel.enso
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ validate : Boolean -> Text -> Any
validate validation ~error_message ~wrapped =
if validation then wrapped else Error.throw (Illegal_Argument_Error error_message)


## PRIVATE
Reads an input Excel file according to the provided section.

Arguments:
- file: The File object to read.
- section: The part of the Excel document to read.
- on_problems: Specifies the behavior when a problem occurs during the
operation. By default, a warning is issued, but the operation proceeds.
If set to `Report_Error`, the operation fails with a dataflow error.
If set to `Ignore`, the operation proceeds without errors or warnings.
- xls_format: If `True` then the file is read in using Excel 95-2003 format
otherwise reads in Excel 2007+ format.
read_excel : File -> Excel_Section -> Problem_Behavior -> Boolean -> (Table | Vector)
read_excel file section _ xls_format=False =
reader stream = case section of
Expand All @@ -161,10 +172,10 @@ read_excel file section _ xls_format=False =
Text -> Reader.readRangeByName stream address skip_rows row_limit xls_format

file_failure caught_panic = File.wrap_io_exception file caught_panic.payload.cause.getCause
catch_file_failure = Panic.catch IllegalArgumentException handler=file_failure
catch_file_failure = Panic.catch IOException handler=file_failure

bad_argument caught_panic = Error.throw (Invalid_Location caught_panic.payload.cause.getCause)
catch_bad_argument = Panic.catch IOException handler=bad_argument
catch_bad_argument = Panic.catch IllegalArgumentException handler=bad_argument

catch_file_failure <| catch_bad_argument <|
file.with_input_stream [File.Option.Read] stream->(stream.with_java_stream reader)
13 changes: 13 additions & 0 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Io/File_Format.enso
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ type Infer

## Read the file to a `Table` from an Excel file
type Excel
## Read Excels files into a Table or Vector.

Arguments:
- section: The `Excel_Section` to read from the workbook.
This can be one of:
- `Sheet_Names` - outputs a `Vector` of sheet names.
- `Range_Names` - outputs a `Vector` of range names.
- `Sheet` - outputs a `Table` containing the specified sheet.
- `Range` - outputs a `Table` containing the specified range.
- `xls_format`:
If set to `True`, the file is read as an Excel 95-2003 format.
If set to `False`, the file is read as an Excel 2007+ format.
`Infer` will attempt to deduce this from the extension of the filename.
type Excel (section:Excel_Section=Excel_Module.Sheet_Names) (xls_format:(True|False|Infer)=Infer)

## Implements the `File.read` for this `File_Format`
Expand Down

0 comments on commit 9c74155

Please sign in to comment.