Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PHP_XLSXWriter
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 101
    • Issues 101
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 24
    • Merge requests 24
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • mk-j
  • PHP_XLSXWriter
  • Merge requests
  • !66
An error occurred while fetching the assigned milestone of the selected merge_request.

Hyperlinks Support Added

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Mayank requested to merge github/fork/mayank/master into 2018-06-0.38 8 years ago
  • Overview 0
  • Commits 5
  • Pipelines 1
  • Changes 2

Added Support for adding Hyperlinks to the Cells using a separate array to be passed when writeSheet() is called. You can see example for more details.

Compare
  • version 1
    23617c99
    2 years ago

  • 2018-06-0.38 (base)

and
  • latest version
    23617c99
    5 commits, 2 years ago

  • version 1
    23617c99
    5 commits, 2 years ago

2 files
+ 79
- 2

    Preferences

    File browser
    Compare changes
example-cli-h‎yperlinks.php‎ +44 -0
xlsxwriter‎.class.php‎ +35 -2
example-cli-hyperlinks.php 0 → 100644
+ 44
- 0
  • View file @ 23617c99

  • Edit in single-file editor

  • Open in Web IDE

<?php
include_once("xlsxwriter.class.php");
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
$filename = "example.xlsx";
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$header = array(
'year'=>'string',
'month'=>'string',
'amount'=>'money',
'first_event'=>'datetime',
'second_event'=>'date',
'url' => 'string'
);
$data1 = array(
array('2003','1','-50.5','2010-01-01 23:00:00','2012-12-31 23:00:00','Visit Google'),
array('2003','=B2', '23.5','2010-01-01 00:00:00','2012-12-31 00:00:00','Visit Github Profile'),
);
$data2 = array(
array('2003','01','343.12'),
array('2003','02','345.12'),
);
$hyperlinks = array(
'F2' => array( 'name' => 'Visit Google', 'link' => 'https://www.google.com/' ),
'F3' => array( 'name' => 'My Profile', 'link' => 'https://mayank.github.io/' )
);
$writer = new XLSXWriter();
$writer->setAuthor('Some Author');
$writer->writeSheet($data1,'Sheet1',$header, $hyperlinks);
$writer->writeSheet($data2,'Sheet2');
#$writer->writeToStdOut();
$writer->writeToFile('example.xlsx');
//echo $writer->writeToString();
exit(0);
xlsxwriter.class.php
+ 35
- 2
  • View file @ 23617c99

  • Edit in single-file editor

  • Open in Web IDE


Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.
@@ -98,6 +98,10 @@ class XLSXWriter
$zip->addEmptyDir("xl/worksheets/");
foreach($this->sheets as $sheet) {
$zip->addFile($sheet->filename, "xl/worksheets/".$sheet->xmlname );
// adding relationships for worksheets
$zip->addEmptyDir("xl/worksheets/_rels/");
$zip->addFile($sheet->rel_filename, "xl/worksheets/_rels/".$sheet->xmlname.".rels" );
}
$zip->addFromString("xl/workbook.xml" , self::buildWorkbookXML() );
$zip->addFile($this->writeStylesXML(), "xl/styles.xml" ); //$zip->addFromString("xl/styles.xml" , self::buildStylesXML() );
@@ -107,7 +111,32 @@ class XLSXWriter
$zip->addFromString("xl/_rels/workbook.xml.rels", self::buildWorkbookRelsXML() );
$zip->close();
}
protected function insertHyperlinks($sheet_name, $hyperlinks)
{
$sheet = &$this->sheets[$sheet_name];
$sheet->relfile_writer->write('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$sheet->relfile_writer->write('<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">');
$sheet->file_writer->write('<hyperlinks>');
$count = 1;
foreach( $hyperlinks as $columnId => $linkData ){
$sheet->file_writer->write('<hyperlink ref="'.$columnId.'" r:id="rId'.$count.'" display="'.self::xmlspecialchars($linkData["name"]).'"></hyperlink>');
$sheet->relfile_writer->write('<Relationship Id="rId'.$count.'" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="'.self::xmlspecialchars($linkData["link"]).'" TargetMode="External" />');
$count++;
}
$sheet->file_writer->write('</hyperlinks>');
$sheet->relfile_writer->write('</Relationships>');
$sheet->relfile_writer->close();
}
protected function initializeSheet($sheet_name, $col_widths=array() )
{
//if already initialized
@@ -115,11 +144,14 @@ class XLSXWriter
return;
$sheet_filename = $this->tempFilename();
$sheet_rel_filename = $this->tempFilename();
$sheet_xmlname = 'sheet' . (count($this->sheets) + 1).".xml";
$this->sheets[$sheet_name] = (object)array(
'filename' => $sheet_filename,
'sheetname' => $sheet_name,
'xmlname' => $sheet_xmlname,
'rel_filename' => $sheet_rel_filename,
'relfile_writer' => new XLSXWriter_BuffererWriter($sheet_rel_filename),
'row_count' => 0,
'file_writer' => new XLSXWriter_BuffererWriter($sheet_filename),
'columns' => array(),
@@ -306,7 +338,7 @@ class XLSXWriter
$sheet->merge_cells[] = $startCell . ":" . $endCell;
}
public function writeSheet(array $data, $sheet_name='', array $header_types=array())
public function writeSheet(array $data, $sheet_name='', array $header_types=array(), array $hyperlinks=array())
{
$sheet_name = empty($sheet_name) ? 'Sheet1' : $sheet_name;
$data = empty($data) ? array(array('')) : $data;
@@ -318,6 +350,7 @@ class XLSXWriter
{
$this->writeSheetRow($sheet_name, $row);
}
$this->insertHyperlinks($sheet_name, $hyperlinks);
$this->finalizeSheet($sheet_name);
}
@@ -897,4 +930,4 @@ class XLSXWriter_BuffererWriter
// vim: set filetype=php expandtab tabstop=4 shiftwidth=4 autoindent smartindent:
// vim: set filetype=php expandtab tabstop=4 shiftwidth=4 autoindent smartindent:
\ No newline at end of file
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
William Cheng
Reference:
Source branch: github/fork/mayank/master

Menu

Explore Projects Groups Snippets