此处将为大家介绍关于phpspreadsheet中文文档的详细内容,并且为您解答有关三计算引擎的相关问题,此外,我们还将为您介绍关于CSpreadSheet中文文档、Jspreadsheetv4:Th
此处将为大家介绍关于phpspreadsheet 中文文档的详细内容,并且为您解答有关三 计算引擎的相关问题,此外,我们还将为您介绍关于CSpreadSheet中文文档、Jspreadsheet v4: The javascript spreadsheet、laravel-phpspreadsheet 导入导出、php 使用phpoffice/phpspreadsheet拓展实现导出图片的有用信息。
本文目录一览:- phpspreadsheet 中文文档(三) 计算引擎(php 计算器)
- CSpreadSheet中文文档
- Jspreadsheet v4: The javascript spreadsheet
- laravel-phpspreadsheet 导入导出
- php 使用phpoffice/phpspreadsheet拓展实现导出图片
phpspreadsheet 中文文档(三) 计算引擎(php 计算器)
2019年10月11日13:59:52
使用PhpSpreadsheet计算引擎
执行公式计算
由于PhpSpreadsheet表示内存中的电子表格,因此它还提供公式计算功能。单元格可以是值类型(包含数字或文本),也可以是公式类型(包含可以求值的公式)。例如,该公式=SUM(A1:A10)
计算得出A1,A2,...,A10中的值之和。
要计算公式,可以调用包含公式方法的单元格getCalculatedValue()
,例如:
$spreadsheet->getActiveSheet()->getCell(''E11'')->getCalculatedValue();
如果您在PhpSpreadsheet随附的发票演示中编写了以下代码行,则其评估值为“ 64”:
PhpSpreadsheet公式解析器的另一个不错的功能是,它可以在插入/删除行/列时自动调整公式。这是一个例子:
您会看到单元格E11中包含的公式是“ SUM(E4:E9)”。现在,当我编写以下代码行时,添加了两个新的产品线:
$spreadsheet->getActiveSheet()->insertNewRowBefore(7, 2);
你注意到了吗?以前的单元格E11中的公式(当我插入2个新行时为E13)更改为“ SUM(E4:E11)”。同样,插入的单元格将复制前一个单元格的样式信息,就像Excel的行为一样。请注意,您可以插入行和列。
计算缓存
一旦计算引擎评估了单元格中的公式后,结果将被缓存,因此,如果您getCalculatedValue()
再次调用同一单元格,则结果将从缓存中返回,而不是第二次评估公式。这有助于提高性能,因为就性能和速度而言,评估公式是一项昂贵的操作。
但是,有时您可能不希望这样,也许您已经更改了基础数据,并且需要使用该新数据重新评估相同的公式。
Calculation::getInstance($spreadsheet)->disableCalculationCache();
将禁用计算缓存,并刷新当前计算缓存。
如果您只想刷新缓存,则可以调用
Calculation::getInstance($spreadsheet)->clearCalculationCache();
已知限制
PhpSpreadsheet计算引擎有一些已知的限制。它们中的大多数是由于在执行之前将Excel公式转换为PHP代码的事实。这意味着Excel公式的计算取决于PHP的语言特性。
Xls不支持的功能
并非所有功能都受支持,要获取完整列表,请按名称阅读 功能列表。
运算符优先级
在Excel中+
胜过&
,就像在普通代数中*
胜过一样+
。前一条规则不是使用PhpSpreadsheet附带的计算引擎所能找到的。
- Excel参考
- PHP参考
涉及数字和文字的公式
包含数字和文本的公式可能会产生意外的结果,甚至导致文件内容无法读取。例如,=3+"Hello "
期望该公式在Excel中产生错误(#VALUE!)。由于PHP转换"Hello "
为数值(零)的事实,该公式的结果被评估为3,而不是错误。这还会导致Excel文档被生成为包含不可读的内容。
- PHP中此行为的参考
公式似乎不是在Excel2003中使用兼容包计算的?
这是兼容包的正常行为,Xlsx正确显示了这一点。使用\PhpOffice\PhpSpreadsheet\Writer\Xls
如果你真的需要计算的值,或强制重新计算Excel2003中中。
处理日期和时间值
返回日期和时间值的Excel函数
在Excel中返回日期值的任何Date and Time函数都可以返回Excel时间戳或PHP时间戳或DateTime
对象。
脚本可以通过调用\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType()
方法来更改用于返回日期值的数据类型 :
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($returnDateType);
以下常量可用于$returnDateType
:
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL
该方法将在成功时返回布尔值True,在失败时返回False(例如,如果为返回日期类型传递了无效值)。
该\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
方法可用于确定此设置的当前值:
$returnDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
默认值为RETURNDATE_PHP_NUMERIC
。
PHP时间戳
如果RETURNDATE_PHP_NUMERIC
为Return Date Type设置了返回值,则通过对Excel中的Date和Time函数的任何访问返回到调用脚本的任何日期值将是一个整数值,表示距PHP / Unix基础日期的秒数。PHP / Unix的基准日期(0)在1970年1月1日为美国标准时间00:00。该值可以是正数或负数:因此-3600的值将是1969年12月31日的23:00。而1970年1月1日的+3600值为01:00。这使PHP的日期范围为1901年12月14日至2038年1月19日。
PHP DateTime
对象
如果将Return Date Type设置为RETURNDATE_PHP_OBJECT
,则通过对Excel中的Date和Time函数的任何访问返回到调用脚本的任何日期值将是一个PHP DateTime
对象。
Excel时间戳
如果RETURNDATE_EXCEL
为Return Date Type设置了返回值,则通过对Excel中的Date和Time函数的任何访问返回的日期值将是一个浮点值,代表距Excel基本日期的天数。Excel的基本日期由Excel使用的日历决定:Windows 1900或Mac 1904日历。1900年1月1日是Windows 1900日历的基准日期,而1904年1月1日是Mac 1904日历的基准日期。
脚本可以通过调用以下\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar()
方法来更改用于计算Excel日期值的日历 :
\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar($baseDate);
以下常量可用于$baseDate
:
\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900
\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904
该方法将在成功时返回布尔值True,在失败时返回False(例如,如果传入了无效值)。
该\PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar()
方法可用于确定此设置的当前值:
$baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar();
默认值为CALENDAR_WINDOWS_1900
。
返回日期/时间值的函数
- 日期
- DATEVALUE
- EDATE
- EOMONTH
- 现在
- 时间
- 时间值
- 今天
接受日期和时间值作为参数的Excel函数
作为参数传递给函数的日期值可以是Excel时间戳或PHP时间戳;或DateTime
对象;或包含日期值的字符串(例如“ 2009年1月1日”)。PhpSpreadsheet将尝试根据PHP数据类型识别其类型:
整数将被视为PHP / Unix时间戳。实数值(浮点数)将被视为Excel日期/时间戳。任何PHP DateTime
对象都将被视为DateTime
对象。任何字符串值(甚至包含直接数字数据的字符串值)都将转换为DateTime
用于验证的对象作为基于服务器区域设置的日期值,因此,如果服务器设置为英国,则通过模棱两可的值''07 / 08/2008''将被视为2008年8月7日,而如果服务器为UK,则将其视为2008年7月8日设置为美国。但是,如果您传递的值(例如“ 31/12/2008”)被位于美国的服务器视为错误,但并不明确,则PhpSpreadsheet会尝试将其更正为2008年12月31日。字符串的内容与php DateTime
对象实现所识别的任何格式都不匹配strtotime()
(可以处理比常规strtotime()
函数更广泛的格式),然后该函数将返回#VALUE
错误。但是,Excel建议您始终对日期函数使用日期/时间戳,对PhpSpreadsheet的建议也相同:避免字符串,因为结果不可预测。
将数据写入Excel时,将应用相同的原理。包含日期实际值(而不是返回日期值的Excel函数)的单元格始终被写入Excel日期,并在必要时进行转换。如果格式化为日期的单元格包含整数或 DateTime
对象值,则将其转换为Excel值以进行写入:如果格式化为日期的单元格包含实数值,则无需进行转换。请注意,字符串值被写为字符串,而不是转换为Excel日期时间戳值。
需要日期/时间值的函数
- 达蒂夫
- 天
- DAYS360
- EDATE
- EOMONTH
- 小时
- 分钟
- 月
- 网络日
- 第二
- 平日
- WEEKNUM
- 工作日
- 年
- 年分会
辅助方法
除了setExcelCalendar()
和getExcelCalendar()
方法,\PhpOffice\PhpSpreadsheet\Shared\Date
该类中还有许多其他方法 可以帮助处理日期:
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: excelToTimestamp($ excelDate)
从Excel日期时间戳转换日期/时间以返回PHP序列化的日期/时间戳。
请注意,此方法不会捕获超出PHP日期时间戳有效范围的Excel日期。
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: excelToDateTimeObject($ excelDate)
将日期转换为Excel日期/时间戳以返回PHP DateTime
对象。
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: PHPToExcel($ PHPDate)
转换PHP序列化的日期/时间戳或PHP DateTime
对象以返回Excel日期时间戳。
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: formattedPHPToExcel($ year,$ month,$ day,$ hours = 0,$ minutes = 0,$ seconds = 0)
接受年,月和日值(以及可选的时,分和秒值),并返回Excel日期时间戳值。
时区支持Excel日期时间戳转换
PhpSpreadsheet中日期函数的默认时区为UST(通用标准时间)。如果需要使用其他时区,则可以使用以下方法:
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: getDefaultTimezone()
返回PhpSpeadsheet用于处理日期和时间的当前时区值。
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: setDefaultTimezone($ timeZone)
将Excel日期时间戳转换的时区设置为$ timeZone,该值必须是有效的PHP DateTimeZone值。返回值是一个布尔值,其中true是成功,false是失败(例如,传递了无效的DateTimeZone值。)
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: excelToDateTimeObject($ excelDate,$ timeZone)
\ PhpOffice \ PhpSpreadsheet \ Shared \ Date :: excelToTimeStamp($ excelDate,$ timeZone)
这些函数支持将时区作为可选的第二个参数。这会将特定时区应用于该函数调用,而不会影响默认的PhpSpreadsheet时区。
功能参考
数据库功能
降级
DAVERAGE函数返回列表或数据库中符合您指定条件的列中单元格的平均值。
句法
DAVERAGE (database, field, criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的平均值。
这是统计平均值。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DAVERAGE(A4:E10,"Yield",A1:B2)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 12
笔记
此功能没有其他注释
DCOUNT
DCOUNT函数返回指定列表或数据库中符合条件的列中包含数字的单元格计数。
句法
DCOUNT(database, [field], criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的计数。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DCOUNT(A4:E10,"Height",A1:B3)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 3
笔记
在MS Excel中,field参数是可选的。如果省略该字段,则DCOUNT将对数据库中符合条件的所有记录进行计数。PhpSpreadsheet中尚未实现此逻辑。
DCOUNTA
DCOUNT函数返回列表或数据库的列中不为空且匹配您指定条件的单元格计数。
句法
DCOUNTA(database, [field], criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的计数。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DCOUNTA(A4:E10,"Yield",A1:A3)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 5
笔记
在MS Excel中,field参数是可选的。如果省略该字段,则DCOUNTA将对数据库中符合条件的所有记录进行计数。PhpSpreadsheet中尚未实现此逻辑。
DGET
DGET函数从与您指定的条件匹配的列表或数据库的列中提取单个值。
句法
DGET(database, field, criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
混合从匹配行的选定列中选择的值。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=GET(A4:E10,"Age",A1:F2)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 14
笔记
此功能没有其他注释
DMAX
DMAX函数返回列表或数据库中符合您指定条件的列中的最大数字。
句法
DMAX(database, field, criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的最大值。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DMAX(A4:E10,"Profit",A1:B2)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 105
笔记
此功能没有其他注释
DMIN
DMIN函数返回与指定条件匹配的列表或数据库的列中的最小数字。
句法
DMIN(database, field, criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的最小值。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DMIN(A4:E10,"Yield",A1:A3)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 6
笔记
此功能没有其他注释
D产品
DPRODUCT函数将匹配您指定条件的列表或数据库的列中的值相乘。
句法
DPRODUCT(database, field, criteria)
参量
数据库组成列表或数据库的单元格范围。
数据库是相关数据的列表,其中相关信息的行是记录,数据的列是字段。列表的第一行包含每一列的标签。
字段指示函数中使用数据库的哪一列。
输入列标签为字符串(用双引号引起来),例如“ Age”或“ Yield”,或者输入代表列在列表中位置的数字(不带引号):1为第一列,2用于第二列,依此类推。
条件包含您指定条件的单元格范围。
您可以对criteria参数使用任何范围,只要它包含至少一个列标签和在列标签下方的至少一个单元格(您在其中为该列指定条件)即可。
返回值
float匹配单元格的乘积。
例子
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DPRODUCT(A4:E10,"Yield",A1:B2)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 140
笔记
此功能没有其他注释
DSTDEV
The DSTDEV function estimates the standard deviation of a population based on a sample by using the numbers in a column of a list or database that match conditions that you specify.
Syntax
DSTDEV(database, field, criteria)
Parameters
database The range of cells that makes up the list or database.
A database is a list of related data in which rows of related information are records, and columns of data are fields. The first row of the list contains labels for each column.
field Indicates which column of the database is used in the function.
Enter the column label as a string (enclosed between double quotation marks), such as "Age" or "Yield," or as a number (without quotation marks) that represents the position of the column within the list: 1 for the first column, 2 for the second column, and so on.
criteria The range of cells that contains the conditions you specify.
You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.
Return Value
float The estimated standard deviation of the matching cells.
Examples
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DSTDEV(A4:E10,"Yield",A1:A3)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 2.97
Notes
There are no additional notes on this function
DSTDEVP
The DSTDEVP function calculates the standard deviation of a population based on the entire population by using the numbers in a column of a list or database that match conditions that you specify.
Syntax
DSTDEVP(database, field, criteria)
Parameters
database The range of cells that makes up the list or database.
A database is a list of related data in which rows of related information are records, and columns of data are fields. The first row of the list contains labels for each column.
field Indicates which column of the database is used in the function.
Enter the column label as a string (enclosed between double quotation marks), such as "Age" or "Yield," or as a number (without quotation marks) that represents the position of the column within the list: 1 for the first column, 2 for the second column, and so on.
criteria The range of cells that contains the conditions you specify.
You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.
Return Value
float The estimated standard deviation of the matching cells.
Examples
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DSTDEVP(A4:E10,"Yield",A1:A3)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 2.65
Notes
There are no additional notes on this function
DSUM
The DSUM function adds the numbers in a column of a list or database that matches conditions you specify.
Syntax
DSUM(database, field, criteria)
Parameters
database The range of cells that makes up the list or database.
A database is a list of related data in which rows of related information are records, and columns of data are fields. The first row of the list contains labels for each column.
field Indicates which column of the database is used in the function.
Enter the column label as a string (enclosed between double quotation marks), such as "Age" or "Yield," or as a number (without quotation marks) that represents the position of the column within the list: 1 for the first column, 2 for the second column, and so on.
criteria The range of cells that contains the conditions you specify.
You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.
Return Value
float The total value of the matching cells.
Examples
$database = [
[ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'' ], [ ''Apple'', 18, 20, 14, 105.00 ], [ ''Pear'', 12, 12, 10, 96.00 ], [ ''Cherry'', 13, 14, 9, 105.00 ], [ ''Apple'', 14, 15, 10, 75.00 ], [ ''Pear'', 9, 8, 8, 76.80 ], [ ''Apple'', 8, 9, 6, 45.00 ], ]; $criteria = [ [ ''Tree'', ''Height'', ''Age'', ''Yield'', ''Profit'', ''Height'' ], [ ''="=Apple"'', ''>10'', NULL, NULL, NULL, ''<16'' ], [ ''="=Pear"'', NULL, NULL, NULL, NULL, NULL ], ]; $worksheet->fromArray( $criteria, NULL, ''A1'' ) ->fromArray( $database, NULL, ''A4'' ); $worksheet->setCellValue(''A12'', ''=DMIN(A4:E10,"Profit",A1:A2)''); $retVal = $worksheet->getCell(''A12'')->getCalculatedValue(); // $retVal = 225
Notes
There are no additional notes on this function
DVAR
Not yet documented.
DVARP
Not yet documented.
Date and Time Functions
Excel provides a number of functions for the manipulation of dates and times, and calculations based on date/time values. it is worth spending some time reading the section titled "Date and Time Values" on passing date parameters and returning date values to understand how PhpSpreadsheet reconciles the differences between dates and times in Excel and in PHP.
DATE
The DATE function returns an Excel timestamp or a PHP timestamp or DateTime
object representing the date that is referenced by the parameters.
Syntax
DATE(year, month, day)
Parameters
year The year number.
If this value is between 0 (zero) and 1899 inclusive (for the Windows 1900 calendar), or between 4 and 1903 inclusive (for the Mac 1904), then PhpSpreadsheet adds it to the Calendar base year, so a value of 108 will interpret the year as 2008 when using the Windows 1900 calendar, or 2012 when using the Mac 1904 calendar.
month The month number.
If this value is greater than 12, the DATE function adds that number of months to the first month in the year specified. For example, DATE(2008,14,2) returns a value representing February 2, 2009.
If the value of month is less than 1, then that value will be adjusted by -1, and that will then be subtracted from the first month of the year specified. For example, DATE(2008,0,2) returns a value representing December 2, 2007; while DATE(2008,-1,2) returns a value representing November 2, 2007.
day The day number.
If this value is greater than the number of days in the month (and year) specified, the DATE function adds that number of days to the first day in the month. For example, DATE(2008,1,35) returns a value representing February 4, 2008.
If the value of day is less than 1, then that value will be adjusted by -1, and that will then be subtracted from the first month of the year specified. For example, DATE(2008,3,0) returns a value representing February 29, 2008; while DATE(2008,3,-2) returns a value representing February 27, 2008.
Return Value
mixed A date/time stamp that corresponds to the given date.
This could be a PHP timestamp value (integer), a PHP DateTime
object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
.
Examples
$worksheet->setCellValue(''A1'', ''Year'')
->setCellValue(''A2'', ''Month'') ->setCellValue(''A3'', ''Day''); $worksheet->setCellValue(''B1'', 2008) ->setCellValue(''B2'', 12) ->setCellValue(''B3'', 31); $worksheet->setCellValue(''D1'', ''=DATE(B1,B2,B3)''); $retVal = $worksheet->getCell(''D1'')->getCalculatedValue(); // $retVal = 1230681600
// We''re going to be calling the same cell calculation multiple times,
// and expecting different return values, so disable calculation cacheing
\PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance()->setCalculationCacheEnabled(FALSE);
$saveFormat = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL
);
$retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATE''], [2008, 12, 31] ); // $retVal = 39813.0 \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType( \PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC ); $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATE''], [2008, 12, 31] ); // $retVal = 1230681600 \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($saveFormat);
Notes
There are no additional notes on this function
DATEDIF
The DATEDIF function computes the difference between two dates in a variety of different intervals, such number of years, months, or days.
Syntax
DATEDIF(date1, date2 [, unit])
Parameters
date1 First Date.
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
date2第二个日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
单位用于计算的间隔类型
这是一个字符串,包含下面列出的值之一:
单元 | 含义 | 描述 |
---|---|---|
米 | 月数 | 在日期之间完成日历月。 |
d | 天 | 日期之间的天数。 |
ÿ | 年份 | 在日期之间完成日历年。 |
ym | 不包括月份的月份 | 在日期之间完成日历月,就好像它们是同一年一样。 |
码 | 不含年份的天数 | 在日期之间完成日历日,就好像它们是同一年一样。 |
md | 不包括年月的天数 | 完成日期之间的日历日,就好像它们是同一月和同一年。 |
单位值不区分大小写,默认为d
。
返回值
整数反映两个日期之间差异的整数值。
这可以是两个日期之间的完整天数,月数或年数,具体取决于传递给函数的间隔单位值作为第三个参数。
例子
$worksheet->setCellValue(''A1'', ''Year'')
->setCellValue(''A2'', ''Month'') ->setCellValue(''A3'', ''Day''); $worksheet->setCellValue(''B1'', 2001) ->setCellValue(''C1'', 2009) ->setCellValue(''B2'', 7) ->setCellValue(''C2'', 12) ->setCellValue(''B3'', 1) ->setCellValue(''C3'', 31); $worksheet->setCellValue(''D1'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"d")'') ->setCellValue(''D2'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"m")'') ->setCellValue(''D3'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"y")'') ->setCellValue(''D4'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"ym")'') ->setCellValue(''D5'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"yd")'') ->setCellValue(''D6'', ''=DATEDIF(DATE(B1,B2,B3),DATE(C1,C2,C3),"md")''); $retVal = $worksheet->getCell(''D1'')->getCalculatedValue(); // $retVal = 3105 $retVal = $worksheet->getCell(''D2'')->getCalculatedValue(); // $retVal = 101 $retVal = $worksheet->getCell(''D3'')->getCalculatedValue(); // $retVal = 8 $retVal = $worksheet->getCell(''D4'')->getCalculatedValue(); // $retVal = 5 $retVal = $worksheet->getCell(''D5'')->getCalculatedValue(); // $retVal = 183 $retVal = $worksheet->getCell(''D6'')->getCalculatedValue(); // $retVal = 30
$date1 = 1193317015; // PHP timestamp for 25-Oct-2007
$date2 = 1449579415; // PHP timestamp for 8-Dec-2015 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''d''] ); // $retVal = 2966 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''m''] ); // $retVal = 97 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''y''] ); // $retVal = 8 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''ym''] ); // $retVal = 1 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''yd''] ); // $retVal = 44 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEDIF''], [$date1, $date2, ''md''] ); // $retVal = 13
笔记
如果Date1晚于Date2,则DATEDIF将返回#NUM!错误。
DATEVALUE
DATEVALUE函数返回由格式为文本字符串的日期表示的日期。使用DATEVALUE将文本表示的日期转换为序列号。
句法
DATEVALUE(dateString)
参量
date日期字符串。
字符串,表示日期值。
返回值
混合对应于给定日期的日期/时间戳。
根据的值,它可以是PHP时间戳记值(整数),PHP DateTime
对象或Excel时间戳记值(实数) \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
。
例子
$worksheet->setCellValue(''A1'', ''Date String'');
->setCellValue(''A2'', ''31-Dec-2008'') ->setCellValue(''A3'', ''31/12/2008'') ->setCellValue(''A4'', ''12-31-2008''); $worksheet->setCellValue(''B2'', ''=DATEVALUE(A2)'') ->setCellValue(''B3'', ''=DATEVALUE(A3)'') ->setCellValue(''B4'', ''=DATEVALUE(A4)''); \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType( \PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL ); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); $retVal = $worksheet->getCell(''B4'')->getCalculatedValue(); // $retVal = 39813.0 for all cases
// We''re going to be calling the same cell calculation multiple times,
// and expecting different return values, so disable calculation cacheing
\PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance()->setCalculationCacheEnabled(FALSE);
$saveFormat = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL
);
$retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEVALUE''], [''31-Dec-2008''] ); // $retVal = 39813.0 \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType( \PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC ); $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DATEVALUE''], [''31-Dec-2008''] ); // $retVal = 1230681600 \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($saveFormat);
笔记
DATEVALUE使用的php DateTime
对象实现strtotime()
(可以处理比常规strtotime()
函数更广泛的格式),并且当参数值是字符串时,也可以为传递给其他日期函数(例如DATEDIF)的任何date参数调用它。
警告: -PhpSpreadsheet比MS Excel接受更广泛的日期格式,因此Excel完全有可能返回#VALUE!传递了无法解释的日期字符串时出错,而PhpSpreadsheet可以将同一字符串转换为正确的日期值。
写入Xls或Xlsx时,在计算中使用字符串格式日期的工作簿中应格外小心。
天
DAY函数返回日期。日期以1到31之间的整数形式给出。
句法
DAY(datetime)
参量
datetime日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
返回值
整数反映月份的整数值。
整数形式,取值范围是1〜31。
例子
$worksheet->setCellValue(''A1'', ''Date String'')
->setCellValue(''A2'', ''31-Dec-2008'') ->setCellValue(''A3'', ''14-Feb-2008''); $worksheet->setCellValue(''B2'', ''=DAY(A2)'') ->setCellValue(''B3'', ''=DAY(A3)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 31 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 14
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DAYOFMONTH''],
[''25-Dec-2008'']
);
// $retVal = 25
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::DAYOFMONTH()
静态调用该方法时。
DAYS360
DAYS360函数根据某些会计系统使用的360天年(每个12个相等的期间,每个30天)来计算两个日期之间的差额。
句法
DAYS360(date1, date2 [, method])
参量
date1第一个日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
date2第二个日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
方法布尔标志(TRUE或FALSE)
这是一个标志,用于根据以下列出的值确定要在计算中使用的方法:
方法 | 描述 |
---|---|
假 | U.S. (NASD) method. If the starting date is the last day of a month, it becomes equal to the 30th of the same month. If the ending date is the last day of a month and the starting date is earlier than the 30th of a month, the ending date becomes equal to the 1st of the next month; otherwise the ending date becomes equal to the 30th of the same month. |
TRUE | European method. Starting dates and ending dates that occur on the 31st of a month become equal to the 30th of the same month. |
The method value defaults to FALSE.
Return Value
integer An integer value that reflects the difference between the two dates.
This is the number of full days between the two dates, based on a 360 day year.
Examples
$worksheet->setCellValue(''B1'', ''Start Date'')
->setCellValue(''C1'', ''End Date'') ->setCellValue(''A2'', ''Year'') ->setCellValue(''A3'', ''Month'') ->setCellValue(''A4'', ''Day''); $worksheet->setCellValue(''B2'', 2003) ->setCellValue(''B3'', 2) ->setCellValue(''B4'', 3); $worksheet->setCellValue(''C2'', 2007) ->setCellValue(''C3'', 5) ->setCellValue(''C4'', 31); $worksheet->setCellValue(''E2'', ''=DAYS360(DATE(B2,B3,B4),DATE(C2,C3,C4))'') ->setCellValue(''E4'', ''=DAYS360(DATE(B2,B3,B4),DATE(C2,C3,C4),FALSE)''); $retVal = $worksheet->getCell(''E2'')->getCalculatedValue(); // $retVal = 1558 $retVal = $worksheet->getCell(''E4'')->getCalculatedValue(); // $retVal = 1557
$date1 = 37655.0; // Excel timestamp for 25-Oct-2007
$date2 = 39233.0; // Excel timestamp for 8-Dec-2015 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DAYS360''], [$date1, $date2] ); // $retVal = 1558 $retVal = call_user_func_array( [''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''DAYS360''], [$date1, $date2, TRUE] ); // $retVal = 1557
Notes
警告:-当第三个(可选)参数使用PHP布尔值时(如上例所示),此功能当前不适用于Xls Writer,并且该编写器将生成并出错。如果方法参数使用数字0或1,它将起作用。或者,如果改用Excel TRUE()
和FALSE()
函数。
EDATE
EDATE函数返回DateTime
代表日期的Excel时间戳或PHP时间戳或对象,该日期是在指定日期(start_date)之前或之后的月份数。使用EDATE来计算到期日或到期日,该到期日或到期日与发行日期在当月的同一天。
句法
EDATE(baseDate, months)
参量
baseDate开始日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
月要添加的月数。
一个整数值,指示baseDate之前或之后的月数。几个月的正值表示将来的日期;负值表示过去的日期。
返回值
混合的日期/时间戳,与基础+月相对应。
根据的值,它可以是PHP时间戳记值(整数),PHP DateTime
对象或Excel时间戳记值(实数) \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
。
例子
$worksheet->setCellValue(''A1'', ''Date String'')
->setCellValue(''A2'', ''1-Jan-2008'') ->setCellValue(''A3'', ''29-Feb-2008''); $worksheet->setCellValue(''B2'', ''=EDATE(A2,5)'') ->setCellValue(''B3'', ''=EDATE(A3,-12)''); \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType( \PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL ); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 39600.0 (1-Jun-2008) $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 39141.0 (28-Feb-2007)
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL
);
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''EDATE''],
[''31-Oct-2008'', 25] ); // $retVal = 40512.0 (30-Nov-2010)
笔记
警告: -Xls Writer当前不支持此功能,因为它不是Excel 5中的标准功能,而是Analysis ToolPak的外接程序。
EOMONTH
The EOMONTH function returns an Excel timestamp or a PHP timestamp or DateTime
object representing the date of the last day of the month that is the indicated number of months before or after a specified date (the start_date). Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
Syntax
EOMONTH(baseDate, months)
Parameters
baseDate Start Date.
An Excel date value, PHP date timestamp, PHP DateTime
object, or a date represented as a string.
months Number of months to add.
An integer value indicating the number of months before or after baseDate. A positive value for months yields a future date; a negative value yields a past date.
Return Value
mixed A date/time stamp that corresponds to the last day of basedate + months.
根据的值,它可以是PHP时间戳记值(整数),PHP DateTime
对象或Excel时间戳记值(实数) \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
。
例子
$worksheet->setCellValue(''A1'', ''Date String'')
->setCellValue(''A2'', ''1-Jan-2000'') ->setCellValue(''A3'', ''14-Feb-2009''); $worksheet->setCellValue(''B2'', ''=EOMONTH(A2,5)'') ->setCellValue(''B3'', ''=EOMONTH(A3,-12)''); \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 39629.0 (30-Jun-2008) $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 39507.0 (29-Feb-2008)
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(
\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL
);
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''EOMONTH''],
[''31-Oct-2008'', 13] ); // $retVal = 40147.0 (30-Nov-2010)
笔记
警告: -Xls Writer当前不支持此功能,因为它不是Excel 5中的标准功能,而是Analysis ToolPak的外接程序。
小时
HOUR函数返回时间值的小时。小时以整数形式给出,范围从0(12:00 AM)到23(11:00 PM)。
句法
HOUR(datetime)
参量
datetime时间。
Excel日期/时间值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期/时间。
返回值
整数反映一天中的小时的整数值。
整数形式,取值范围是0〜23。
例子
$worksheet->setCellValue(''A1'', ''Time String'')
->setCellValue(''A2'', ''31-Dec-2008 17:30'') ->setCellValue(''A3'', ''14-Feb-2008 4:20 AM'') ->setCellValue(''A4'', ''14-Feb-2008 4:20 PM''); $worksheet->setCellValue(''B2'', ''=HOUR(A2)'') ->setCellValue(''B3'', ''=HOUR(A3)'') ->setCellValue(''B4'', ''=HOUR(A4)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 17 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 4 $retVal = $worksheet->getCell(''B4'')->getCalculatedValue(); // $retVal = 16
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''HOUROFDAY''],
[''09:30'']
);
// $retVal = 9
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::HOUROFDAY()
静态调用该方法时。
分钟
MINUTE函数返回时间值的分钟。分钟以整数形式给出,范围为0到59。
句法
MINUTE(datetime)
参量
datetime时间。
Excel日期/时间值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期/时间。
返回值
整数反映小时中分钟的整数值。
整数形式,取值范围是0〜59。
例子
$worksheet->setCellValue(''A1'', ''Time String'')
->setCellValue(''A2'', ''31-Dec-2008 17:30'') ->setCellValue(''A3'', ''14-Feb-2008 4:20 AM'') ->setCellValue(''A4'', ''14-Feb-2008 4:45 PM''); $worksheet->setCellValue(''B2'', ''=MINUTE(A2)'') ->setCellValue(''B3'', ''=MINUTE(A3)'') ->setCellValue(''B4'', ''=MINUTE(A4)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 30 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 20 $retVal = $worksheet->getCell(''B4'')->getCalculatedValue(); // $retVal = 45
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''MINUTE''],
[''09:30'']
);
// $retVal = 30
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::MINUTE()
静态调用该方法时。
月
MONTH函数返回日期的月份。月份为1到12之间的整数。
句法
MONTH(datetime)
参量
datetime日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
返回值
integer An integer value that reflects the month of the year.
This is an integer ranging from 1 to 12.
Examples
$worksheet->setCellValue(''A1'', ''Date String'');
$worksheet->setCellValue(''A2'', ''31-Dec-2008''); $worksheet->setCellValue(''A3'', ''14-Feb-2008''); $worksheet->setCellValue(''B2'', ''=MONTH(A2)''); $worksheet->setCellValue(''B3'', ''=MONTH(A3)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 12 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 2
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''MONTHOFYEAR''],
[''14-July-2008'']
);
// $retVal = 7
Notes
Note that the PhpSpreadsheet function is \PhpOffice\PhpSpreadsheet\Calculation\Functions::MONTHOFYEAR()
when the method is called statically.
NETWORKDAYS
The NETWORKDAYS function returns the number of whole working days between a start date and an end date. Working days exclude weekends and any dates identified in holidays. Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days worked during a specific term.
Syntax
NETWORKDAYS(startDate, endDate [, holidays])
Parameters
startDate Start Date of the period.
An Excel date value, PHP date timestamp, PHP DateTime
object, or a date represented as a string.
endDate End Date of the period.
An Excel date value, PHP date timestamp, PHP DateTime
object, or a date represented as a string.
假日假日日期的可选数组。
从工作日历中排除的一个或多个日期的可选范围,例如州和联邦假日以及浮动假日。
该列表可以是包含日期的单元格范围,也可以是Excel日期值,PHP日期时间戳,PHP日期对象或表示为字符串的日期的数组常量。
返回值
整数工作天数。
startDate和endDate之间的工作天数。
例子
笔记
此功能没有其他注释
现在
NOW函数返回当前日期和时间。
句法
NOW()
参量
该NOW()
功能没有参数。
返回值
混合的与当前日期和时间相对应的日期/时间戳。
根据的值,它可以是PHP时间戳记值(整数),PHP DateTime
对象或Excel时间戳记值(实数) \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType()
。
例子
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::DATETIMENOW()
静态调用该方法时。
第二
SECOND函数返回时间值的秒数。第二个整数形式,取值范围是0到59。
句法
SECOND(datetime)
参量
datetime时间。
Excel日期/时间值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期/时间。
返回值
整数反映分钟内秒数的整数值。
整数形式,取值范围是0〜59。
例子
$worksheet->setCellValue(''A1'', ''Time String'')
->setCellValue(''A2'', ''31-Dec-2008 17:30:20'') ->setCellValue(''A3'', ''14-Feb-2008 4:20 AM'') ->setCellValue(''A4'', ''14-Feb-2008 4:45:59 PM''); $worksheet->setCellValue(''B2'', ''=SECOND(A2)'') ->setCellValue(''B3'', ''=SECOND(A3)''); ->setCellValue(''B4'', ''=SECOND(A4)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 20 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 0 $retVal = $worksheet->getCell(''B4'')->getCalculatedValue(); // $retVal = 59
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''SECOND''],
[''09:30:17'']
);
// $retVal = 17
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::SECOND()
静态调用该方法时。
时间
尚未记录。
时间值
尚未记录。
今天
尚未记录。
平日
WEEKDAY函数返回给定日期的星期几。该日期以1到7之间的整数形式给出,但可以修改为返回0到6之间的值。
句法
WEEKDAY(datetime [, method])
参量
datetime日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
方法整数标志(值0、1或2)
这是一个标志,用于根据以下列出的值确定要在计算中使用的方法:
method | Description
:-----:|------------------------------------------
0 | Returns 1 (Sunday) through 7 (Saturday). 1 | Returns 1 (Monday) through 7 (Sunday). 2 | Returns 0 (Monday) through 6 (Sunday).
方法值默认为1。
返回值
整数反映星期几的整数值。
这是一个整数,范围是1到7,或0到6,取决于method的值。
例子
$worksheet->setCellValue(''A1'', ''Date String'')
->setCellValue(''A2'', ''31-Dec-2008'') ->setCellValue(''A3'', ''14-Feb-2008''); $worksheet->setCellValue(''B2'', ''=WEEKDAY(A2)'') ->setCellValue(''B3'', ''=WEEKDAY(A3,0)'') ->setCellValue(''B4'', ''=WEEKDAY(A3,2)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 12 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 2 $retVal = $worksheet->getCell(''B4'')->getCalculatedValue(); // $retVal = 2
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''WEEKDAY''],
[''14-July-2008'']
);
// $retVal = 7
笔记
请注意,PhpSpreadsheet函数是 \PhpOffice\PhpSpreadsheet\Calculation\Functions::WEEKDAY()
静态调用该方法时。
WEEKNUM
尚未记录。
工作日
尚未记录。
年
YEAR函数返回日期的年份。
句法
YEAR(datetime)
参量
datetime日期。
Excel日期值,PHP日期时间戳,PHP DateTime
对象或表示为字符串的日期。
返回值
整数反映一年中月份的整数值。
这是整数年值。
例子
$worksheet->setCellValue(''A1'', ''Date String'')
->setCellValue(''A2'', ''17-Jul-1982'') ->setCellValue(''A3'', ''16-Apr-2009''); $worksheet->setCellValue(''B2'', ''=YEAR(A2)'') ->setCellValue(''B3'', ''=YEAR(A3)''); $retVal = $worksheet->getCell(''B2'')->getCalculatedValue(); // $retVal = 1982 $retVal = $worksheet->getCell(''B3'')->getCalculatedValue(); // $retVal = 2009
$retVal = call_user_func_array(
[''\PhpOffice\PhpSpreadsheet\Calculation\Functions'', ''YEAR''],
[''14-July-2001'']
);
// $retVal = 2001
笔记
此功能没有其他注释
年分会
尚未记录
CSpreadSheet中文文档
CSpreadSheet中文文档
http://www.codeproject.com/info/Licenses.aspx
简介
CSpreadSheet是一个C++编写的Excel读写控件,当我们希望输出Excel文件或以文
本文件分隔 以Tab分隔的文件时, CSpreadSheet能使我们的工作事半功倍.该控件
能方便我们读写此类文件,以对象的形式供我们使用.
主要特征
创建Excel文件或文本特征文件.,写入多行或单行.读取多行,列,一行从Excel文件
或文本特征文件.替代、插入、追加到Excel文件或文本特征文件.转换已存在或最近
打开的Excel文件或文本特征文件.
限制
该控件需要MFC(微软基础类库)支持.未测试是否支持Unicode编码.控件以ODBC读写
Excel文件,需要ODBC驱动程序.Excel文件必须列标记.且首行列标记唯一(字段).禁止
删除工作簿,仅允许删除工作簿内容.列值类型参照程序数据类型.不采用Excel格式.
一,如何使用此类?
常用函数:
CSpreadSheet(CString File, CString SheetOrSeparator, bool Backup = true)
bool AddHeaders(CStringArray &FieldNames, bool replace = false)
bool AddRow(CStringArray &RowValues, long row = 0, bool replace = false)
bool AddCell(CString CellValue, short column, long row = 0)
bool AddCell(CString CellValue, CString column, long row = 0,bool Auto=true)
bool ReadRow(CStringArray &RowValues, long row = 0)
bool ReadColumn(CStringArray &ColumnValues, short column)
bool ReadColumn(CStringArray &ColumnValues, CString column,bool Auto = true)
bool ReadCell (CString &CellValue, short column, long row = 0)
bool ReadCell (CString &CellValue,CString column,long row=0,bool Auto=true)
bool DeleteSheet()
bool DeleteSheet(CString SheetName)
bool Convert(CString SheetOrSeparator)
void BeginTransaction()
bool Commit()
bool RollBack()
bool GetTransactionStatus()
void GetFieldNames (CStringArray &FieldNames)
long GetTotalRows()
short GetTotalColumns()
long GetCurrentRow()
bool GetBackupStatus()
CString GetLastError()
Excel特定函数:
bool ReplaceRows(CStringArray &NewRowValues, CStringArray &OldRowValues)
文本函数:
尚无.
函数介绍:
CSpreadSheet(CString File, CString SheetOrSeparator, bool Backup = true)
该构造函数将打开Excel(xls)文件或其他制定工作簿的文件以供读写.创建一个CSpreadSheet对象.
参数:
File: 文件路径,可以是绝对路径或相对路径,如果文件不存在将创建一个文件.
SheetOrSeparator 工作簿名.
Backup 制定是否备份文件,默认未备份文件,如果文件存在,将创建一个名为CSpreadSheetBackup 的备份文件.
bool AddHeaders(CStringArray &FieldNames, bool replace = false)
该函数将在打开的工作簿的首行添加一个头(字段).对于Excel,每列字段必须唯一.对于特
定特征的文本文件没有限制.对于一个打开的工作簿文件,默认将添加一列,如果设置replace=true
将替代存在的字段值.该函数返回一个Bool类型的值.对于Excel,该函数需
在添加任意行之前调用.对于特定特征的文本文件,该函数可选.
参数:
FieldNames 字段名数组.
Replace 如字段存在,该参数将决定是否替代原有字段.
bool AddRow(CStringArray &RowValues, long row = 0, bool replace = false)
该函数将追加、插入或替代一行到已经打开的文档,默认追加到行的尾部.替代将以变量的值而定,新的一行将插入或替代到指定的行.
参数:
RowValues 行值
Row 行编号,如果Row=1 第一行.即字段行.
Replace 如果该行存在,指示是否替代原有行.
bool AddCell(CString CellValue, short column, long row = 0)
bool AddCell(CString CellValue, CString column, long row = 0,bool Auto=true)
添加或替代一个打开的工作簿中的单元格,默认为该行的最后一个单元格.返回一个Bool类型的值(状态);
参数:
CellValue 填充的单元格的值。
Column 列编号
column 列名
Row 含编号,如果Row=1 第一行,即字段行.
Auto 是否让函数自动判断自动判断字段.
bool ReadRow(CStringArray &RowValues, long row = 0)
从打开的工作簿中读取一行,默认读取下一行,如果你没有使用连接池,连续运行两次,则第一次读取第一行,第二次读取第二行.返回一个Bool类型的值(状态);
参数:
RowValues 用于存储读取到的值。
Row 行编号.默认为第一行.
bool ReadColumn(CStringArray &ColumnValues, short column)
bool ReadColumn(CStringArray &ColumnValues, CString column,bool Auto = true)
从打开的工作簿中读取一列.返回一个Bool类型的值(状态);
参数:
Short column 列编号
CString column 列名或字段名.
Columnvalues 存储读取到的值.
Auto 设置函数自动扫描列名或字段.
bool ReadCell (CString &CellValue, short column, long row = 0)
bool ReadCell (CString &CellValue,CString column,long row=0,bool Auto=true)
从打开的工作簿中读取一个单元格的值。默认读取下一行.返回一个Bool类型的值(状态);
参数:
CellValue 存储单元格的值.
Short column 列编号.
Row 行编号
CString column 列名
Auto 设置函数自动扫描列名或字段.
bool DeleteSheet()
从打开的文档中删除所有的工作簿内容.返回一个Bool类型的值(状态);
bool DeleteSheet(CString SheetName)
从打开的文档中删除指定工作簿名的工作簿内容.返回一个Bool类型的值(状态);
参数:
SheetName 工作簿名.e.G Sheet1
bool Convert(CString SheetOrSeparator)
将Excel(xls)文件转换为特定特征的文本文件(.csv)或将特定特征的文本文件(.csv)转换为Excel(xls)文件.如果
将特定特征的文本文件(.csv)转换为Excel(xls)文件SheetOrSeparator将不会被使用.返回一个Bool类型的值(状态);
参数:
SheetOrSeparator 特征样式.
void BeginTransaction()
bool Commit()
bool Commit()
与SQL语言函数,函数相似,BeginTransaction开始事务,Commit提交事务.RoolBack回滚至保存点.Commit Commit将返回一个Bool值来表示是否成功.
bool GetTransactionStatus()
查询事务的状态,如果为true 表明已经开始,false表明没有开始或已经结束.
void GetFieldNames (CStringArray &FieldNames)
返回一个工作簿中的字段数组.
参数:
FieldNames 存储字段名的数组.
long GetTotalRows()
获得工作簿中行数.返回行数.
short GetTotalColumns()
获得工作簿中列数.返回列数.
long GetCurrentRow()
获得已选择的当前行的行号.返回行号,当前行将调用默认的ReadRow函数.
bool GetBackupStatus()
获得备份执行情况,true 已经执行,false没有执行(用户选择)或执行错误.
CString GetLastError()
返回最后一次错误信息.
Excel特定函数:
bool ReplaceRows(CStringArray &NewRowValues, CStringArray &OldRowValues)
该函数将搜索且代替多次执行的值.不支持已经回滚或释放的文档.执行完将返回执行的状态.
参数:
NewRowValues 新的值,即更新的值.
OldRowValues 原有的值,即已经存在的值.
示例:
// Create a new Excel spreadsheet, filename is test.xls, sheetname is TestSheet
CSpreadSheet SS("Test.xls", "TestSheet");
// Fill a sample 5 by 5 sheet
CStringArray sampleArray, testRow, Rows, Column;
CString tempString;
char alphabet = ''A'';
SS.BeginTransaction();
for (int i = 1; i <= 5; i++)
{
sampleArray.RemoveAll();
for (int j = 1; j <= 5; j++)
{
tempString.Format("%c%d", alphabet++, i);
sampleArray.Add(tempString);
}
alphabet = ''A'';
if (i == 1) // Add header rows
{
SS.AddHeaders(sampleArray);
}
else // Add data rows
{
SS.AddRow(sampleArray);
}
}
// Set up test row for appending, inserting and replacing
for (int k = 1; k <= 5; k++)
{
testRow.Add("Test");
}
SS.AddRow(testRow); // append test row to spreadsheet
SS.AddRow(testRow, 2); // insert test row into second row of spreadsheet
SS.AddRow(testRow, 4, true); // replace fourth row of spreadsheet with test row
SS.Committ();
SS.Convert(";"); // convert Excel spreadsheet into text delimited format
// with ; as separator
// print out total number of rows
printf("Total number of rows = %d\n\n", SS.GetTotalRows());
// Print out entire spreadsheet
for (i = 1; i <= SS.GetTotalRows(); i++)
{
// Read row
SS.ReadRow(Rows, i);
for (int j = 1; j <= Rows.GetSize(); j++)
{
if (j != Rows.GetSize())
{
printf("%s\t", Rows.GetAt(j-1));
}
else
{
printf("%s\n", Rows.GetAt(j-1));
}
}
}
// print out total number of columns
printf("\nTotal number of columns = %d\n\n", SS.GetTotalColumns());
// Read and print out contents of second column of spreadsheet
SS.ReadColumn(Column, 2);
for (i = 0; i < Column.GetSize(); i++)
{
printf("Column 2 row %d: %s\n", i+1, Column.GetAt(i));
}
// Read in and print out the cell value at column 3, row 3 of spreadsheet
if (SS.ReadCell(tempString, 3, 3))
{
printf("\nCell value at (3,3): %s\n", tempString);
}
else
{
// print out error message if cell value cannot be read
printf("Error: %s\n", SS.GetLastError);
}
About Author:
Yap Chun Wei
http://www.codeproject.com/Members/Yap-Chun-Wei
翻译:
武汉软件工程职业学院 孟德军
http://hi.baidu.Com/mak0000
下载:
http://www.codeproject.com/KB/database/CSpreadSheet/CSpreadSheet_src.zip
Jspreadsheet v4: The javascript spreadsheet
Jspreadsheet v4: The javascript spreadsheet
Jexcel has been renamed to Jspreadsheet.Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based online interactive tables and spreadsheets compatible with other spreadsheet software. You can create an online spreadsheet table from a JS array, JSON, CSV or XSLX files. You can copy from excel and paste straight to your online spreadsheet and vice versa. It is very easy to integrate any third party javascript plugins to create your own custom columns, custom editors, and customize any feature into your application. Jspreadsheet has plenty of different input options through its native column types to cover the most common web-based application requirements. It is a complete solution for web data management. Create amazing online spreadsheets with Jspreadsheet.
For enterprise projects go Pro Version (exclusive features, plugins, extensions and technical support). You can test our Pro Version in development for free for as long as you need.
With a few simple steps, you can have Jspreadsheet integrated into your applications. Impress your clients with better user experience with this amazing data interactive tool.
- Make rich and user-friendly web interfaces and applications
- You can easily handle complicated data inputs in a way users are used to
- Improve your user software experience
- Create rich CRUDS and beautiful UI
- Compatibility with excel spreadsheets: users can move data around with common copy and paste shortcuts
- Easy customizations with easy third-party plugin integrations
- Lean, fast and simple to use
- Thousands of successfully user cases
- Speed up your work dealing with difficult data entry in a web-based software
- Create and share amazing online spreadsheets
Create amazing online spreadsheets
A example how to embed a simple javascript spreadsheet in your application. You can check out for more examples here.
Car | Make | Available | Photo | Stock | Price | G | |
Jazz | 12/02/2019 | $ 2.000,00 | |||||
Civic | 11/07/2018 | $ 4.000,01 |
Installation
- % npm install jspreadsheet-ce
Spreadsheet source code example
- <html>
- <script src="https://bossanova.uk/jspreadsheet/v4/jexcel.js"></script>
- <link rel="stylesheet" href="https://bossanova.uk/jspreadsheet/v4/jexcel.css" type="text/css" />
- <script src="https://jsuites.net/v4/jsuites.js"></script>
- <link rel="stylesheet" href="https://jsuites.net/v4/jsuites.css" type="text/css" />
- <div id="spreadsheet"></div>
- <script>
- var data = [
- ['Jazz', 'Honda', '2019-02-12', '', true, '$ 2.000,00', '#777700'],
- ['Civic', 'Honda', '2018-07-11', '', true, '$ 4.000,01', '#007777'],
- ];
- jspreadsheet(document.getElementById('spreadsheet'), {
- data:data,
- columns: [
- {
- type: 'text',
- title:'Car',
- width:90
- },
- {
- type: 'dropdown',
- title:'Make',
- width:120,
- source:[
- "Alfa Romeo",
- "Audi",
- "Bmw",
- "Chevrolet",
- "Chrystler",
- // (...)
- ]
- },
- {
- type: 'calendar',
- title:'Available',
- width:120
- },
- {
- type: 'image',
- title:'Photo',
- width:120
- },
- {
- type: 'checkBox',
- title:'Stock',
- width:80
- },
- {
- type: 'numeric',
- title:'Price',
- mask:'$ #.##,00',
- width:80,
- decimal:','
- },
- {
- type: 'color',
- width:80,
- render:'square',
- },
- ]
- });
- </script>
- </html>
Jspreadsheet History
Jspreadsheet 4.6.0
- Jexcel is renamed to Jpreadsheet
- Integration with Jsuites v4
Jspreadsheet 4.2.3
- The spreadsheet plugin Now compatible with Jsuites v3.
- New flags, security implementation
- New DOM element references in the Toolbar and tabs spreadsheet worksheet events
4.0.0
A special thank to the FDL - Fonds de Dotation du Libre support and sponsorship that make the new online spreadsheet version possible with so many nice features.
- The online spreadsheet with Support workbooks/tabs
- Create a dynamic spreadsheet table from a HTML static element
- Highlight the selected cells in the spreadsheet after CTRL+C
- Footer with formula support
- Multiple columns resize
- JSON update support (Helpers to update a Remote Server)
- Javascript spreadsheet global super event (centralized method to dispatch all events in one)
- Custom helpers: =PROGRESS (progressbar), =rating (5 star rating)
- Custom helpers: =COLUMN, =ROW, =CELL, =TABLE, =VALUE information to be used on formula execution
- Dynamic nested header updates
- A new column type for HTML editing
- New flags such as: includeHeadersOncopy, persistance, filters, autoCasting, freezeColumns
- New events such as: onevent, onchangepage, onbeforesave, onsave
- More examples and documentation
Jspreadsheet 3.9.0
- New methods
- General fixes
Jspreadsheet 3.6.0
- Better spreadsheet formula parsing
- New javascript spreadsheet events
- New initialization options
- General fixes
Jspreadsheet 3.2.3
- getMeta, setMeta methods
- Npm package with jSuites
- General fixes
Jspreadsheet 3.0.1
Jspreadsheet v3 is a complete rebuilt of the javascript spreasheet jquery plugin version. For that reason it was not possible to keep a complete compatibility with the prevIoUs version. If you are upgraging you might need to implement a few updates in your code. If you have questions, you can review the article upgraging from Jspreadsheet Spreadsheet v2 or Handsontable.
The Jspreadsheet v3 brings lot of great new features:
- Drag and drop columns
- Resizable rows
- Merge columns
- Search
- Pagination
- Lazy loading
- Full screen flag
- Image upload
- Native color picker
- Better mobile compatibility
- Better nested headers compatibily
- Amazing keyboard navegation support
- Better hidden column management
- Great data picker: dropdown, autocomplete, multiple, group options and icons
- Importing from XSLX (experimental)
Big improviments are included, such as:
- Complete new formula engine with no external depencies with much faster results.
- Absolutely no selectors, means a much faster application
- New native columns
- No jQuery is required
- React, Vue and Angular examples
- XLXS support using a custom sheetjs (Experimental).
Jspreadsheet 2.1.0
We are glad to bring you the latest jquery plugin version, with the following improvements:
- Mobile touch fixes
- Paste fixes & New CSV parser
Jspreadsheet 2.0.0
- New radio column
- New dropdown with autocomplete and multiple selection options
- Header/body separation for a better scroll/column resize behavior and compatibility
- Better text-wrap including alt+enter excel compatibility
- New set/get Meta information
- New set/get config parameters
- New set/get programmatically cell style
- New set/get cell comments
- New table custom toolbar
- New responsive calendar picker
Jspreadsheet 1.5.7
- CheckBox column type improvements
- Destroy jquery table updates
Jspreadsheet 1.5.1
- Spreadsheet data overflow and fixed headers. See an example
- Navigation improvements
Jspreadsheet 1.5.0
- Relative insertRow, deleteRow, insertColumn, deleteColumn. See an example
- Redo, Undo action tracker for insertRow, deleteRow, insertColumn, deleteColumn, moveRow
- New formula column recursive chain
- New alternative design option bootstrap-like. See an example
- updateSettings updates
Javascript spreadsheet examples
- Create from a HTML table
A full example on how to create a dynamic jspreadsheet table from a HTML table.
- Using tabs
Grouping multiple spreasheets in tabs.
- Formulas on table footer
Adding formulas fixed on the table footer.
- React Implementation
A full example on how to integrate Jspreadsheet with React
- VUE Implementation
A full example on how to integrate Jspreadsheet with Vue
- Angular Implementation
A full example on how to integrate Jspreadsheet with Angular
- Jquery Implementation
A full example on how to integrate Jspreadsheet with Jquery
- Search and pagination
Full spreadsheet example with search and pagination to bring great compatibility for those who love datatables.
- Column types
Learn more about the powerful column types. This example brings all native column types and how to create your own custom type.
- Advanced dropdown
Full examples on how to handle simple, advanced, multiple, autocomplete and conditional dropdowns. Create amazing javascript tables using categories and images in your dropdowns.
- Date and datetime picker
Example from basic to advanced calendar usage, date and datetime picker
- Images
This examples shows how to embed and upload images to your spreadsheet
- Richtext column
This examples shows how to create a richtext column
- Programmatically updates
How to update your spreadsheet and its data by javascript
- Table Style
Bring a very special touch to your applications customizing your javascript spreadsheet.
- Table Scripting
Customize the table behavior using javascript
- Events
Learn how to handle events on Jspreadsheet
- Importing data
How to import data from an external CSV, json file or XLSX.
- Formulas
Unleash the power of your tables bringing formulas and custom javascript methods on your Jspreadsheet spreadsheet.
- Custom toolbars
Full example on how to enable nor customize your javascript spreadsheet toolbar.
- Cell comments
Allow comments in your table spreadsheet.
- Headers
Header updates and column dragging
- Nested headers
Enabled nested headers in your spreadsheet and learn how to set or get header values
- Column dragging
Enabled the column dragging
- Translations
How to translate the default messages from Jspreadsheet
- Meta information
Keep hidden information about your cells using Meta information methods
- Merged cells
Full example on how to handle merge cells in your javascript tables.
- Sorting columns
Example how to sort the table by a column via javascript.
- Readonly Columns
Example how to setup readonly cells
- Lazy loading
This example brings a very nice feature to deal with large table datasets.
- Custom Contextmenu
How to customize jspreadsheet contextmenu
- Table overflow
How define a fixed width and height for the jspreadsheet tables.
- Column filters
How to enable column filters on a Jspreadsheet - the online spreadsheet.
- Freeze columns
Setup freeze columns in Jspreadsheet
copyright and license
Jspreadsheet is released under the MIT license.The software is registered under UK law. Contact contact@jspreadsheet.com
About Jspreadsheet
The Jspreadsheet is a full original javascript software created to facilitate the data manipulation in web based applications. It was created to be an easy javascript data input tool for users and it was created inspired on other spreadsheet software.This software is free and was created to be a light alternative to create amazing online javascript spreadsheets.
laravel-phpspreadsheet 导入导出
之前的excel导入导出用的是 Maatwebsite\Excel ,实际内部调用的还是 PhpOffice\PhpSpreadsheet。并且可用方法太少了,如果导入大量数据,即使使用队列,在初次拉取数据的时候可能会超出内存限制报错。还不如直接使用PhpSpreadsheet。
官方文档: https://phpspreadsheet.readthedocs.io/en/latest/
相关代码
$file = base_path(''storage/app/public/''.$curfile); // 保存或生成文件完整路径
if(file_exist($file)){
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);//如果文件存在则直接载入
$sheet = $spreadsheet->getActiveSheet();//获取活动的工作sheet
}else{
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();//文件不存在则实例化一个新的文件
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(''A1'', ''订单号'');//新文件需要设置头部
$sheet->setCellValue(''B1'', ''支付金额'');
$sheet->setCellValue(''C1'', ''购买数量'');
$sheet->setCellValue(''D1'', ''单价'');
}
$row = 1;//记录行数
foreach ($orders as $key => $value) {// 写入数据
$sheet->setCellValue(''A''.($row+1), $value->order_id.'','');
$sheet->setCellValue(''B''.($row+1), $order_code.'','');
$sheet->setCellValue(''C''.($row+1), $value->num);
$row++;
}
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($file);//写入excel文件并保存
// ....执行其他代码
// 更新导出记录表
// 如果是大量数据,则可以通过递归,再创建新队列,记录写入数据
大致代码如上。更多方法查看文档
php 使用phpoffice/phpspreadsheet拓展实现导出图片
基础操作参考:https://blog.csdn.net/huaweichenai/article/details/95994006
文档地址:https://phpspreadsheet.readthedocs.io/
github地址:https://github.com/PHPOffice/PhpSpreadsheet
导出插入图片主要使用\PhpOffice\PhpSpreadsheet\Worksheet\Drawing实现
一:方法介绍
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName(''Logo'');//设置图片名称
$drawing->setDescription(''Logo'');//设备图片描述
$drawing->setPath(''./images/officelogo.jpg'');//设置图片地址
$drawing->setHeight(36);//设置图片高度
$drawing->setCoordinates(''A1'');//设置图片绘制到指定单元格
$drawing->setWorksheet($spreadsheet->getActiveSheet());//将图片绘制到工作表
二:实现实例
$spreadsheet = new Spreadsheet();//创建一个新的excel文档
$sheet = $spreadsheet->getActiveSheet();//获取当前操作sheet的对象
//将图片绘制到excel中
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath($img);
$drawing->setHeight(50);
$drawing->setCoordinates(''A1'');
$drawing->setWorksheet($sheet);
$writer = new Xlsx($spreadsheet);
$writer->save(''xxx.xlsx'');//生成excel文件
//将多个图片绘制到excel中
$spreadsheet = new Spreadsheet();//创建一个新的excel文档
$sheet = $spreadsheet->getActiveSheet();//获取当前操作sheet的对象
//将图片绘制到excel中
foreach ($imgs as $img) {
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath($img);
$drawing->setHeight(50);
$drawing->setCoordinates(''A1'');
$drawing->setWorksheet($sheet);
}
$writer = new Xlsx($spreadsheet);
$writer->save(''xxx.xlsx'');//生成excel文件
我们今天的关于phpspreadsheet 中文文档和三 计算引擎的分享已经告一段落,感谢您的关注,如果您想了解更多关于CSpreadSheet中文文档、Jspreadsheet v4: The javascript spreadsheet、laravel-phpspreadsheet 导入导出、php 使用phpoffice/phpspreadsheet拓展实现导出图片的相关信息,请在本站查询。
本文标签: