# perldoc > Spreadsheet::ParseExcel::Utility

---
type: CommandReference
command: Spreadsheet::ParseExcel::Utility
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `LocaltimeExcel(sec, min, hour, day, month, year)` — convert localtime-like array to Excel date/time number
- `ExcelLocaltime($excel_datetime)` — convert Excel date/time number to localtime-like array
- `ExcelFmt($format_string, $number)` — format a number using Excel's format string (e.g., dates, currency)
- `col2int($column)` — convert Excel column letter (e.g., 'A', 'AA') to zero-indexed column number
- `int2col($col_num)` — convert zero-indexed column number to column letter
- `sheetRef($cell_string)` — convert 'A1' notation to zero-indexed `(row, col)` pair
- `xls2csv($filename, $region, $rotate)` — convert part of an Excel file to CSV text

## Name

**Spreadsheet::ParseExcel::Utility** — Utility functions for Spreadsheet::ParseExcel.

## Synopsis

perl
use Spreadsheet::ParseExcel::Utility qw(ExcelFmt ExcelLocaltime LocaltimeExcel);

# Convert localtime to Excel time
my $datetime = LocaltimeExcel(11, 10, 12, 23, 2, 64);       # 1964-3-23 12:10:11
print $datetime, "\n";                                       # 23459.5070717593

# Convert Excel time to localtime
my @time = ExcelLocaltime($datetime);
print join(":", @time), "\n";                                # 11:10:12:23:2:64:1:0

# Formatting
print ExcelFmt('yyyy-mm-dd', $datetime), "\n";               # 1964-3-23
print ExcelFmt('m-d-yy',     $datetime), "\n";               # 3-23-64
print ExcelFmt('#,##0',      $datetime), "\n";               # 23,460
print ExcelFmt('#,##0.00',   $datetime), "\n";               # 23,459.51
## Functions

All functions are optionally exported. Import individually or with `qw()`.

- `ExcelFmt($format_string, $number, $is_1904)` — Format a raw number using an Excel number format string (e.g., dates, currency, percentages). For dates, `$is_1904` (default 0) switches to Excel's 1904 epoch. Example: `ExcelFmt('$#,##0.00', 1234.567)` returns `$1,234.57`.

- `ExcelLocaltime($excel_datetime, $is_1904)` — Convert an Excel date/time number to a `localtime()`-like array: `($sec, $min, $hour, $day, $month, $year, $wday, $msec)`. Month is zero-indexed, year is years since 1900. `$is_1904` optional.

- `LocaltimeExcel($sec, $min, $hour, $day, $month, $year, $wday, $msec, $is_1904)` — Convert a `localtime()`-like array to an Excel date/time number. `$wday` and `$msec` are optional. Example: `LocaltimeExcel(0, 0, 0, 1, 0, 101)` yields the number for 1 Jan 2001.

- `col2int($column)` — Convert Excel column letter(s) to zero-indexed integer. `col2int('A')` → 0, `col2int('AA')` → 26.

- `int2col($column_number)` — Convert zero-indexed column number to column letter(s). `int2col(0)` → 'A', `int2col(26)` → 'AA'.

- `sheetRef($cell_string)` — Convert 'A1' notation to zero-indexed `(row, col)` array. `sheetRef('A1')` → (0,0), `sheetRef('C2')` → (1,2).

- `xls2csv($filename, $region, $rotate)` — Convert a section of an Excel file to CSV. `$region` format: `"sheet-colrow:colrow"` (e.g., `'1-A1:B2'`). `$rotate` 0 or 1 for transposition. Requires `Text::CSV_XS`.

## Examples

perl
use Spreadsheet::ParseExcel::Utility qw(ExcelFmt ExcelLocaltime LocaltimeExcel col2int int2col sheetRef);

# Date conversions
my $num = LocaltimeExcel(0, 0, 0, 1, 0, 101);  # 1 Jan 2001
print ExcelFmt('d mmm yyyy', $num);             # 1 Jan 2001

# Column conversions
print col2int('A');   # 0
print int2col(26);    # 'AA'

# Cell reference
my ($row, $col) = sheetRef('C2');               # (1, 2)
## See Also

- [Spreadsheet::ParseExcel](https://www.chedong.com/phpMan.php/perldoc/Spreadsheet%3A%3AParseExcel/markdown)
- [Spreadsheet::ParseExcel::Cell::value](https://www.chedong.com/phpMan.php/perldoc/Spreadsheet%3A%3AParseExcel%3A%3ACell/markdown)
- [Text::CSV_XS](https://www.chedong.com/phpMan.php/perldoc/Text%3A%3ACSV_XS/markdown)
- [Spreadsheet::Read](https://www.chedong.com/phpMan.php/perldoc/Spreadsheet%3A%3ARead/markdown)
- Ken Prows' xls2csv: <http://search.cpan.org/~ken/xls2csv/script/xls2csv>
- H.Merijn Brand's xls2csv: <http://search.cpan.org/~hmbrand/Spreadsheet-Read/>