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
  • !233
An error occurred while fetching the assigned milestone of the selected merge_request.

Avoiding error when using writeToStdOut/String with an empty document.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/Dj1b/master into master 6 years ago
  • Overview 3
  • Commits 2
  • Pipelines 0
  • Changes 1

Created by: Dj1b

As writeToFile doesn’t create a temp file on empty document, resulting in an error, we assure to have at least one cell written for writeToStdOut and writeToString methods.

Compare
  • master (base)

and
  • latest version
    06f2df44
    2 commits, 2 years ago

1 file
+ 22
- 3

    Preferences

    File browser
    Compare changes
xlsxwriter.class.php
+ 22
- 3
  • View file @ 06f2df44


@@ -66,20 +66,24 @@ class XLSXWriter
public function writeToStdOut()
{
$temp_file = $this->tempFilename();
self::writeToFile($temp_file);
self::writeToFile($temp_file, true);
readfile($temp_file);
}
public function writeToString()
{
$temp_file = $this->tempFilename();
self::writeToFile($temp_file);
self::writeToFile($temp_file, true);
$string = file_get_contents($temp_file);
return $string;
}
public function writeToFile($filename)
public function writeToFile($filename, $forceCreateFile=false)
{
// Create an empty sheet on forceCreateFile
if (empty($this->sheets) and $forceCreateFile)
$this->writeSheetRow('Sheet1', array(''));
foreach($this->sheets as $sheet_name => $sheet) {
self::finalizeSheet($sheet_name);//making sure all footers have been written
}
@@ -116,6 +120,21 @@ class XLSXWriter
$zip->close();
}
public function writeToStdOutAsAttachment($filename)
{
if (!preg_match('/\.xlsx$/', $filename))
$filename .= '.xlsx';
$content = $this->writeToString();
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.strlen($content));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
echo $content;
die();
}
protected function initializeSheet($sheet_name, $col_widths=array(), $auto_filter=false, $freeze_rows=false, $freeze_columns=false )
{
//if already initialized
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
0
0 participants
Reference:
Source branch: github/fork/Dj1b/master

Menu

Explore Projects Groups Snippets