I'm trying to open an excel sheet and insert few records into it. But, it's not working.
Here is my code
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
//we load the file that we want to read
$objPHPExcel = PHPExcel_IOFactory::load("/home/bigc/Desktop/test.xlsx");
$objPHPExcel->setActiveSheetIndex(0);
// Change the file
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B1', 'World!');
// Write the file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
error_reporting(E_ALL);
ini_set('display_errors', 1);
$objWriter->save("/home/bigc/Documents/test.xlsx");
//we save
$objWriter->save();
The error which it throws is
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Could not close zip file /home/bigc/Documents/test.xlsx.' in /home/bigc/Development/Development/Classes/PHPExcel/Writer/Excel2007.php:399 Stack trace: #0 /home/bigc/Development/Development/Upload.php(39): PHPExcel_Writer_Excel2007->save('/home/bigc/Docu...') #1 {main} thrown in /home/bigc/Development/Development/Classes/PHPExcel/Writer/Excel2007.php on line 399
I've already set read & write permissions. Any help would be greatly appreciated.
But that is the issue, you are trying to write over the top of the file on your desk top. It is not an issue with your code or phpexcel. It is about permissions. Try saving the file to a different location, then to the same location but with a different name. Is the current file read only by chance. Keep chasing the permission issue.
Related
I'm a newbie to code and pretty well illiterate. I have inserted some code into my customized header file only to realize it was the wrong place.
I since received this error message when i try to get onto my website
Parse error: syntax error, unexpected '$', expecting variable (T_VARIABLE) in /home2/seth1/public_html/wp-content/themes/TESSERACT/inc/custom-header.php on line 151
After seeing this i downloaded filezilla and removed the code I had previously inserted. This code wasn't on or near line 151 where the error was.
The website is sethslawnandgarden
and here is a link to my code pastebin.com/s7ePRE6Q
This error says than your js code incude before jquery library.
try add parameter array('jquery') in
wp_enqueue_script( 'theme-js', get_template_directory_uri() . '/js/main.js', array('jquery') ); or in file (or in tags) transfer all code to
jQuery.noConflict();
(function( $ ) {
//your code
})(jQuery);
You should take your backup and simply replace your ../TESSERACT/inc/custom-header.php file with the original or backup one.
I have a ZIP File to be served via Symfony. The controller looks like this:
$headers = [
'Content-Type' => 'application/zip',
'Content-Disposition' => 'attachment; filename="archive.zip"'
];
return new Response(file_get_contents($pathToFile), 201, $headers);
And this one works well. However, if I try to use BinaryFileResponse (as the Documentation recommends), the ZIP File gets corrupted:
$response = new BinaryFileResponse($pathToFile);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
$response->setStatusCode(Response::HTTP_CREATED);
return $response;
The output I get when trying to fix the file with zip -FF archive.zip --out fixed.zip :
zip warning: End record (EOCDR) only 17 bytes - assume truncated
(this command fixes the archive correctly)
Is it a bug or am I doing something wrong?
My setup:
Symfony 2.8.11
PHP 7.0.8
Ubuntu 16.04
nginx 1.10.0
EDIT:
I have made proposed changes, but the problem still exists:
$response = new BinaryFileResponse($pathToFile);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'archive.zip');
$response->headers->set('Content-Type', 'application/zip');
clearstatcache(false, $pathToFile);
return $response;
EDIT2:
I found one more interesting thing: serving this ZIP file with standard Response (the working code) creates openable file, however running zip -T on it gives:
1 extra byte at beginning or within zipfile
Testing original file gives:
OK
The size of file is less than 1MB.
SOLUTION:
When I opened generated ZIP file in text editor, I found an extra empty line at the beggining of it...
So I've added ob_clean(); before returning Response object and now it works!
No idea where this newline character came from, though...
Since I see you are returning 201 http header I assume file has been created with same request. As per symfony documentation:
If you just created the file during this same request, the file may be sent without any content. This may be due to cached file stats that return zero for the size of the file. To fix this issue, call clearstatcache(false, $file) with the path to the binary file.
I'm trying to create a application for load and read a large excel file (more than 60,000 rows) using PHPExcel library. I am getting internal server. It works fine upto 600 rows. But its not working for large files. Please help.
Or any other php library available to load large files.
set_time_limit(36000);
ini_set('max_execution_time', 36000);
##$top_records is a boolean set to get just the header and the first data row (( For field Mapping))
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
set_include_path(get_include_path() . PATH_SEPARATOR . SITE_PATH . '/core/extLib/Excel/Classes/');
require_once (SITE_PATH . '/core/extLib/Excel/Classes/PHPExcel.php');
include (SITE_PATH . '/core/extLib/Excel/Classes/PHPExcel/IOFactory.php');
PHPExcel_Cell::setValueBinder1( new PHPExcel_Cell_AdvancedValueBinder() );
$inputFileName = $file;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
Thanks
I have same your problem. The problem occur when work on this line
$objPHPExcel = $objReader->load($inputFileName);
Unfortunately PHPExcel is not meant to handle very large files. Changing the memory limit or time limit is at best a temporary fix but you will have the same problem with bigger files.
I can suggest you taking a look at Spout instead. It works great for your use case!
Increase memory limit. (eg: ini_set('memory_limit', '512') ),
Or use chunk instead. link
We want to modify the node of an xml file such as web.config and we get messy code after saving the file. The code we use is below:
set xmlDocument = CoCreateObject("Msxml2.DOMDocument.4.0");
if (!IsObject(xmlDocument)) then
return -1;
endif;
xmlDocument.async=FALSE;
xmlDocument.setProperty("SelectionLanguage","XPath");
xmlDocument.load(xmlFileName);
if(IsObject(xmlDocument)=FALSE) then
return -1;
endif;
set xmlNode = xmlDocument.selectSingleNode(nodePath);
if(IsObject(xmlNode)=TRUE) then
xmlNode.Attributes.getNamedItem("value").nodeValue = value;
xmlDocument.save(xmlFileName);
I tried to use many ways to resolve this problem, such as BOM or Encoding in xml file head.
But I haven't found the right way.
Now I would like to know two things:
the modifed file encoding.
modify the file with its encoding.
who can help me?
I have a bunch of SQL in a file, which creates the tables and so forth. The problem is that the .read command simply returns "can't open xxx" when I try to execute it. I've set the permissions to everybody read/write, but that didn't help. I can cat the file from the command line and see it fine.
This is under Mac OS 10.6.3.
Anybody have any idea here? Thanks!
Here's the source code in shell.c, where the sqlite3 utility executes the .read and tries to read the .sql file:
if( c=='r' && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
FILE *alt = fopen(azArg[1], "rb");
if( alt==0 ){
fprintf(stderr,"can't open \"%s\"\n", azArg[1]);
}else{
process_input(p, alt);
fclose(alt);
}
}else
You can see that the utility will print "can't open xxx" only when the call to fopen fails. Pity they don't print errno for you, but this info should really help you narrow down the problem as not specific to sqlite.
You're either specifying the path wrong (try quoting it), you don't have permission, or the file really doesn't exist (meaning that there's something different in how you're using cat and .read, like the current directory is different).
Watch out for the ; at the end. .read does not like ;'s.