MarkBaker

MarkBaker

Member Since 10 years ago

MessageBird BV, Amsterdam

1 organizations

PHPOffice

Experience Points
347
follower
Lessons Completed
0
follow
Lessons Completed
17
stars
Best Reply Awards
40
repos

629 contributions in the last year

MarkBaker Most Used Languages
MarkBaker GitHub Stats

40 Pinned

⚡ PHP Class for handling Complex numbers
⚡ PHP Class for handling Matrices
⚡ PHPGeodetic is a library written in PHP, providing a set of classes for the handling of Geodetic Latitude/Longitude, ECEF and UTM coordinates, and conversions between datums
⚡ Trie and RadixTrie Datastructure Implementations in PHP, with a couple of working examples showing their use
⚡ PHP Implementation of QuadTree datastructure
⚡ QuadTree classes with the search() method implemented as a PHP 5.5 Generator
Jun
23
7 hours ago
pull request

MarkBaker merge to PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Check for existance of cellCollection before we try to use it

Will update these as I go along after we confirm the fix is good in our internal projects.

This is:

- [X ] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

What problem is this trying to solve? What error does it fix? How can we replicate that error?

If a worksheet exists, then a cell collection should also exist, because it's defined in the sheet's constructor, so it would be better to determine if the worksheet exists.

We need unit tests to prove that this works if it is a fix for some problem

pull request

MarkBaker merge to PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Check for existance of cellCollection before we try to use it

Will update these as I go along after we confirm the fix is good in our internal projects.

This is:

- [X ] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

What problem is this trying to solve? What error does it fix? How can we replicate that error?

If a worksheet exists, then a cell collection should also exist, because it's defined in the sheet's constructor.

We need unit tests to prove that this works if it is a fix for some problem

pull request

MarkBaker merge to PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Check for existance of cellCollection before we try to use it

Will update these as I go along after we confirm the fix is good in our internal projects.

This is:

- [X ] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

What problem is this trying to solve? What error does it fix?

If a worksheet exists, then a cell collection should also exist, because it's defined in the sheet's constructor.

We need unit tests to prove that this works if it is a fix for some problem

Jun
21
2 days ago
Activity icon
issue

MarkBaker issue comment MarkBaker/PHPComplex

MarkBaker
MarkBaker

Why autoload.files in composer.json

Hello,

I'd just like to ask what is the reason behind having all the files with functions and operations in autoload.files section of composer.json. I'm curious because, as per Composer docs, this way autoloading effectively runs all specified files for every request because lazy-loading cannot work, which obviously consumes precious resources.

Have you thought about having the functions encapsulated in classes instead, so lazy-loading could be used?

Thank you

MarkBaker
MarkBaker

You're quite at liberty to fork the library and remove all those functions there. That's your prerogative.

I made a design decision early on; you disagree with that; but with opcaching, there will be negligible performance overhead after the initial load. Even without opcaching, the performance overhead is minimal, and I have yet to see any evidence to tell me otherwise.

Activity icon
delete

MarkBaker in PHPOffice/PhpSpreadsheet delete branch PHP81-Changes-to-Defaults-Requires-Explicit-Arguments

deleted time in 1 day ago
push

