### Example usage of getPageSetup Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-page-setup.md Demonstrates how to open a file, select a sheet, and retrieve its page setup configuration. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $ps = $excel->openFile('source.xlsx') ->openSheet() ->getPageSetup(); var_export($ps); ``` -------------------------------- ### Install Dependencies Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/ubuntu.md Installs the necessary zlib development library for compiling extensions. ```bash apt-get install -y zlib1g-dev ``` -------------------------------- ### Installation Dependencies Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/windows.md Steps to download and build zlib, a dependency for some PHP extensions. ```bash cd PHP_BUILD_PATH/deps DownloadFile http://zlib.net/zlib-1.2.11.tar.gz 7z x zlib-1.2.11.tar.gz > NUL 7z x zlib-1.2.11.tar > NUL cd zlib-1.2.11 cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_C_FLAGS_RELEASE="/MT" cmake --build . --config "Release" ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-link.md An example demonstrating how to insert a URL with custom formatting. ```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(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/margins.md An example demonstrating how to set margins for an Excel file. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setPaper(\Vtiful\Kernel\Excel::PAPER_A3) ->setLandscape() ->setMargins(1, 1, 2, 2) ->output(); ``` -------------------------------- ### Function Test Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/ubuntu.md Runs the test suite to verify the installation. ```bash make && make test ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-style-format.md An example demonstrating how to use getStyleFormat to retrieve cell formatting details. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->openFile('source.xlsx')->openSheet(); $row = $excel->nextRowWithFormula(); $sid = $row[0]['style_id']; print_r($excel->getStyleFormat($sid)); // Array // ( // [num_fmt_id] => 14 // [category] => date // [format_string] => m/d/yyyy // [font] => Array ( [name] => Calibri [size] => 11 ... ) // [fill] => Array ( [pattern_type] => solid [fg_color] => FFFFFF00 ... ) // [border] => Array ( [left] => Array ( [style] => thin [color] => FF000000 ) ... ) // [alignment] => Array ( [horizontal] => center [vertical] => center ... ) // [protection] => Array ( [locked] => 1 [hidden] => 0 ) // ) ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/underline.md An example demonstrating how to use the underline function to apply a single underline style. ```php $format = new \Vtiful\Kernel\Format($fileHandle); $underlineStyle = $format->underline(Format::UNDERLINE_SINGLE)->toResource(); ``` -------------------------------- ### Example of getting sheet protection Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-sheet-protection.md An example demonstrating how to open a file, select a sheet, and retrieve its protection settings. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $prot = $excel->openFile('source.xlsx') ->openSheet() ->getSheetProtection(); var_export($prot); ``` -------------------------------- ### Get page setup method Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-page-setup.md This method returns the page setup configuration of the active worksheet. ```php getPageSetup(): ?array ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/sheet-list-with-meta.md An example demonstrating how to use sheetListWithMeta to get worksheet metadata. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $meta = $excel->openFile('source.xlsx') ->sheetListWithMeta(); print_r($meta); // Array // ( // [0] => Array ( [name] => Sheet1 [state] => visible ) // [1] => Array ( [name] => Hidden [state] => hidden ) // ) ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/create.md An example demonstrating how to create and append worksheets to an Excel file. ```php $config = [ 'path' => './filePath' ]; $excel = new \Vtiful\Kernel\Excel($config); // A worksheet is automatically created here $fileObject = $excel->fileName("tutorial01.xlsx"); $fileObject->header(['name', 'age']) ->data([['viest', 21]]); // append a worksheet to the file $fileObject->addSheet() ->header(['name', 'age']) ->data([['wjx', 22]]); // Finally, the output file $filePath = $fileObject->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/align.md An example demonstrating how to use the align method to set both horizontal and vertical alignment to center. ```php $format = new \Vtiful\Kernel\Format($fileHandle); $alignStyle = $format ->align(Format::FORMAT_ALIGN_CENTER, Format::FORMAT_ALIGN_VERTICAL_CENTER) ->toResource(); ``` -------------------------------- ### Get Formula AST Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-formula-ast.md Demonstrates how to parse a formula string into an abstract syntax tree (AST) and displays the output using var_export. ```php var_export(\\Vtiful\\Kernel\\Excel::getFormulaAst('=SUM(A1:A10) + 1')); // Output is shaped like: // array ( // 'kind' => 'op', // 'op' => '+', // 'args' => array ( // 0 => array ( // 'kind' => 'func', // 'name' => 'SUM', // 'args' => array ( 0 => array ('kind' => 'range', 'text' => 'A1:A10') ), // ), // 1 => array ('kind' => 'number', 'value' => 1.0), // ), // ) ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/cell-border.md An example demonstrating how to create and apply a thin border style to cells. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $data = [ ['viest1', 21, 100, "A"], ['viest2', 20, 80, "B"], ['viest3', 22, 70, "C"], ]; $format = new \Vtiful\Kernel\Format($fileHandle); // Create a border style $borderStyle = $format ->border(\Vtiful\Kernel\Format::BORDER_THIN) ->toResource(); $fileObject->header(['name', 'age', 'score', 'level']) ->data($data) ->setRow('A1', 20, $borderStyle) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-conditional-formats.md An example demonstrating how to use the getConditionalFormats method to retrieve conditional formatting rules from an Excel file. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $cfs = $excel->openFile('source.xlsx') ->openSheet() ->getConditionalFormats(); var_export($cfs); ``` -------------------------------- ### Example of getting auto filter Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-auto-filter.md An example demonstrating how to retrieve the auto filter settings from an Excel file. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $af = $excel->openFile('source.xlsx') ->openSheet() ->getAutoFilter(); var_export($af); // array ( // 'range' => 'A1:C100', // 'columns' => array ( // 0 => array ( 'col_id' => 0, 'type' => 'list', 'values' => array ('apple','pear') ), // ), // ) ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/chart/data-input.md Complete example demonstrating how to create an Excel file, add data, and insert a chart with multiple data series. ```php $config = ['path' => './tests']; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_COLUMN); $chartResource = $chart->series('Sheet1!$A$1:$A$5')      ->series('Sheet1!$B$1:$B$5')      ->series('Sheet1!$C$1:$C$5')      ->toResource(); $filePath = $fileObject->data([      [1, 2, 3],      [2, 4, 6],      [3, 6, 9],      [4, 8, 12],      [5, 10, 15], ])->insertChart(0, 3, $chartResource)->output(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/row-column-options.md Example usage of row and column option retrieval methods. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->openFile('source.xlsx')->openSheet(); print_r($excel->getRowOptions(0)); // Array ( [height] => 24 [hidden] => false [outline_level] => 0 [collapsed] => false [custom_height] => true ) print_r($excel->getColumnOptions('B')); // Array ( [width] => 18 [hidden] => false [outline_level] => 0 [collapsed] => false ) var_dump($excel->getDefaultRowHeight()); // float(15) var_dump($excel->getDefaultColumnWidth()); // float(8.43) or NULL ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-hyperlinks.md Example of how to use the getHyperlinks method to retrieve hyperlinks from an Excel file and print them. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $links = $excel->openFile('source.xlsx') ->openSheet() ->getHyperlinks(); print_r($links); // Array // ( // [0] => Array // ( // [first_row] => 1 // [first_col] => 1 // [last_row] => 1 // [last_col] => 1 // [url] => https://www.php.net // [location] => // [display] => PHP home // [tooltip] => Click to visit // ) // ) ``` -------------------------------- ### Instance Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/switch.md Example of creating an Excel file, adding data, adding a new worksheet, and switching between worksheets. ```php $config = [    'path' => './tests' ]; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName("tutorial01.xlsx"); $fileObject->header(['name', 'age'])      ->data([      ['viest', 21],      ['viest', 22],      ['viest', 23],      ]); // Add a worksheet and insert data $fileObject->addSheet('twoSheet')      ->header(['name', 'age'])      ->data([['vikin', 22]]); / / Switch back to the default work table, and append data $fileObject->checkoutSheet('Sheet1')      ->data([['sheet1']]); $filePath = $fileObject->output(); ``` -------------------------------- ### Example of getting defined names Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-defined-names.md An example demonstrating how to open an Excel file and retrieve its defined names. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $names = $excel->openFile('source.xlsx') ->getDefinedNames(); print_r($names); // Array // ( // [0] => Array // ( // [name] => TaxRate // [formula] => Sheet1!$A$1 // [scope] => // [hidden] => false // ) // ) ``` -------------------------------- ### Quick start example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/conditional-format/README.md This example demonstrates how to highlight cells in a range with a red background and white font if their value is greater than 50. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); // Style applied when the rule matches $highlight = (new \Vtiful\Kernel\Format($fileHandle)) ->background(\Vtiful\Kernel\Format::COLOR_RED) ->fontColor(\Vtiful\Kernel\Format::COLOR_WHITE) ->toResource(); // Build the rule: cell type + greater than 50 + apply $highlight $cf = new \Vtiful\Kernel\ConditionalFormat(); $cf->type(\Vtiful\Kernel\ConditionalFormat::TYPE_CELL) ->criteria(\Vtiful\Kernel\ConditionalFormat::CRITERIA_GREATER_THAN) ->value(50) ->format($highlight); $fileObject->header(['score']) ->data([[10], [60], [80]]) ->conditionalFormatRange('A2:A4', $cf) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/cell_callback.md An example demonstrating how to create an Excel file and then read it using the `nextCellCallback` method. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $filePath = $excel->fileName('tutorial.xlsx')     ->header(['Item', 'Cost'])     ->data([         ['Item_1', 'Cost_1'],     ])     ->output(); $excel->openFile('tutorial.xlsx')->nextCellCallback(function ($row, $cell, $data) {     echo 'cell:' . $cell . ', row:' . $row . ', value:' . $data . PHP_EOL; }); ``` -------------------------------- ### Install xlswriter via PECL Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/pecl.md This command installs the xlswriter extension using PECL. After installation, you need to add `extension = xlswriter.so` to your php.ini configuration file. ```bash pecl install xlswriter # Add extension = xlswriter.so to ini configuration ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/rich-text.md An example demonstrating how to insert rich text with multiple styles into a cell. ```php $config = [ 'path' => './tests' ]; $excel = new \Vtiful\Kernel\Excel($config); $file = $excel->fileName('tutorial.xlsx'); $fileHandle = $file->getHandle(); $boldStyle = (new \Vtiful\Kernel\Format($fileHandle)) ->bold() ->toResource(); $redStyle = (new \Vtiful\Kernel\Format($fileHandle)) ->fontColor(\Vtiful\Kernel\Format::COLOR_RED) ->toResource(); $italicStyle = (new \Vtiful\Kernel\Format($fileHandle)) ->italic() ->toResource(); $file->insertRichText(0, 0, [ new \Vtiful\Kernel\RichString('Hello ', $boldStyle), new \Vtiful\Kernel\RichString('World', $redStyle), new \Vtiful\Kernel\RichString(' from ', null), new \Vtiful\Kernel\RichString('xlswriter', $italicStyle), ])->output(); ``` -------------------------------- ### Categories Parameter Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/chart/data-input.md Example of specifying category names. ```php Category Name ``` -------------------------------- ### APK Install Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/alpine.md This snippet shows the command to install the php7-pecl-xlswriter package using apk. ```bash apk add php7-pecl-xlswriter ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/repeat-columns.md An example demonstrating how to set columns to repeat on each printed page. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age', 'city']) ->data([ ['viest', 21, 'Beijing'], ['wjx', 21, 'Shanghai'] ]) ->repeatColumns('A:A') // Repeat column A on every printed page ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/portrait.md Example of how to set the printing direction to portrait using the library. ```php $config = ['path' =>'./tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('printed_portrait.xlsx','sheet1') ->setPortrait() // Set the printing direction to portrait ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-merged-cells.md An example demonstrating how to use the getMergedCells method to retrieve merged cell information. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $merged = $excel->openFile('source.xlsx') ->openSheet() ->getMergedCells(); print_r($merged); // Array // ( // [0] => Array // ( // [first_row] => 1 // [first_col] => 1 // [last_row] => 1 // [last_col] => 3 // ) // ) ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/landscape.md An example demonstrating how to use the setLandscape() method to set the printing direction to landscape. ```php $config = ['path' =>'./tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('printed_landscape.xlsx','sheet1') ->setLandscape() // Set the printing direction to landscape ->output(); ``` -------------------------------- ### Multi-range example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/conditional-format/multi-range.md Example demonstrating how to apply a conditional format rule to three disjoint ranges. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $highlight = (new \Vtiful\Kernel\Format($fileHandle)) ->background(\Vtiful\Kernel\Format::COLOR_RED) ->fontColor(\Vtiful\Kernel\Format::COLOR_WHITE) ->toResource(); $cf = new \Vtiful\Kernel\ConditionalFormat(); $cf->type(\Vtiful\Kernel\ConditionalFormat::TYPE_CELL) ->criteria(\Vtiful\Kernel\ConditionalFormat::CRITERIA_GREATER_THAN) ->value(50) ->format($highlight) ->multiRange('A2:A6 C2:C6 E2:E6'); // conditionalFormatRange still needs a starting range for the first parameter; // the actual targets come from the multiRange() string above. $fileObject->header(['x', '_', 'y', '_', 'z']) ->data([ [10, '', 60, '', 30], [70, '', 20, '', 80], [55, '', 45, '', 90], [40, '', 35, '', 25], [85, '', 65, '', 15], ]) ->conditionalFormatRange('A2:A6', $cf) ->output(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style/default-format.md Example of applying default formats to cells. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('tutorial.xlsx'); $format = new \Vtiful\Kernel\Format($excel->getHandle()); $colorOneStyle = $format ->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE) ->border(\Vtiful\Kernel\Format::BORDER_DASH_DOT) ->toResource(); $format = new \Vtiful\Kernel\Format($excel->getHandle()); $colorTwoStyle = $format ->fontColor(\Vtiful\Kernel\Format::COLOR_GREEN) ->toResource(); $filePath = $excel // Apply the first style as the default ->defaultFormat($colorOneStyle) ->header(['hello', 'xlswriter']) // Apply the second style as the default style ->defaultFormat($colorTwoStyle) ->data([ ['hello', 'xlswriter'], ]) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/column-style.md An example demonstrating how to set a column width and apply a bold style to it. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName('tutorial01.xlsx'); $fileHandle = $fileObject->getHandle(); $format = new \Vtiful\Kernel\Format($fileHandle); $boldStyle = $format->bold()->toResource(); $fileObject->header(['name', 'age']) ->data([['viest', 21]]) ->setColumn('A:A', 200, $boldStyle) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/table/options.md An example demonstrating how to use various table options to configure a sales table with a total row, banded columns, and highlighted first column. ```php $config = ['path' => './']; $excel = new \Vtiful\Kernel\Excel($config); $table = new \Vtiful\Kernel\Table(); $table->name('Sales') ->totalRow() ->bandedColumns() ->firstColumn() ->columns([ ['header' => 'Region', 'total_string' => 'Total'], ['header' => 'Amount', 'total_function' => \Vtiful\Kernel\Table::FUNCTION_SUM], ]); $excel->fileName('tutorial.xlsx') ->data([ ['East', 100], ['West', 90], ['', 0], // reserved for the total row ]) ->addTable('A1:B4', $table) ->output(); ``` -------------------------------- ### Install zlib dependency Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/mac.md Installs the zlib library, a common dependency for compiling extensions, using the Homebrew package manager. ```bash brew install zlib ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/scale.md An example demonstrating how to set the print scale to 180%. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setPaper(\Vtiful\Kernel\Excel::PAPER_A3) ->setLandscape() ->setMargins(1, 1, 2, 2) ->setPrintScale(180) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/first.md An example demonstrating how to set the current worksheet as the first worksheet. ```php $config = ['path' =>'./tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('hide.xlsx','sheet1') // Initialize the file and initialize the first sheet at the same time sheet1 ->header(['sheet1']) // insert data in sheet1 worksheet ->addSheet('sheet2') // Add a new sheet sheet2, and set the current active sheet to sheet2 ->setCurrentSheetIsFirst() // The current active sheet is sheet2, and set sheet2 as the first sheet ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/header-footer.md Example demonstrating how to set header and footer text with format codes and options. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setHeader('&L&"Arial,Bold"&14Sales Report&R&D') ->setFooter('&CPage &P of &N', ['margin' => 0.4]) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/gridlines.md An example demonstrating how to hide gridlines for a worksheet. ```php $config = ['path' =>'./tests']; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName("tutorial01.xlsx"); $fileObject->header(['name','age']) ->gridline(\Vtiful\Kernel\Excel::GRIDLINES_HIDE_ALL) // Set the grid line of the worksheet ->data([ ['viest', 21], ['viest', 22], ['viest', 23], ]) ->output(); ``` -------------------------------- ### Instance Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/zoom.md An example demonstrating how to set the worksheet zoom factor to 200. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName("tutorial01.xlsx"); $fileObject->header(['name', 'age']) ->zoom(200) // Set the worksheet zoom factor ->data([ ['viest', 21], ['viest', 22], ['viest', 23], ]) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/sheet_list.md Example demonstrating how to create an Excel file with multiple sheets, retrieve the list of sheets, and then access data from each sheet. ```php $excel = new \Vtiful\Kernel\Excel(['path' => './tests']); // Build the sample file $filePath = $excel // First worksheet ->fileName('tutorial.xlsx', 'test1') ->header(['sheet']) ->data([['test1']]) // Second worksheet ->addSheet('test2') ->header(['sheet']) ->data([['test2']]) ->output(); // Open the sample file $sheetList = $excel->openFile('tutorial.xlsx') ->sheetList(); Foreach ($sheetList as $sheetName) { echo 'Sheet Name:' . $sheetName . PHP_EOL; // Get the worksheet data by the worksheet name $sheetData = $excel ->openSheet($sheetName) ->getSheetData(); var_dump($sheetData); } ``` -------------------------------- ### stopIfTrue example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/conditional-format/multi-range.md Example illustrating the use of stopIfTrue to control rule precedence. ```php $first = new \Vtiful\Kernel\ConditionalFormat(); $first->type(\Vtiful\Kernel\ConditionalFormat::TYPE_CELL) ->criteria(\Vtiful\Kernel\ConditionalFormat::CRITERIA_GREATER_THAN) ->value(90) ->format($highlightGold) ->stopIfTrue(); $second = new \Vtiful\Kernel\ConditionalFormat(); $second->type(\Vtiful\Kernel\ConditionalFormat::TYPE_CELL) ->criteria(\Vtiful\Kernel\ConditionalFormat::CRITERIA_GREATER_THAN) ->value(60) ->format($highlightYellow); $fileObject->conditionalFormatRange('A2:A10', $first) ->conditionalFormatRange('A2:A10', $second); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-formula.md An example demonstrating how to insert a formula to calculate a sum. ```php $excel = new \Vtiful\Kernel\Excel($config); $freeFile = $excel->fileName("free.xlsx") ->header(['name', 'money']); for($index = 1; $index < 10; $index++) { $textFile->insertText($index, 0, 'viest'); $textFile->insertText($index, 1, 10); } $textFile->insertText(12, 0, "Total"); $textFile->insertFormula(12, 1, '=SUM(B2:B11)'); $freeFile->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/csv/put-csv.md An example demonstrating how to create an Excel file, then open it and use the putCSV function to append data to a CSV file. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $filePath = $excel->fileName('tutorial.xlsx', 'TestSheet1') ->header(['Item', 'Cost']) ->data([ ['Item_1', 'Cost_1', 10, 10.9999995], ]) ->output(); // Write mode is on, pointing the file pointer to the end of the file. $fp = fopen('./tests/file.csv', 'a'); $csvResult = $excel->openFile('tutorial.xlsx') ->openSheet() ->putCSV($fp); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/page-breaks.md Example demonstrating how to use horizontalPageBreaks and verticalPageBreaks to set page breaks in an Excel file. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $rows = []; for ($i = 1; $i <= 100; $i++) { $rows[] = ["row{$i}", $i]; } $filePath = $fileObject->header(['name', 'value']) ->data($rows) ->horizontalPageBreaks([20, 40, 60, 80]) // New page every 20 rows ->verticalPageBreaks([3]) // Page break before column 3 ->output(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/properties/custom.md Example of using setCustomProperty to add custom properties to an Excel file. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setCustomProperty('Department', 'Sales') // inferred as string ->setCustomProperty('Confidential', true) // inferred as boolean ->setCustomProperty('Revision', 3) // inferred as number ->setCustomProperty('Reviewed', time(), 'datetime') // datetime must be explicit ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/text-size.md An example demonstrating how to set the font size for cells in an Excel file. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $format = new \Vtiful\Kernel\Format($fileHandle); $style = $format->fontSize(30)->toResource(); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setRow('A1', 50, $style) ->setRow('A2:A3', 50, $style) ->output(); var_dump($filePath); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/csv/put-csv-callback.md Example demonstrating how to use putCSVCallback to export data to a CSV file. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel ($config); $filePath = $excel-> fileName('tutorial.xlsx', 'TestSheet1') ->header(['String', 'Int', 'Double']) ->data([ ['Item_1', 10, 10.9999995], ]) ->output (); $fp = fopen ('./ tests / file.csv', 'w'); $csvResult = $excel->openFile('tutorial.xlsx') ->openSheet() ->putCSVCallback(function (array $row) { return $row; }, $fp); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/border-four-sides.md Example of how to use borderOfTheFourSides to apply different border styles to each side of a cell. ```php $config = [ 'path' => './tests' ]; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $borderStyle = (new \Vtiful\Kernel\Format($fileHandle)) ->borderOfTheFourSides( \Vtiful\Kernel\Format::BORDER_THIN, // top \Vtiful\Kernel\Format::BORDER_MEDIUM, // right \Vtiful\Kernel\Format::BORDER_THIN, // bottom \Vtiful\Kernel\Format::BORDER_DASHED // left ) ->toResource(); $fileObject->header(['name', 'score']) ->setRow('A1', 20, $borderStyle) ->output(); ``` -------------------------------- ### Example Usage of iterateImages Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/iterate-images.md Example demonstrating how to use the iterateImages method to iterate through embedded images and save them. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->openFile('source.xlsx'); $excel->iterateImages(function (array $img) { echo "image at ({$img['from_row']}, {$img['from_col']}), MIME={$img['mime']}\n"; file_put_contents('./out_' . $img['name'], $img['data']); }, 'Sheet1'); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-text.md An example demonstrating how to insert text and numerical data into an Excel sheet. ```php $excel = new \Vtiful\Kernel\Excel($config); $textFile = $excel->fileName("free.xlsx") ->header(['name', 'money']); for ($index = 0; $index < 10; $index++) { $textFile->insertText($index+1, 0, 'viest'); $textFile->insertText($index+1, 1, 10000, '#,##0'); // #,##0 is the cell data style } $textFile->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/table/README.md An example demonstrating how to create a table with custom name, style, and columns, and then add it to an Excel file. ```php $config = ['path' => './']; $excel = new \Vtiful\Kernel\Excel($config); $table = new \Vtiful\Kernel\Table(); $table->name('Performance') ->style(\Vtiful\Kernel\Table::STYLE_TYPE_LIGHT, 11) ->columns([ ['header' => 'Name'], ['header' => 'Score'], ]); $excel->fileName('tutorial.xlsx') ->data([ ['Alice', 90], ['Bob', 80], ]) ->addTable('A1:B3', $table) ->output(); ``` -------------------------------- ### Example — buffer Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-image.md Example of inserting an image using its raw bytes. ```php $excel = new \Vtiful\Kernel\Excel($config); $bytes = file_get_contents('/vagrant/logo.png'); $excel->fileName('tutorial.xlsx') ->insertImageBuffer(5, 0, $bytes, [ 'x_scale' => 0.5, 'y_scale' => 0.5, 'url' => 'https://github.com/viest/php-ext-xlswriter', 'description' => 'xlswriter logo', ]) ->output(); ``` -------------------------------- ### Value Parameter Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/chart/data-input.md Example of how to specify the worksheet and cell range for individual category data. ```php Sheet1 ! $A$1 : $A$5 Worksheet ! Start cell : End cell ``` -------------------------------- ### Fit to pages example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/fit-to-pages.md This example demonstrates how to use the fitToPages method to scale the worksheet to fit within a specified number of pages horizontally and vertically. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age', 'city', 'email']) ->data([ ['viest', 21, 'Beijing', 'viest@example.com'], ['wjx', 21, 'Shanghai', 'wjx@example.com'] ]) ->fitToPages(1, 0) // Fit to 1 page wide, unlimited height ->output(); ``` -------------------------------- ### Example — path Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-image.md Example of inserting an image using its file path. ```php $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('tutorial.xlsx') ->insertImage(5, 0, '/vagrant/logo.png') ->output(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/worksheet/tab-color.md Example of setting the tab color using an RGB integer and a constant. ```php $config = [ 'path' => './tests' ]; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('tutorial.xlsx', 'sheet1') ->setTabColor(0xFF0000) ->addSheet('sheet2') ->setTabColor(\Vtiful\Kernel\Format::COLOR_GREEN) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/font-size.md Example demonstrating how to create a style with a specific font size and apply it to cells. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); // Create a style resource $format = new \Vtiful\Kernel\Format($fileHandle); $style = $format->fontSize(30)->toResource(); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->setRow('A1', 50, $style) // Apply style ->setRow('A2:A3', 50, $style) // Apply style ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/cell/insert-date.md An example demonstrating how to use the insertDate function to insert a date into a spreadsheet. ```php $excel = new \Vtiful\Kernel\Excel($config); $dateFile = $excel->fileName("free.xlsx") ->header(['date']); $dateFile->insertDate(1, 0, time(), 'mmm d yyyy hh:mm AM/PM'); $textFile->output(); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/style-list/indent.md Example of how to use the indent function to set different indent levels for text in cells. ```php $config = [ 'path' => './tests' ]; $excel = new \Vtiful\Kernel\Excel($config); $fileObject = $excel->fileName('tutorial.xlsx'); $fileHandle = $fileObject->getHandle(); $level1 = (new \Vtiful\Kernel\Format($fileHandle)) ->indent(1) ->toResource(); $level3 = (new \Vtiful\Kernel\Format($fileHandle)) ->indent(3) ->toResource(); $fileObject->header(['title']) ->insertText(1, 0, 'level 1', null, $level1) ->insertText(2, 0, 'level 3', null, $level3) ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/page-setup/repeat-rows.md Example of how to use the repeatRows function to repeat a row on every printed page. ```php $config = [ 'path' => './tests' ]; $fileObject = new \Vtiful\Kernel\Excel($config); $fileObject = $fileObject->fileName('tutorial.xlsx'); $filePath = $fileObject->header(['name', 'age']) ->data([ ['viest', 21], ['wjx', 21] ]) ->repeatRows('1:1') // Repeat row 1 on every printed page ->output(); ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-data-validations.md Example of how to use the getDataValidations method to retrieve data validations from an Excel file. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $dvs = $excel->openFile('source.xlsx') ->openSheet() ->getDataValidations(); print_r($dvs); ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/legacy-create-file/read-full.md PHP code demonstrating how to create an Excel file, write header information, and then read the entire sheet data. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $filePath = $excel->fileName('tutorial.xlsx') ->header(['Item', 'Cost']) ->output(); $data = $excel->openFile('tutorial.xlsx') ->openSheet() ->getSheetData(); var_dump($data) ``` -------------------------------- ### Example Usage Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/set-type.md An example demonstrating how to use the `setType` method to specify data types for columns and retrieve sheet data. ```php $data = $excel->openFile('tutorial.xlsx')     ->openSheet()     ->setType([         \Vtiful\Kernel\Excel::TYPE_STRING,         \Vtiful\Kernel\Excel::TYPE_INT,         \Vtiful\Kernel\Excel::TYPE_TIMESTAMP,     ])     ->getSheetData(); var_dump($data); ``` -------------------------------- ### Table Styling Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/table/style.md This example demonstrates how to create a table with a specific name and style (Medium 9) and add it to an Excel file. ```php $config = ['path' => './']; $excel = new \Vtiful\Kernel\Excel($config); $table = new \Vtiful\Kernel\Table(); $table->name('Performance') ->style(\Vtiful\Kernel\Table::STYLE_TYPE_MEDIUM, 9) ->columns([ ['header' => 'Name'], ['header' => 'Score'], ]); $excel->fileName('tutorial.xlsx') ->data([ ['Alice', 90], ['Bob', 80], ]) ->addTable('A1:B3', $table) ->output(); ``` -------------------------------- ### Get Author Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/helper/get_author.md Get the author of the Excel file. ```php var_dump(xlswriter_get_author()); // output:string(26) "Jiexing.Wang (wjx@php.net)" ``` -------------------------------- ### Sample Output Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/cell_callback.md The expected output when running the example code. ```text cell:0, row:0, value:Item cell:1, row:0, value:Cost cell:1, row:0, value:XLSX_ROW_END // end identifier cell:0, row:1, value:Item_1 cell:1, row:1, value:Cost_1 cell:1, row:1, value:XLSX_ROW_END // end identifier ``` -------------------------------- ### Example Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/legacy-create-file/read-cursor.md Demonstrates how to open an Excel file and read rows using the cursor. ```php $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $filePath = $excel->fileName('tutorial.xlsx') ->header(['Item', 'Cost']) ->output(); $excel->openFile('tutorial.xlsx') ->openSheet(); var_dump($excel->nextRow()); // ['Item', 'Cost'] var_dump($excel->nextRow()); // NULL ``` -------------------------------- ### Compiling Extensions Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/windows.md Steps to clone, configure, and compile a PHP extension (php-ext-excel-export) on Windows. ```bash cd PHP_PATH/ext git clone https://github.com/viest/php-ext-excel-export.git cd php-ext-excel-export git submodule update --init phpize configure.bat --with-xlswriter --with-extra-libs=PATH\zlib-1.2.11\Release --with-extra-includes=PATH\zlib-1.2.11 nmake ``` -------------------------------- ### Compile Extensions Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/install/ubuntu.md Clones the repository, updates submodules, and compiles the xlswriter extension. ```bash git clone https://github.com/viest/php-ext-excel-export cd php-ext-excel-export git submodule update --init phpize && ./configure --with-php-config=/path/to/php-config --enable-reader make && make install ``` -------------------------------- ### Create an Excel file with data Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/quick-start/create.md This snippet shows how to initialize the Excel object, specify the file name and sheet name, add headers and data, and then output the file. ```php $config = ['path' => '/home/viest']; $excel = new \Vtiful\Kernel\Excel($config); // fileName will automatically create a worksheet, // you can customize the worksheet name, the worksheet name is optional $filePath = $excel->fileName('tutorial01.xlsx', 'sheet1') ->header(['Item', 'Cost']) ->data([ ['Rent', 1000], ['Gas', 100], ['Food', 300], ['Gym', 50], ]) ->output(); ``` -------------------------------- ### Get sheet protection method signature Source: https://github.com/viest/php-ext-xlswriter-doc/blob/master/en/reader/get-sheet-protection.md The method signature for getSheetProtection. ```php getSheetProtection(): ?array ```