Read Microsoft Excel spreadsheet file using Java
value = xlread(file_path)
value = xlread(file_path,sheet)
value = xlread(file_path,range)
value = xlread(file_path,sheet,range)
[value,text,data] = xlread(...)
[value,text,data,custom] = xlread(file_path,sheet,range,processFun)
a character string giving the path of the Excel file.
an integer giving the sheet position or a character string giving the sheet name.
a character string giving the rectangular range to be read in the sheet using Excel syntax.
Scilab function used to process the sheet data.
a matrix of numbers containing the numerical data found in the sheet at specfied range. The cells
without numerical data are represented by NaN
values.
a matrix of strings containing the textual data found in the sheet at specfied range. The cells without text data are represented by empty strings.
a cell array containing the raw data found in the sheet at specfied range. Empty cells
are represented by NaN
values.
contains the eventual second output from processFun
This function reads a given sheet of an Excel workbook by eventually specifying the range to be read using the Excel syntax
e.g. A1:B3
. It returns the numerical data and the strings contained in the sheet cells.
When the sheet argument is not given, then the first sheet of the workbook is read. In this case, the range argument must include a colon, otherwise it will be interpreted as a sheet name.
When the range argument is not given, then the whole sheet is read. Otherwise it can be of the form A1
to read a single cell, A1:B3
, A1:
, :B3
, where the two latter specify the start or the end cell of the range.
When the processFun parameter is given, the function is called with a single argument Data
where
Data.Value
contains the raw data of the sheet, Data.Count
is the number of cells and Data.WorkSheet
is the sheet as a Java object. The first output of processFun
replaces the raw sheet data before further analysis and the eventual second output is returned in the custom output argument.
![]() | Only .xls and .xlsx files are handled (EXCEL97 xlWorkbookNormal and EXCEL2007 xlOpenXMLWorkbook). Binary .xlsb files are not supported. |
// read first sheet filename = fullfile(SCI,'modules/spreadsheet/demos/xls/Test1.xls'); [numbers,text,raw] = xlread(filename) // read specified range of second sheet of xlsx file filename = fullfile(SCI,'contrib/xlreadwrite/1.0/demos/xlsx/Testbig.xlsx'); numbers = xlread(filename,2,"B3:D6") // read specified range of sheet named "Sheet 2" of xlsx file numbers = xlread(filename,'Sheet 2','B4:D14') // apply function to data function Data=convert(Data) for k = 1:Data.Count Data.Value{k} = floor(100*Data.Value{k}); end end numbers = xlread(filename,'Sheet 2','B4:D14',convert) | ![]() | ![]() |
This function is based on POI library (http://poi.apache.org/).