Skip to content

Commit

Permalink
added Xls and Xlsx readers
Browse files Browse the repository at this point in the history
added BaseWriter
  • Loading branch information
AlexHaxe committed May 12, 2019
1 parent 8d4be9c commit 83c3a68
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

## dev branch / next version (0.x.x)

## version 0.3.0 (2019-05-12)

- Added Xls and Xlsx readers for spreadsheet
- Added BaseWriter for spreadsheet

## version 0.2.1 (2019-05-01)

- Added Dimension base class
Expand Down
4 changes: 2 additions & 2 deletions haxelib.json
Expand Up @@ -14,8 +14,8 @@
"externs"
],
"description": "Haxe externs for PHPOffice",
"version": "0.2.1",
"releasenote": "added Dimension base class - see CHANGELOG",
"version": "0.3.0",
"releasenote": "added Xls and Xlsx readers - see CHANGELOG",
"contributors": [
"AlexHaxe"
],
Expand Down
2 changes: 1 addition & 1 deletion makeReleaseZip.sh
@@ -1,4 +1,4 @@
#!/bin/bash -e

rm -f phpoffice.zip
zip -9 -r -q phpoffice.zip src haxelib.json hxformat.json README.md CHANGES.md LICENSE
zip -9 -r -q phpoffice.zip src haxelib.json hxformat.json README.md CHANGELOG.md LICENSE
114 changes: 114 additions & 0 deletions src/php/phpoffice/phpspreadsheet/reader/BaseReader.hx
@@ -0,0 +1,114 @@
package php.phpoffice.phpspreadsheet.reader;

import php.phpoffice.phpspreadsheet.Spreadsheet;

@:native("PhpOffice\\PhpSpreadsheet\\Reader\\BaseReader")
extern class BaseReader {
/**
* Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
* If false (the default) it will read data and formatting.
*
* @return bool
*/
public function getReadDataOnly():Bool;

/**
* Set read data only
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
* Set to false (the default) to advise the Reader to read both data and formatting for cells.
*
* @param bool $pValue
*
* @return IReader
*/
public function setReadDataOnly(value:Bool):IReader;

/**
* Read empty cells?
* If this is true (the default), then the Reader will read data values for all cells, irrespective of value.
* If false it will not read data for cells containing a null value or an empty string.
*
* @return bool
*/
public function getReadEmptyCells():Bool;

/**
* Set read empty cells
* Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.
* Set to false to advise the Reader to ignore cells containing a null value or an empty string.
*
* @param bool $pValue
*
* @return IReader
*/
public function setReadEmptyCells(value:Bool):IReader;

/**
* Read charts in workbook?
* If this is true, then the Reader will include any charts that exist in the workbook.
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
* If false (the default) it will ignore any charts defined in the workbook file.
*
* @return bool
*/
public function getIncludeCharts():Bool;

/**
* Set read charts in workbook
* Set to true, to advise the Reader to include any charts that exist in the workbook.
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
* Set to false (the default) to discard charts.
*
* @param bool $pValue
*
* @return IReader
*/
public function setIncludeCharts(value:Bool):IReader;

/**
* Get which sheets to load
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
* indicating that all worksheets in the workbook should be loaded.
*
* @return mixed
*/
public function getLoadSheetsOnly():Any;

/**
* Set which sheets to load.
*
* @param mixed $value
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
* If NULL, then it tells the Reader to read all worksheets in the workbook
*
* @return IReader
*/
public function setLoadSheetsOnly(value:Any):IReader;

/**
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
*
* @return IReader
*/
public function setLoadAllSheets():IReader;

/**
* Read filter.
*
* @return IReadFilter
*/
public function getReadFilter():Any;

/**
* Set read filter.
*
* @param IReadFilter $pValue
*
* @return IReader
*/
public function setReadFilter(value:Any):IReader;

public function getSecuritySCanner():Any;
}
26 changes: 26 additions & 0 deletions src/php/phpoffice/phpspreadsheet/reader/IReader.hx
@@ -0,0 +1,26 @@
package php.phpoffice.phpspreadsheet.reader;

import php.phpoffice.phpspreadsheet.Spreadsheet;

@:native("PhpOffice\\PhpSpreadsheet\\Reader\\IReader")
extern interface IReader {
/**
* Can the current IReader read the file?
*
* @param string $pFilename
*
* @return bool
*/
public function canRead(filename:String):Bool;

/**
* Loads PhpSpreadsheet from file.
*
* @param string $pFilename
*
* @throws Exception
*
* @return \PhpOffice\PhpSpreadsheet\Spreadsheet
*/
public function load(filename:String):Spreadsheet;
}
82 changes: 82 additions & 0 deletions src/php/phpoffice/phpspreadsheet/reader/Xls.hx
@@ -0,0 +1,82 @@
package php.phpoffice.phpspreadsheet.reader;

import php.phpoffice.phpspreadsheet.Spreadsheet;

