|
@@ -1,28 +1,39 @@
|
|
-## Excel-Export
|
|
|
|
|
|
+## xlswriter [ Excel-Export ]
|
|
|
|
|
|
Authon: viest [[email protected]](mailto:[email protected])
|
|
Authon: viest [[email protected]](mailto:[email protected])
|
|
|
|
|
|
--------
|
|
|
|
|
|
+## 安装
|
|
|
|
+
|
|
|
|
+- [编译安装](#编译安装)
|
|
|
|
+- [PECL](#PECL)
|
|
|
|
+
|
|
|
|
+## 使用
|
|
|
|
+
|
|
|
|
+1. [创建一个简单的xlsx文件](#创建一个简单的xlsx文件)
|
|
|
|
+2. [单元格插入文字](#单元格插入文字)
|
|
|
|
+3. [单元格插入链接](#单元格插入链接)
|
|
|
|
+4. [单元格插入公式](#单元格插入公式)
|
|
|
|
+5. [单元格插入本地图片](#单元格插入本地图片)
|
|
|
|
+6. [数据过滤](#数据过滤)
|
|
|
|
+7. [合并单元格](#合并单元格)
|
|
|
|
+8. [设置列单元格样式](#设置列单元格格式)
|
|
|
|
+9. [设置行单元格样式](#设置行单元格格式)
|
|
|
|
+10. [固定内存导出](#固定内存导出)
|
|
|
|
+11. [创建工作表](#创建工作表)
|
|
|
|
+12. [组合样式](#组合样式)
|
|
|
|
+13. [样式列表](#样式列表)
|
|
|
|
+
|
|
|
|
+## PECL
|
|
|
|
|
|
-- **安装**
|
|
|
|
- - **[编译安装 Excel-Export](#编译安装)**
|
|
|
|
-- **使用**
|
|
|
|
- - **[创建一个简单的xlsx文件](#创建一个简单的xlsx文件)**
|
|
|
|
- - **[1、向单元格插入文字](#向单元格插入文字)**
|
|
|
|
- - **[2、单元格插入公式](#单元格插入公式)**
|
|
|
|
- - **[3、单元格插入本地图片](#单元格插入本地图片)**
|
|
|
|
- - **[4、数据过滤](#数据过滤)**
|
|
|
|
- - **[5、合并单元格](#合并单元格)**
|
|
|
|
- - **[6、设置列单元格格式](#设置列单元格格式)**
|
|
|
|
- - **[7、设置行单元格格式](#设置行单元格格式)**
|
|
|
|
- - **[8、固定内存导出](#固定内存导出)**
|
|
|
|
- - **[9、向文件追加表格](#追加表格)**
|
|
|
|
|
|
+```bash
|
|
|
|
+pecl install xlswriter
|
|
|
|
|
|
---------
|
|
|
|
|
|
+# 添加 extension = xlswriter.so 到 ini 配置
|
|
|
|
+```
|
|
|
|
|
|
-### 编译安装
|
|
|
|
|
|
+## 编译安装
|
|
|
|
|
|
-#### Unix
|
|
|
|
|
|
+### Unix
|
|
|
|
|
|
##### Ubuntu
|
|
##### Ubuntu
|
|
|
|
|
|
@@ -31,7 +42,7 @@ Authon: viest [[email protected]](mailto:[email protected])
|
|
|
|
|
|
sudo apt-get install -y zlib1g-dev
|
|
sudo apt-get install -y zlib1g-dev
|
|
|
|
|
|
-# Excel-Export
|
|
|
|
|
|
+# 扩展
|
|
|
|
|
|
git clone https://github.com/viest/php-ext-excel-export.git
|
|
git clone https://github.com/viest/php-ext-excel-export.git
|
|
|
|
|
|
@@ -53,7 +64,7 @@ make && make install
|
|
|
|
|
|
brew install zlib
|
|
brew install zlib
|
|
|
|
|
|
-# Excel-Export
|
|
|
|
|
|
+# 扩展
|
|
|
|
|
|
git clone https://github.com/viest/php-ext-excel-export.git
|
|
git clone https://github.com/viest/php-ext-excel-export.git
|
|
|
|
|
|
@@ -122,7 +133,7 @@ $filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
|
|
->output();
|
|
->output();
|
|
```
|
|
```
|
|
|
|
|
|
-### 向单元格插入文字
|
|
|
|
|
|
+### 单元格插入文字
|
|
|
|
|
|
#### 语法
|
|
#### 语法
|
|
|
|
|
|
@@ -162,9 +173,53 @@ for ($index = 0; $index < 10; $index++) {
|
|
$textFile->output();
|
|
$textFile->output();
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+### 单元格插入链接
|
|
|
|
+
|
|
|
|
+#### 函数原型
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+insertUrl(int $row, int $column, string $url[, resource $format])
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+##### int $row
|
|
|
|
+
|
|
|
|
+> 单元格所在行
|
|
|
|
+
|
|
|
|
+##### int $column
|
|
|
|
+
|
|
|
|
+> 单元格所在列
|
|
|
|
+
|
|
|
|
+##### string $url
|
|
|
|
+
|
|
|
|
+> 链接地址
|
|
|
|
+
|
|
|
|
+##### resource $format
|
|
|
|
+
|
|
|
|
+> 链接样式
|
|
|
|
+
|
|
|
|
+##### 实例
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+$excel = new \Vtiful\Kernel\Excel($config);
|
|
|
|
+
|
|
|
|
+$urlFile = $excel->fileName("free.xlsx")
|
|
|
|
+ ->header(['url']);
|
|
|
|
+
|
|
|
|
+$fileHandle = $fileObject->getHandle();
|
|
|
|
+
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$urlStyle = $format->bold()
|
|
|
|
+ ->underline(Format::UNDERLINE_SINGLE)
|
|
|
|
+ ->toResource();
|
|
|
|
+
|
|
|
|
+$urlFile->insertUrl(1, 0, 'https://github.com', $urlStyle);
|
|
|
|
+
|
|
|
|
+$textFile->output();
|
|
|
|
+```
|
|
|
|
+
|
|
### 单元格插入公式
|
|
### 单元格插入公式
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
insertFormula(int $row, int $column, string $formula)
|
|
insertFormula(int $row, int $column, string $formula)
|
|
@@ -203,7 +258,7 @@ $freeFile->output();
|
|
|
|
|
|
### 单元格插入本地图片
|
|
### 单元格插入本地图片
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
insertImage(int $row, int $column, string $localImagePath[, double $widthScale, double $heightScale])
|
|
insertImage(int $row, int $column, string $localImagePath[, double $widthScale, double $heightScale])
|
|
@@ -245,7 +300,7 @@ $freeFile->output();
|
|
|
|
|
|
### 数据过滤
|
|
### 数据过滤
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
autoFilter(string $scope);
|
|
autoFilter(string $scope);
|
|
@@ -267,7 +322,7 @@ $excel->fileName('test.xlsx')
|
|
|
|
|
|
### 合并单元格
|
|
### 合并单元格
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
mergeCells(string $scope, string $data);
|
|
mergeCells(string $scope, string $data);
|
|
@@ -291,7 +346,7 @@ $excel->fileName("test.xlsx")
|
|
|
|
|
|
### 设置列单元格格式
|
|
### 设置列单元格格式
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
setColumn(string $range, double $width [, resource $format]);
|
|
setColumn(string $range, double $width [, resource $format]);
|
|
@@ -329,7 +384,7 @@ $fileObject->header(['name', 'age'])
|
|
|
|
|
|
### 设置行单元格格式
|
|
### 设置行单元格格式
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
setRow(string $range, double $height [, resource $format]);
|
|
setRow(string $range, double $height [, resource $format]);
|
|
@@ -377,7 +432,7 @@ $fileObject->header(['name', 'age'])
|
|
|
|
|
|
最大内存使用量 = 最大一行的数据占用量
|
|
最大内存使用量 = 最大一行的数据占用量
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
constMemory(string $fileName);
|
|
constMemory(string $fileName);
|
|
@@ -401,9 +456,9 @@ $fileObject->header(['name', 'age'])
|
|
->output();
|
|
->output();
|
|
```
|
|
```
|
|
|
|
|
|
-### 追加表格
|
|
|
|
|
|
+### 创建工作表
|
|
|
|
|
|
-#### 语法
|
|
|
|
|
|
+#### 函数原型
|
|
|
|
|
|
```php
|
|
```php
|
|
addSheet([string $sheetName]);
|
|
addSheet([string $sheetName]);
|
|
@@ -433,3 +488,83 @@ $fileObject->addSheet()
|
|
$filePath = $fileObject->output();
|
|
$filePath = $fileObject->output();
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+### 组合样式
|
|
|
|
+
|
|
|
|
+将多个样式合并为一个新样式应用在单元格上
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+// 将粗体与斜体合并为一个样式
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$boldItalicStyle = $format->bold()->italic()->toResource();
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+### 样式列表
|
|
|
|
+
|
|
|
|
+##### 粗体
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$boldStyle = $format->bold()->toResource();
|
|
|
|
+```
|
|
|
|
+##### 斜体
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$italicStyle = $format->italic()->toResource();
|
|
|
|
+```
|
|
|
|
+##### 下划线
|
|
|
|
+
|
|
|
|
+###### 函数原型
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+underline(resource $resourchHandle, Format::const $style): \Vtiful\Kernel\Format
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+###### 实例
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$underlineStyle = $format->underline(Format::UNDERLINE_SINGLE)->toResource();
|
|
|
|
+```
|
|
|
|
+###### Style
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+Format::UNDERLINE_SINGLE; // 单下划线
|
|
|
|
+Format::UNDERLINE_DOUBLE; // 双下划线
|
|
|
|
+Format::UNDERLINE_SINGLE_ACCOUNTING; // 会计用单下划线
|
|
|
|
+Format::UNDERLINE_DOUBLE_ACCOUNTING; // 会计用双下划线
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+##### 对齐
|
|
|
|
+
|
|
|
|
+###### 函数原型
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+align(resource $resourchHandle, Format::const ...$style): \Vtiful\Kernel\Format
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+###### 实例
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+$format = new \Vtiful\Kernel\Format($fileHandle);
|
|
|
|
+$alignStyle = $format
|
|
|
|
+ ->align(Format::FORMAT_ALIGN_CENTER, Format::FORMAT_ALIGN_VERTICAL_CENTER)
|
|
|
|
+ ->toResource();
|
|
|
|
+```
|
|
|
|
+###### Style
|
|
|
|
+
|
|
|
|
+```php
|
|
|
|
+Format::FORMAT_ALIGN_LEFT; // 水平左对齐
|
|
|
|
+Format::FORMAT_ALIGN_CENTER; // 水平剧中对齐
|
|
|
|
+Format::FORMAT_ALIGN_RIGHT; // 水平右对齐
|
|
|
|
+Format::FORMAT_ALIGN_FILL; // 水平填充对齐
|
|
|
|
+Format::FORMAT_ALIGN_JUSTIFY; // 水平两端对齐
|
|
|
|
+Format::FORMAT_ALIGN_CENTER_ACROSS; // 横向中心对齐
|
|
|
|
+Format::FORMAT_ALIGN_DISTRIBUTED; // 分散对齐
|
|
|
|
+Format::FORMAT_ALIGN_VERTICAL_TOP; // 顶部垂直对齐
|
|
|
|
+Format::FORMAT_ALIGN_VERTICAL_BOTTOM; // 底部垂直对齐
|
|
|
|
+Format::FORMAT_ALIGN_VERTICAL_CENTER; // 垂直剧中对齐
|
|
|
|
+Format::FORMAT_ALIGN_VERTICAL_JUSTIFY; // 垂直两端对齐
|
|
|
|
+Format::FORMAT_ALIGN_VERTICAL_DISTRIBUTED; // 垂直分散对齐
|
|
|
|
+```
|
|
|
|
+
|