Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
MassiPi
@MassiPi
well something like that can be sourced for example trying to access $array[use] instead of $array['use'].. why don't you paste that line of code?
odlarhg
@odlarhg

use PhpOffice\PhpSpreadsheet\Spreadsheet;

require DIR . '/../Header.php';

$spreadsheet = new Spreadsheet();
$helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet();

// Set document properties
$helper->log('Set document properties');
$spreadsheet->getProperties()
->setCreator('Maarten Balliauw')
->setLastModifiedBy('Maarten Balliauw')
->setTitle('PhpSpreadsheet Test Document')
->setSubject('PhpSpreadsheet Test Document')
->setDescription('Test document for PhpSpreadsheet, generated using PHP classes.')
->setKeywords('office PhpSpreadsheet php')
->setCategory('Test result file');

// Add some data
$helper->log('Add some data');
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');

$spreadsheet->getActiveSheet()
->setCellValue('A8', "Hello\nWorld");
$spreadsheet->getActiveSheet()
->getRowDimension(8)
->setRowHeight(-1);
$spreadsheet->getActiveSheet()
->getStyle('A8')
->getAlignment()
->setWrapText(true);

$value = "-ValueA\n-Value B\n-Value C";
$spreadsheet->getActiveSheet()
->setCellValue('A10', $value);
$spreadsheet->getActiveSheet()
->getRowDimension(10)
->setRowHeight(-1);
$spreadsheet->getActiveSheet()
->getStyle('A10')
->getAlignment()
->setWrapText(true);
$spreadsheet->getActiveSheet()
->getStyle('A10')
->setQuotePrefix(true);

// Rename worksheet
$helper->log('Rename worksheet');
$spreadsheet->getActiveSheet()
->setTitle('Simple');

// Save
$helper->write($spreadsheet, FILE);

The first line is the one that generates the error.
MassiPi
@MassiPi
what did you put before? wjere did you put that "use"? it can't be within a method
odlarhg
@odlarhg
There is nothing before. It is the first line of the file. Take the code of the example file and in Scriptcase I inserted it into an application that Scriptcase calls Blank.
_
MassiPi
@MassiPi
so noone ever tried to open a password protected excel file with phpspreadsheet?
odlarhg
@odlarhg
Hello,I have been able to solve the problem in order to create an xlsx file with phpspreadsheet inside a Scriptcase application. I do not know if it is the most correct solution, but at least it allows me to create the file. Now I have to customize my code to export the data I need, but I think I'm on the right track. I leave the code in case someone is useful.

$contenido="<?php
require ('../../../vendor/autoload.php');

use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;".'

require_once "../../../vendor/phpoffice/phpSpreadsheet/src/Bootstrap.php";

$helper = new Sample();
if ($helper->isCli()) {
$helper->log("This example should only be run from a Web Browser" . PHP_EOL);

return;

}
// Create new Spreadsheet object
$spreadsheet = new Spreadsheet();

// Set document properties
$spreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");

// Add some data
$spreadsheet->setActiveSheetIndex(0)
->setCellValue("A1", "Hello")
->setCellValue("B2", "world!")
->setCellValue("C1", "Hello")
->setCellValue("D2", "world!");

// Miscellaneous glyphs, UTF-8
$spreadsheet->setActiveSheetIndex(0)
->setCellValue("A4", "Miscellaneous glyphs")
->setCellValue("A5", "éàèùâêîôûëïüÿäöüç");

// Rename worksheet
$spreadsheet->getActiveSheet()->setTitle("Simple");

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Xlsx)
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");'.'
header("Content-Disposition: attachment; filename=' . "01simple.xlsx".'");
header("Cache-Control: max-age=0");
// If you are serving to IE 9, then the following may be needed
header("Cache-Control: max-age=1");

// If you are 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");

$spreadsheet->disconnectWorksheets();
unset($spreadsheet);?>';

$file = fopen("prueba2.php", "a");
fwrite($file, $contenido);
fclose($file);
header ("Location: prueba2.php");

odlarhg
@odlarhg
Por cierto gracias al comentario de José Renteira que me ayudó a encontrar una solución. https://plus.google.com/114583721646550413124/posts/DkCnhC65wJ2
By the way, thanks to José Renteira's comment that helped me find a solution . https://plus.google.com/114583721646550413124/posts/DkCnhC65wJ2
Adrien Crivelli
@PowerKiKi
MassiPi
@MassiPi
@PowerKiKi isn't it for SETTING security on newly created files? i'm trying to OPEN an excel file password protected..
Fräntz Miccoli
@frantzmiccoli
@MassiPi columns headers says whether or not you are looking at readers or writers
MassiPi
@MassiPi
oh god that was so clear lol :) i did not find any code example for a reader opening a password protected file, can you help me?
tputraa
@tputraa
Class 'CachedObjectStorageFactory' not found in phpspreadsheet, how m8?
Xenothan Hojem
@xenothanhojem
Hey Guys
Am looking to use PHPPresentation and PHPWord in my Laravel 5.6 app, any pointers?
Adrien Crivelli
@PowerKiKi
@tputraa it seems you migrated from PHPExcel and are looking for \PhpOffice\PhpSpreadsheet\Collection\CellsFactory
@xenothanhojem Try your luck in their Gitter rooms, not here
tputraa
@tputraa

