Parsing excel files in php




















This structure contains file stream offsets for every excel row for currently selected worksheet. One advantage of Row-by-row mode is that it allowes many settings to be changed that affect which cells are proccessed and how.

Please refer to Reading settings part of Methods functions subsection for more information. Debug mode enables output echo of all error and warning messages. To enable Debug mode, set the 2nd parameter to true in the constructor :. To do this, set the 4th parameter to true in the constructor :.

PHP function name in which error occured is displayed alongside the actual message. Do not enable Debug mode in your production code since it may pose a security risk! It is stored either in memory or as a temporary file, depending on data size. XLS file may sometimes be stored as a Workbook stream itself, in which case a temporary file or stream is not needed and not created. You can control when a temporary file is used instead of memory by specifying the threshold in bytes as the 3rd parameter to the constructor.

If Workbook stream size in bytes is less than this value, it will be stored in memory. You can instruct PHP not to use a temporary file thus always storing Workbook stream in memory by setting this parameter to zero:. It will behave the same way as described above, and will also use that 3rd parameter as its memory limiter.

Note: temporary files are automatically managed created and deleted by PHP. Rows and columns numeration in this parser is zero-based. Excel row numeration is numeric and starts from 1 , and column numeration is alphabetical and starts with A. Excel references a single cell by its column letter and row number, for example: A1, B3, C4, F9. The 1st index corresponds to row number, and the 2nd index is the column number. In Row-by-row mode , a single row is returned as an array of cells. The table below illustrates how the cells are numerated.

Workbook stream , or just Workbook is a binary bytestream that essentially represents excel BIFF file. There are several versions exist which differ in how they store excel data from version to version.

Workbook stream consists of Workbook Globals substream and one or more Sheet substreams. Workbook Globals contains information about the file such as BIFF5 encoding, encryption, sheets information and much more we do not actually need much more. Sheet substreams, or Sheets represent actual sheets that are created in Excel.

They can be Worksheets, Charts, Visual Basic modules and some more, but only regular Worksheets can be parsed. Excel keeps track of cells starting with first non-empty row and non-empty column, ending with last non-empty row and non-empty column.

All other cells are completely ignored by this parser like they don't exist at all. Note: during every stage extensive error checking is performed. See Error handling for more info. If it is a Compound File, the script attempts to extract Workbook stream to a temporary file and use that file in the future for all operations. Otherwise, it will directly use the supplied XLS file. The script never opens the supplied XLS file for writing.

After that, either the first non-empty worksheet will be selected and ready for parsing and all other sheets information will be available to the user, or some error will be created for example, when no non-empty worksheet was found.

Attempts to invoke a Row-by-row -mode related method that is suitable for Array mode only and vice versa will create an error, disabling any further actions most of the time. If no errors occured, it is now possible to select and setup parsing mode. When you are finished parsing a file, it is a good idea to free memory manually, especially if something else is going on in your script later on.

Set as the 2nd parameter to the constructor. This propertry is made public instead of using a getter mainly for performance reasons. Gathers information about all sheets in the file. This method is called automatically when XLS file is opened. Invoking it manually makes sence only if BIFF5 codepage was detected incorrectly and you cannot see sheet names and you really need them. Russian Federation. Innovation award Nominee: 1x.

Install with Composer. Version Control. Download Rankings. All time:. This week:. Very pleased - good job! Thank you, Sergey.

Absolutely simple to use 6 years ago eduardo de souza. Good solution for XLSX file parsing. Many thanks Sergey! Great, no memory troubles on big sheets. A tough problem and a great start 8 years ago sigmond axel. Great job! Exactly what I was looking for. Good solution for parsing XLSX file. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.

Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related



0コメント

  • 1000 / 1000