// Original file header of ParseXL (used as the base for this class):
// --------------------------------------------------------------------------------
// Adapted from Excel_Spreadsheet_Reader developed by users bizon153,
// trex005, and mmp11 (SourceForge.net)
// https://sourceforge.net/projects/phpexcelreader/
// Primary changes made by canyoncasa (dvc) for ParseXL 1.00 ...
// Modelled moreso after Perl Excel Parse/Write modules
// Added Parse_Excel_Spreadsheet object
// Reads a whole worksheet or tab as row,column array or as
// associated hash of indexed rows and named column fields
// Added variables for worksheet (tab) indexes and names
// Added an object call for loading individual woorksheets
// Changed default indexing defaults to 0 based arrays
// Fixed date/time and percent formats
// Includes patches found at SourceForge...
// unicode patch by nobody
// unpack("d") machine depedency patch by matchy
// boundsheet utf16 patch by bjaenichen
// Renamed functions for shorter names
// General code cleanup and rigor, including <80 column width
// Included a testcase Excel file and PHP example calls
// Code works for PHP 5.x
// Primary changes made by canyoncasa (dvc) for ParseXL 1.10 ...
// http://sourceforge.net/tracker/index.php?func=detail&aid=1466964&group_id=99160&atid=623334
// Decoding of formula conditions, results, and tokens.
// Support for user-defined named cells added as an array "namedcells"
// Patch code for user-defined named cells supports single cells only.
// NOTE: this patch only works for BIFF8 as BIFF5-7 use a different
// external sheet reference structure
@:native("PhpOffice\\PhpSpreadsheet\\Reader\\Xls")
extern class Xls extends BaseReader implements IReader {
/**
* Create a new Xls Reader instance.
*/
public function new();

/**
* Can the current IReader read the file?
*
* @param string $pFilename
*
* @return bool
*/
public function canRead(filename:String):Bool;

/**
* Reads names of the worksheets from a file, without parsing the whole file to a PhpSpreadsheet object.
*
* @param string $pFilename
*
* @throws Exception
*
* @return array
*/
public function listWorksheetNames(filename:String):NativeArray;

/**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).
*
* @param string $pFilename
*
* @throws Exception
*
* @return array
*/
public function listWorksheetInfo(filename:String):NativeArray;

/**
* Loads PhpSpreadsheet from file.
*
* @param string $pFilename
*
* @throws Exception
*
* @return Spreadsheet
*/
public function load(filename:String):Spreadsheet;
}
53 changes: 53 additions & 0 deletions src/php/phpoffice/phpspreadsheet/reader/Xlsx.hx
@@ -0,0 +1,53 @@
package php.phpoffice.phpspreadsheet.reader;

import php.phpoffice.phpspreadsheet.Spreadsheet;

@:native("PhpOffice\\PhpSpreadsheet\\Reader\\Xlsx")
extern class Xlsx extends BaseReader implements IReader {
/**
* Create a new Xls Reader instance.
*/
public function new();

/**
* Can the current IReader read the file?
*
* @param string $pFilename
*
* @return bool
*/
public function canRead(filename:String):Bool;

/**
* Reads names of the worksheets from a file, without parsing the whole file to a PhpSpreadsheet object.
*
* @param string $pFilename
*
* @throws Exception
*
* @return array
*/
public function listWorksheetNames(filename:String):NativeArray;

/**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).
*
* @param string $pFilename
*
* @throws Exception
*
* @return array
*/
public function listWorksheetInfo(filename:String):NativeArray;

/**
* Loads PhpSpreadsheet from file.
*
* @param string $pFilename
*
* @throws Exception
*
* @return Spreadsheet
*/
public function load(filename:String):Spreadsheet;
}
75 changes: 75 additions & 0 deletions src/php/phpoffice/phpspreadsheet/writer/BaseWriter.hx
@@ -0,0 +1,75 @@
package php.phpoffice.phpspreadsheet.writer;

import php.phpoffice.phpspreadsheet.Spreadsheet;

@:native("PhpOffice\\PhpSpreadsheet\\Writer\\BaseWriter")
extern class BaseWriter {
/**
* Write charts in workbook?
* If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
* If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
*
* @return bool
*/
public function getIncludeCharts():Bool;

/**
* Set write charts in workbook
* Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
* Set to false (the default) to ignore charts.
*
* @param bool $pValue
*
* @return IWriter
*/
public function setIncludeCharts(value:Bool):IWriter;

/**
* Get Pre-Calculate Formulas flag
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving,
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet
* viewer when opening the file
* If false, then formulae are not calculated on save. This is faster for saving in PhpSpreadsheet, but slower
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
*
* @return bool
*/
public function getPreCalculateFormulas():Bool;

/**
* Set Pre-Calculate Formulas
* Set to true (the default) to advise the Writer to calculate all formulae on save
* Set to false to prevent precalculation of formulae on save.
*
* @param bool $pValue Pre-Calculate Formulas?
*
* @return IWriter
*/
public function setPreCalculateFormulas(value:Bool):IWriter;

/**
* Get use disk caching where possible?
*
* @return bool
*/
public function getUseDiskCaching():Bool;

/**
* Set use disk caching where possible?
*
* @param bool $pValue
* @param string $pDirectory Disk caching directory
*
* @throws Exception when directory does not exist
*
* @return IWriter
*/
public function setUseDiskCaching(value:Bool, directory:Null<String> = null):IWriter;

/**
* Get disk caching directory.
*
* @return string
*/
public function getDiskCachingDirectory():String;
}
15 changes: 15 additions & 0 deletions src/php/phpoffice/phpspreadsheet/writer/IWriter.hx
@@ -0,0 +1,15 @@
package php.phpoffice.phpspreadsheet.writer;

import php.phpoffice.phpspreadsheet.Spreadsheet;

@:native("PhpOffice\\PhpSpreadsheet\\Writer\\IWriter")
extern interface IWriter {
/**
* Save PhpSpreadsheet to file.
*
* @param string $pFilename Name of the file to save
*
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function save(filename:String):Void;
}

0 comments on commit 83c3a68

Please sign in to comment.