@PowerKiKi this my code
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array('memoryCacheSize' => '8MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);

i dont understand correlation between cachedobjectstoragefactory and cellsfactory.
please help me

Adrien Crivelli
@PowerKiKi
@tputraa you are using PHPExcel, but this is a Gitter room for PhpSpreadsheet. You are in the wrong place, and more importantly you are using the wrong library, see: https://github.com/PHPOffice/PHPExcel#phpexcel---dead
tputraa
@tputraa
@PowerKiKi i mean i should change that method to phpspreadsheet style, but which one
i dont see correlation between cachedobjectstoragefactory and cellsfactory
Adrien Crivelli
@PowerKiKi
@tputraa see https://phpspreadsheet.readthedocs.io/en/latest/topics/migration-from-PHPExcel/, there is a section dedicated to caching
ahdavis
@ahdavis
I'm sorry if this has been asked before, but I didn't see it when I searched. Are there any plans to implement Excel's document password encryption feature where you have to enter a password to open the file? For my purposes, it doesn't have to be compatible with Excel's encryption algorithm. I just need to create a file and encrypt it with a password, so the user is prompted for the password to open the file. Thanks
Alan
@lovealan
How do I know which cells are merged?
Adrien Crivelli
@PowerKiKi
@ahdavis AFAIK, there's nobody actively working on encryption. But a contribution would certainly be appreciated !
@lovealan try \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::getMergeCells() and read https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#mergeunmerge-cells
Alan
@lovealan
Thx,I got it
Carlos A. Molano
@carlosmolano
so noone ever tried to open a password protected excel file with phpspreadsheet?..
Fräntz Miccoli
@frantzmiccoli
I just observed that the activity log on the right of the Gitter UI seems broken since a few months.
Adrien Crivelli
@PowerKiKi
@frantzmiccoli thanks for letting me know, it's been re-activated
Fräntz Miccoli
@frantzmiccoli
You are welcome
Santosh Patel
@newblend_no8_twitter
Hi, using Phpspreadsheet to read Excel files and consume the data/metadata (not excel anymore). Is there a way to suppress adding _xlfn. to functions that Phpspreadsheet does not recognize? Getting an issue with CONCAT.
William Minerva
@WilliamMinerva3_twitter
hello
Andriy Khyliuk
@Smartop
how get row by sheet index $sheet->getRowIterator() , for example i need get only second row in current sheet without foreach?
VertZu
@VertZu
What I want is - If I have date (A2:A5) for example 1.4.2019 and I want that day's expenses (B2:B5) in format of B2+B3+B4... and so on
And if they are paid with credit card (C2:C5), I want them in same format also C2+C4+C5.. they might not have been paid with card so that needs to be left out
I want business expenses + paid with card to same row where the is already put date when they were made to another Excel file without making a new excel, just updating existing one. Is this possible with phpspreadsheet?
Adrien Crivelli
@PowerKiKi
@Smartop try something similar to:
$row = new Row($sheet, 2);
Michel Ojeda
@kristofermagic
Hello Everyone

I'm just trying to use the PhpOffice/PhpSpreadsheet with ZF3. I installed by composer and when I used then : $inputFileType = 'Xls';

    $reader = IOFactory::createReader($inputFileType);

my application show the following error: Class 'PhpOffice\PhpSpreadsheet\IOFactory' not found

Michel Ojeda
@kristofermagic
etc, etc
Dan Eveland
@duckydan
@kristofermagic Hi, this might be super basic, but did you put in the “Use” lines to load the classes?
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
Michel Ojeda
@kristofermagic
yes, I did!
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
private function readExcelFile( $inputFileName )
{
$inputFileType = 'Xls';
    $reader = IOFactory::createReader($inputFileType);

    $reader->setReadDataOnly( true );
    $spreadsheet = $reader->load($inputFileName);

    $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
    return $sheetData;
}
Dan Eveland
@duckydan
@kristofermagic I just started working with this yesterday. Wish I could help.
Michel Ojeda
@kristofermagic
thanks a lot. Me too. I was developing some test from my local and it worked pretty good, but with ZF3, I could not.
Michel Ojeda
@kristofermagic
Somehow, the IDE perfectly recognizes the namespace and take me to the scripts definitions when I click it over without no problem. would it be something related to autoload.
Michel Ojeda
@kristofermagic
@PowerKiKi How can I use this in ZF3??