MarkBaker push PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Changes to the default arguments for htmlspecialchars() and html_entity_decode() requires setting of the argument value explicitly to prevent changes in behaviour. (#2176)

Specifically, the default for these two functions has been changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE

This PR configures the argument used for those functions in Settings, and then explicitly applies it everywhere they are used in the codebase.

commit sha: 5769885802b8b4394a880398c8fb1a7d919e8da6

push time in 1 day ago
pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Changes to the default arguments for `htmlspecialchars()` and `html_entity_decode()` for PHP8.1

This is:

- [ ] a bugfix
- [ ] a new feature
- [X] PHP version change

Checklist:

Why this change is needed?

Changes to the default arguments for htmlspecialchars() and html_entity_decode() for PHP8.1 requires setting of the argument value explicitly to prevent changes in behaviour.

Specifically, the default for these two functions has been changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE

This PR configures the argument used for those functions in Settings, and then explicitly applies it everywhere they are used in the codebase.

pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Changes to the default arguments for `htmlspecialchars()` and `html_entity_decode()` for PHP8.1

This is:

- [ ] a bugfix
- [ ] a new feature
- [X] PHP version change

Checklist:

Why this change is needed?

Changes to the default arguments for htmlspecialchars() and html_entity_decode() for PHP8.1 requires setting of the argument value explicitly to prevent changes in behaviour.

Specifically, the default for these two functions has been changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE

This PR configures the argument used for those functions in Settings, and then explicitly applies it everywhere they are used in the codebase.

Activity icon
created branch

MarkBaker in PHPOffice/PhpSpreadsheet create branch PHP81-Changes-to-Defaults-Requires-Explicit-Arguments

createdAt 1 day ago
Jun
19
4 days ago
Activity icon
issue

MarkBaker issue PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

setWrapText

This is:

- [ ] a bug report
- [ ] a feature request

setWrapText is not working on merge cell

$sheet->setCellValue('A1', 'This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample 123456');

$spreadsheet->getActiveSheet()->mergeCells('A1:C1''); $spreadsheet->getActiveSheet()->getStyle('A1:C1')->getAlignment()->setWrapText(true);

Activity icon
issue

MarkBaker issue comment PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

setWrapText

This is:

- [ ] a bug report
- [ ] a feature request

setWrapText is not working on merge cell

$sheet->setCellValue('A1', 'This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample This is just a sample 123456');

$spreadsheet->getActiveSheet()->mergeCells('A1:C1''); $spreadsheet->getActiveSheet()->getStyle('A1:C1')->getAlignment()->setWrapText(true);

MarkBaker
MarkBaker

I've just tested this, and it works for Xls, Xls, Ods and Html Writers... what wrapText doesn't do is change the row height, you have to do that yourself

Activity icon
issue

MarkBaker issue comment PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Phpspreadsheet Charts don't work when adding multiple sheets - demo code works fine one worksheet, blank for 2+

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Creating charts with multiple worksheets should not be different from creating charts with just one worksheet

What is the current behavior?

I can create one or 2 charts happily so long as I stick to the first worksheet, but as soon as I add multiple worksheets the charts written are corrupted or just blank.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

If you run the code below with $stickToOneSheet set to true, the code runs fine.

There are several options for adding a worksheet and 2 (different?) $writers and none of them produce working charts if there is more than one worksheet.

<?php

require __DIR__ . '/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;



$stickToOneSheet = true;
$useNewWriterFactory = false;
$cloneNewWorksheet = true; // Only relevant if multiple sheets
$multipleCharts = true;
$title = 'newworksheet';

$spreadsheet = new Spreadsheet();

if ($stickToOneSheet) {
    $worksheet = $spreadsheet->getActiveSheet();

} elseif ($cloneNewWorksheet) {
    $worksheet1 = $spreadsheet->getActiveSheet();
    $worksheet = clone $worksheet1;
    $worksheet->setTitle($title);
    $spreadsheet->addSheet($worksheet,1);
} elseif ($useNewWriterFactory) {

    $worksheet = new Worksheet($spreadsheet, $title);
    $spreadsheet->addSheet($worksheet,1);
} else {
    echo "Sorry, no idea what you want to test";
    die;
}


// Todo generate data in this format
$data = [  // Note this data need to be transposed
    ['Tutor Dashboard Report for someone@example.com'],
    [''],
    ['','Course Minutes','Quiz Minutes','Book Minutes','Other Minutes','Panopto Minutes','Total Minutes', 'Graded Activities', '# Vidoes Watched', '# Watched Completely', 'Quartile Rank'],
    ['Sep20',22,23,65,60,37,256,2,3,2,1],
    ['Oct20',18,39,47,68,38,256,2,3,2,1],
    ['Nov20',12,15,43,67,38,256,4,3,2,3],
    ['Dec20',4,1,154,0,21,256,2,3,2,1],
    ['Jan21',22,15,38,18,10,256,4,4,2,4],
    ['Feb21',18,39,47,68,38,256,2,3,2,1],
    ['Mar21',12,15,43,67,38,256,2,5,2,1],
    ['Apr21',4,1,154,14,21,256,2,1,1,1],
    ['May21',18,39,47,68,38,256,2,3,2,2],
];


$worksheet->fromArray($data);


$num_columns = count($data[2]);
$num_rows = count($data)-3;
echo "\n\nColumns: $num_columns, Rows: $num_rows\n\n";

// Set the Labels for each data series we want to plot
//     Datatype
//     Cell reference for data
//     Format Code
//     Number of datapoints in series
//     Data values
//     Data Marker
//Todo set start values to calculations
$dataSeriesLabels = [
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$3', null, 1), // Course
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$3', null, 1), // Quiz
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$3', null, 1), // Books
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$E$3', null, 1), // Other
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$F$3', null, 1), // Panopto
];
// Set the X-Axis Labels
//     Datatype
//     Cell reference for data
//     Format Code
//     Number of datapoints in series
//     Data values
//     Data Marker
$xAxisTickValues = [
    //Todo set values to calculations
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$4:$A$12', null, 4), // Q1 to Q4
];
// Set the Data values for each data series we want to plot
//     Datatype
//     Cell reference for data
//     Format Code
//     Number of datapoints in series
//     Data values
//     Data Marker
//Todo set start and end values to calculations
$dataSeriesValues = [
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$4:$B$12', null, 4),
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$4:$C$12', null, 4),
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$4:$D$12', null, 4),
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$E$4:$E$12', null, 4),
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$F$4:$F$12', null, 4),
];

// Build the dataseries
$series = new DataSeries(
    DataSeries::TYPE_BARCHART, // plotType
    DataSeries::GROUPING_STACKED, // plotGrouping
    range(0, count($dataSeriesValues) - 1), // plotOrder
    $dataSeriesLabels, // plotLabel
    $xAxisTickValues, // plotCategory
    $dataSeriesValues        // plotValues
);
// Set additional dataseries parameters
//     Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(DataSeries::DIRECTION_COL);

// Set the series in the plot area
$plotArea = new PlotArea(null, [$series]);
// Set the chart legend
$legend = new Legend(Legend::POSITION_RIGHT, null, false);

$title = new Title('Tutor Dashboard - brmerritt@rvc.ac.uk'); // Todo add student email
$yAxisLabel = new Title('Learning Minutes');

// Create the chart
$chart = new Chart(
    'chart1', // name
    $title, // title
    $legend, // legend
    $plotArea, // plotArea
    true, // plotVisibleOnly
    DataSeries::EMPTY_AS_GAP, // displayBlanksAs
    null, // xAxisLabel
    $yAxisLabel  // yAxisLabel
);

// Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('A'.($num_rows + 7));
$chart->setBottomRightPosition('M'.($num_rows + 22));

// Add the chart to the worksheet
$worksheet->addChart($chart);

if ($multipleCharts) {


    // OK, try adding another chart!
    $dataSeriesLabels2 = [
        //new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$G$3', null, 1), // Total Minutes - ignore!
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$H$3', null, 1), // Graded Activities
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$I$3', null, 1), // Videos Watched
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$J$3', null, 1), // Watched Completely
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$K$3', null, 1), // Quartile Ranking
    ];
    $xAxisTickValues2 = [
        //Todo set values to calculations
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$4:$A$12', null, 4), // Q1 to Q4
    ];

    //Todo set start and end values to calculations
    $dataSeriesValues2 = [
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$H$4:$H$12', null, 4),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$I$4:$I$12', null, 4),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$J$4:$J$12', null, 4),
        new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$K$4:$K$12', null, 4),
        //new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$F$4:$F$12', null, 4),
    ];

    // Build the dataseries
    $series2 = new DataSeries(
        DataSeries::TYPE_BARCHART, // plotType
        DataSeries::GROUPING_CLUSTERED, // plotGrouping
        range(0, count($dataSeriesValues2) - 1), // plotOrder
        $dataSeriesLabels2, // plotLabel
        $xAxisTickValues2, // plotCategory
        $dataSeriesValues2        // plotValues
    );
    // Set additional dataseries parameters
    //     Make it a vertical column rather than a horizontal bar graph
    $series2->setPlotDirection(DataSeries::DIRECTION_COL);

    // Set the series in the plot area
    $plotArea2 = new PlotArea(null, [$series2]);
    // Set the chart legend
    $legend2 = new Legend(Legend::POSITION_RIGHT, null, false);

    $title2 = new Title('Graded Activities, Videos Watched, and Quartile Ranking'); // Todo add student email
    $yAxisLabel2 = new Title('Number of Each');


    $chart2 = new Chart(
        'chart2', // name
        $title2, // title
        $legend2, // legend
        $plotArea2, // plotArea
        true, // plotVisibleOnly
        DataSeries::EMPTY_AS_GAP, // displayBlanksAs
        null, // xAxisLabel
        $yAxisLabel2  // yAxisLabel
    );
    // Set the position where the chart should appear in the worksheet
    $chart2->setTopLeftPosition('A' . ($num_rows + 29));
    $chart2->setBottomRightPosition('M' . ($num_rows + 44));

    // Add the chart to the worksheet
    $worksheet->addChart($chart2);
}

// Save Excel file

$filename = "test_col1_stacked_7.xlsx";
if ($useNewWriterFactory) {
    $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
} else {
    $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
}

$writer->setIncludeCharts(true);
$callStartTime = microtime(true);
$writer->save($filename);
return 0;

// add code that show the issue here...

$stickToOneSheet = false; // Change the code above and the charts will not have visible data or be corrupted.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.4.12 Phpspreadsheet versions 1.16 and 1.18 Excel version 2105 build 14026...

MarkBaker
MarkBaker

I'm glad that you were able to figure it out.

I'd set aside this weekend to give myself time to look at your problem, because it would likely take a lot of investigation time... one of these days, I'll look at creating a wizard/helper to make it easier to define charts, because the classes are currently just a mapping of the underlying XML structures to PHP classes.

push

MarkBaker push PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Locale Generator - Change to Use Unix Line Endings Even on Windows (#2174)

See issue #2172. The locale files are regenerated whenever the test suite is run.

The use of PHP_EOL in LocaleGenerator.php is awkward on Windows systems, since it causes git to think the file has changed. Change to use "\n" instead.

commit sha: d200c5363f53ad28d6d3cddfa9d08559c2f6ec1c

push time in 3 days ago
pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Locale Generator - Change to Use Unix Line Endings Even on Windows

See issue #2172. The locale files are regenerated whenever the test suite is run.

The use of PHP_EOL in LocaleGenerator.php is awkward on Windows systems, since it causes git to think the file has changed. Change to use "\n" instead.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

Activity icon
issue

MarkBaker issue comment PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Xlsx Reader Better Namespace Handling Phase 1 Try2

This is a replacement for #2088, which has run into merge conflicts. I will close that PR in the near future, however the comments in that PR may prove useful for this one. While that PR has been in draft status all along, I am marking this one as ready. I will gladly add additional tests (and, of course, make code changes) that anyone has to suggest, but, with my most recent test files which I will describe in a separate comment, I have no further ideas on useful additions.

As mentioned in the earlier ticket, this is a risky change. But, as has been demonstrated, delaying it comes with its own set of risks. It would be helpful to have a temporary moratorium on changes to Reader/Xlsx until this change is merged.

The original commit message follows.

There have been a number of issues concerning the handling of legitimate but unexpected namespace prefixes in Xlsx spreadsheets created by software other than Excel and PhpSpreadsheet/PhpExcel.I have studied them, but, till now, have not had a good idea on how to act on them. A recent comment https://github.com/PHPOffice/PhpSpreadsheet/issues/860#issuecomment-824926224 in issue #860 by @IMSoP has triggered an idea about how to proceed.

Gnumeric Reader was recently changed to handle namespaces better. Using that as a model, this PR begins the process of doing the same for Xlsx. Xlsx is much larger and more complicated than Gnumeric, hence the need to tackle it in multiple phases. I believe that this PR handles all of:

  • listWorkSheetNames
  • listWorkSheetInfo. Note that there was a bug in this function which would cause it to count only used columns rather than all columns. That bug is corrected.
  • active sheet
  • selected cell and top left cell
  • cell content (formulas, numbers, text)
  • hyperlinks
  • comments (partial - see below)

This PR does not address:

  • styles
  • images and charts
  • VBA and ribbons
  • many other items, I'm sure

The issue for non-standard namespacing till now has been the use of unexpected prefixes. While I was working on this change, @Lambik introduced issue #2067 PR #2068 which introduced a completely different problem - the use of unexpected URLs. That PR and the issue associated with it were quite well documented, including the supplying of a test file and tests for it. I asked if I could take a look to see if it could be integrated with my change, and the result seems to be yes, so those changes are also part of this PR.

While adding a comment to my test file, I discovered that Microsoft had added "threaded comments" as a new feature. I believe these are not yet supported by PhpSpreadsheet, and I am not going to add it, at least not now. I believe that, among other things, this will make identifying the author of a comment more difficult.

Although there are a number of Phpstan baseline changes as part of this PR, I did not attempt to resolve all Phpstan reports for Reader/Xlsx. Nor did I do anything to increase coverage. This change is already large and complex enough without those efforts.

I will add more detail as comments after I push this change.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

Let me know when you're happy with it: it might be one of the riskiest changes we've ever made to the codebase, but it's long overdue, and you've done great work in introducing it. I know I do some refactoring work to benefit the Pivot Table reading; but I've more than enough other things I want to look at (Array functions, the new spilled range and implicit intersection operators, empty operands in IF() with lazy evaluation, LET() and LAMBDA(), some TLC for charts, etc) that will keep me occupied and away from the Xlsx Reader until then.

Activity icon
issue

MarkBaker issue comment PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Locale Files are Generated with Windows Line-endings

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Files should have Unix line endings.

What is the current behavior?

They have Windows line endings. This causes git to think they have all been changed; at least that's what it thinks on my Windows machine (which I have configured to use Unix line endings). It would be easy enough to change them all, but, since they appear to be generated, I'm not sure any such change would stick.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

Which versions of PhpSpreadsheet and PHP are affected?

This seems to have been caused by #2111.

MarkBaker
MarkBaker

I'm glad you figured it out.... I test locally against different PHP versions on Windows while I'm working, but I always run the tests on a Linux VM before my commit

Jun
17
6 days ago
Jun
16
1 week ago
Activity icon
created branch

MarkBaker in PHPOffice/PhpSpreadsheet create branch Column-Autosize-only-if-cell-value-requires-it

createdAt 6 days ago
Activity icon
issue

MarkBaker issue comment PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Writing to a Template xlsx file with a Pivot Table

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Load existing template with a pivot table on the first worksheet, input raw data on the second sheet, and have the pivot table update with the new data.

What is the current behavior?

Data is being inputted on the second sheet but the pivot table on the first sheet is not longer a pivot table, and is now text.

What are the steps to reproduce?

  1. create excel (xlsx) template with pivot table on first page generated from raw data on second.
  2. delete the raw data and refresh the pivot table
  3. load new data into the raw data worksheet with PhpSpreadsheet
  4. download and view xlsx file

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server: This is very simplified version of the code I'm trying to run. I cannot provide the issue without providing an external excel file, so I'm trusting that you can do that on your own.

<?php
//receive payload as a json post parameter
$payload = isset($_POST['PAYLOAD']) ? json_decode($_POST['PAYLOAD'], true) : null;

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

require_once __DIR__ . './vendor/phpoffice/phpspreadsheet/src/Bootstrap.php';

// Create new Spreadsheet object
$spreadsheet = IOFactory::load('./templates/PivotTemplate.xlsx');

$spreadsheet->getProperties()->setCreator('Ori Nachassi')
        ->setTitle('Pivot Demo')
        ->setSubject('Office 2007 XLSX');


// ============================ START Raw Data SHEET =============================

$spreadsheet->setActiveSheetIndex(1);
$spreadsheet->getActiveSheet()->setTitle('Raw Data');

if ($payload != null) {
	$rowCount = '2';
	foreach ($payload as $row) {

               $spreadsheet->setActiveSheetIndex(1)
		  ->setCellValue('A'.$rowCount, utf8_encode($row[0]));
		
		$spreadsheet->setActiveSheetIndex(1)
		  ->setCellValue('B'.$rowCount, utf8_encode($row[1]));

                $spreadsheet->setActiveSheetIndex(1)
		  ->setCellValue('C'.$rowCount, utf8_encode($row[2]));

                $rowCount++;
	}		
} 	

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(1);
$filename = 'Pivot Table ('.date("d-m-y").').xlsx';
// Redirect output to a client’s web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;

?>

Which versions of PhpSpreadsheet and PHP are affected?

Php Version 7.1.8 PHPSpreadsheet Version 1.0.0

Thank you for this great tool, your help is greatly appreciated!

Activity icon
delete

MarkBaker in PHPOffice/PhpSpreadsheet delete branch Additional-Financial_Unit-Tests-with-positive-and-negative-interest-rates-and-values

deleted time in 6 days ago
push

MarkBaker push PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Additional unit tests for negative interest rates in the financial functions, and also tests using negative present/future value arguments (#2166)

commit sha: d2076fefabcb201619bbd326e9234eb9c3c696fa

push time in 6 days ago
pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Additional unit tests for negative interest rates in the financial fu…

…nctions, and also tests using negative present/future value arguments

This is:

- [ ] a bugfix
- [ ] a new feature
- [X] unit tests

Checklist:

Why this change is needed?

Additional unit tests to ensure that more of the financial functions can handle a negative interest rate argument, and also negative PV and FV arguments where appropriate

pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Additional unit tests for negative interest rates in the financial fu…

…nctions, and also tests using negative present/future value arguments

This is:

- [ ] a bugfix
- [ ] a new feature
- [X] unit tests

Checklist:

Why this change is needed?

Additional unit tests to ensure that more of the financial functions can handle a negative interest rate argument, and also negative PV and FV arguments where appropriate

Activity icon
created branch

MarkBaker in PHPOffice/PhpSpreadsheet create branch Additional-Financial_Unit-Tests-with-positive-and-negative-interest-rates-and-values

createdAt 6 days ago
Activity icon
delete

MarkBaker in PHPOffice/PhpSpreadsheet delete branch PPMT-Allow-negative-rate

deleted time in 6 days ago
open pull request

MarkBaker wants to merge PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Autofilter Part 2

Most of the remaining 32-bit-unsafe date handling that remains in PhpSpreadsheet is in AutoFilter. Cleaning this up demonstrated that there are a lot of problems with AutoFilter, and I will do it in two pieces. Part 1 was PR #2141 which I have just merged.

In this PR:

  • Fix remaining 32-bit dates in filterTestInDateGroupSet.
  • Also in some of the existing AutoFilter samples. Note that the comments in two of those said the filter was being set for the first day of each month, but the code specifies the last day - I have corrected the comments.
  • Remove mocking in unit tests for AutoFilter in favor of 'real' tests.
  • Code coverage is now 100% in all of AutoFilter, AutoFilter/Column, and AutoFilter/Common/Rule.
  • No remaining AutoFilter(/Column(/Rule)) exceptions in Phpstan baseline.
  • Documentation for escaping of asterisk, question mark, and tilde in text filters included spurious backslashes which are now removed.
  • Text filter escaping of question mark did not work. There had been no unit tests for any text filtering.
  • Likewise there had been no testing for TopTen.
  • Above- and below- average filters were not working because they acquired their Calculation instance incorrectly. There had been no tests.
  • Several unchanging private static arrays in Rule were changed to private const arrays.
  • Clones are now tested.
  • RuleTest is moved to same directory as other tests.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

Documentation for escaping of asterisk, question mark, and tilde in text filters included spurious backslashes which are now removed.

Note that there is now a helper class for handling this, the WildcardMatch class that's used by the Database functions. You can find examples of its use in the buildCondition() method of DatabaseAbstract or in the ExcelMatch class used for the Excel MATCH() function. It handles a lot more edge cases than this version: I'd forgotten that it was also needed for AutoFilter as well.

pull request

MarkBaker merge to PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Autofilter Part 2

Most of the remaining 32-bit-unsafe date handling that remains in PhpSpreadsheet is in AutoFilter. Cleaning this up demonstrated that there are a lot of problems with AutoFilter, and I will do it in two pieces. Part 1 was PR #2141 which I have just merged.

In this PR:

  • Fix remaining 32-bit dates in filterTestInDateGroupSet.
  • Also in some of the existing AutoFilter samples. Note that the comments in two of those said the filter was being set for the first day of each month, but the code specifies the last day - I have corrected the comments.
  • Remove mocking in unit tests for AutoFilter in favor of 'real' tests.
  • Code coverage is now 100% in all of AutoFilter, AutoFilter/Column, and AutoFilter/Common/Rule.
  • No remaining AutoFilter(/Column(/Rule)) exceptions in Phpstan baseline.
  • Documentation for escaping of asterisk, question mark, and tilde in text filters included spurious backslashes which are now removed.
  • Text filter escaping of question mark did not work. There had been no unit tests for any text filtering.
  • Likewise there had been no testing for TopTen.
  • Above- and below- average filters were not working because they acquired their Calculation instance incorrectly. There had been no tests.
  • Several unchanging private static arrays in Rule were changed to private const arrays.
  • Clones are now tested.
  • RuleTest is moved to same directory as other tests.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

Id recommend switching to use of the WildCard class for handling wildcards in text searches, because it handles a lot of edge cases that this original simplistic method didn't take into account

pull request

MarkBaker merge to PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Autofilter Part 2

Most of the remaining 32-bit-unsafe date handling that remains in PhpSpreadsheet is in AutoFilter. Cleaning this up demonstrated that there are a lot of problems with AutoFilter, and I will do it in two pieces. Part 1 was PR #2141 which I have just merged.

In this PR:

  • Fix remaining 32-bit dates in filterTestInDateGroupSet.
  • Also in some of the existing AutoFilter samples. Note that the comments in two of those said the filter was being set for the first day of each month, but the code specifies the last day - I have corrected the comments.
  • Remove mocking in unit tests for AutoFilter in favor of 'real' tests.
  • Code coverage is now 100% in all of AutoFilter, AutoFilter/Column, and AutoFilter/Common/Rule.
  • No remaining AutoFilter(/Column(/Rule)) exceptions in Phpstan baseline.
  • Documentation for escaping of asterisk, question mark, and tilde in text filters included spurious backslashes which are now removed.
  • Text filter escaping of question mark did not work. There had been no unit tests for any text filtering.
  • Likewise there had been no testing for TopTen.
  • Above- and below- average filters were not working because they acquired their Calculation instance incorrectly. There had been no tests.
  • Several unchanging private static arrays in Rule were changed to private const arrays.
  • Clones are now tested.
  • RuleTest is moved to same directory as other tests.

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

MarkBaker
MarkBaker

Id recommend switching to use of the WildCard class for handling wildcards in text searches, because it handles a lot of edge cases that this original simplistic method didn't take into account

Jun
15
1 week ago
push

MarkBaker push PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Allow negative interest rate in PPMT() Financial function (#2164)

commit sha: ebdeb231ebc6da619720a016e464b483967374d5

push time in 1 week ago
pull request

MarkBaker pull request PHPOffice/PhpSpreadsheet

MarkBaker
MarkBaker

Allow negative interest rate in PPMT() Financial function

This is:

- [X] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

Allow a negative interest rate in PPMT() function Issue #2163