unable to load file from url phpoffice/spreadsheet - phpoffice

Trying to load an .xlsx file from url but it gives error like,
Fatal error: Uncaught InvalidArgumentException: File
"http://localhost/test/csvfile/samplesms.xlsx" does not exist. in
D:\wamp\www\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Shared\File.php on line 137
Loading file with below,
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load($filename);
File is already at given location.

you can load file content using php_get_content or curl and save it temporary locally then load local version of the file
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$file = file_get_contents($filename);
$inputFileName = 'tempfile.xlsx';
file_put_contents($inputFileName, $file);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

loading from URL is not supported in phpoffice/spreadsheet.

Related

How to download a .zip file located on Google Drive?

I am trying to download a .shp file that is inside a .zip file. This .zip file is on https://drive.google.com/drive/u/2/folders/1u5oO0h9YKL1Nfi_pLGJgcEGGvUBJnE7D. I tried:
url = "https://drive.google.com/drive/u/2/folders/1u5oO0h9YKL1Nfi_pLGJgcEGGvUBJnE7D"
dir = tempdir()
temp = tempfile(fileext = ".zip", tmpdir = dir)
googledrive::drive_download(url, path = temp, overwrite = T)
And I got this error:
Error in `cli::cli_abort()`:
! Cannot export Google file of type:
* application/vnd.google-apps.folder
as a file of type:
* application/zip
How do I download it?

ZipArchive::close(): Renaming temporary file failed: Invalid argument Phpexcel Laravel

I am working on append excel content into existing excel file and save it in a predefined directory with different name. I am using the Laravel 5.4 framework for my application.
I am using the below code to create excel file and save it on specified location:
$objPHPExcel = \PHPExcel_IOFactory::createReader('Excel2007');
//Load Existing excel file into I want to append
$objPHPExcel = $objPHPExcel->load(getDocumentPath().'/Report_Template_UG.xlsx');
$objPHPExcel->setActiveSheetIndex(0);
//Here I have Written code to insert my data into loaded excel file
$today = date('d-m-Y');
$time = date('H:i:s');
$filename = 'Report_'.$today.' '.$time.'.xlsx';
//welcomed is the root directory name of laravel project
$dir = 'C:\xampp\htdocs\welcomed\storage\documents\';
$filepath = $dir . $filename;
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($path);
On executing the above code, I am gettign the below error:
ErrorException in Excel2007.php line 377:
ZipArchive::close(): Renaming temporary file failed: Invalid argument
Can anyone please tell me, What I have done wrong in above code or do I have missed something?
Thanks

Wordpress : Genesis-Legacy Theme error

I am getting this error message on some of my pages within worrdpress dashboard.
Google Analytics Stats
Warning: array_merge(): Argument #1 is not an array in
/home/c5280den/public_html/wp-content/plugins/google-analyticator/google-api-php-client/src/Google_Client.php
on line 40
Fatal error: Class name must be a valid object or a string in
/home/c5280den/public_html/wp-content/plugins/google-analyticator/google-api-php-client/src/Google_Client.php
on line 104
Any help is most appreciated!!
Update your plugin bro.. If updated already, try this.
FILE - google-analyticator > google-api-php-client > src > Google_Client.php
OLD CODE (starting at Line 35)
require_once "config.php";
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
$defaultConfig = $apiConfig;
require_once (dirname(__FILE__) . '/local_config.php');
$apiConfig = array_merge($defaultConfig, $apiConfig);
NEW CODE (starting at Line 35)
require_once (dirname(__FILE__) . "/config.php");
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
$defaultConfig = $apiConfig;
require_once (dirname(__FILE__) . '/local_config.php');
$apiConfig = array_merge($defaultConfig, $apiConfig);
Adding to line 35...
require_once (dirname(__FILE__) . "/config.php");
in place of...
require_once "config.php";
seems to have fixed the problem.
Get it from here https://wordpress.org/support/topic/recent-update-throws-error-in-settings-page

Symfony2 :500 Internal error on assetic generated file in dev mode

I use assetic on my Symfony2 project and when i put my project on a new server environement i have the following 500 internal Server Error on the top of the CSS and JS generated files on dev environement. It seems that assetic can't access to the temp directory to generate the file.
[exception] 500 | Internal Server Error | ErrorException
[message] Warning: file_put_contents(): Filename cannot be empty in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
[1] ErrorException: Warning: file_put_contents(): Filename cannot be empty in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
at n/a
in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
at Symfony\Component\HttpKernel\Debug\ErrorHandler->handle('2', 'file_put_contents(): Filename cannot be empty', '/Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php', '92', array('content' => '/*!
The line 92 of the BaseCompressorFilter class is the last line of this code :
$tempDir = realpath(sys_get_temp_dir());
$input = tempnam($tempDir, 'YUI-IN-');
$output = tempnam($tempDir, 'YUI-OUT-');
file_put_contents($input, $content);
$tempDir is ok, but $input is empty.
Any idea ?

How to call a python or shell script from within Extendscript?

I have a python script that needs to be called from within an Extendscript script. Is there any library function available which can do this? I tried finding a solution in the documentation and many other online resources but nothing has worked for me so far. Any help is appreciated.
ExtendScript File objects have an execute() method, as already shown by Fabian.
I did not know about .term files and would have used a .command file instead, that's a plain shell script rather than XML.
If running within InDesign, you can bypass Terminal.app and use AppleScript:
myScript = 'do shell script "diff f1 f2 > o" ';
app.doScript(myScript, ScriptLanguage.applescriptLanguage);
Take a look at this example.
It creates a .term file next to the script file and executes it.
This is a cleaned version:
main();
function main() {
var script_file = File($.fileName); // get the full path of the script
var script_folder = script_file.path; // get the path from that
var new_termfile = createTermFile("execute_something", script_folder);
new_termfile.execute(); // now execute the termfile
}
/**
* creates a .term file
* #param {String} term_file_name --> the name for the .term file
* #param {Strin} path --> the path to the script file
* #return {File} the created termfile
*/
function createTermFile(term_file_name, path) {
/*
http://docstore.mik.ua/orelly/unix3/mac/ch01_03.htm
1.3.1.1. .term files
You can launch a customized Terminal window from the command line by saving some prototypical Terminal settings to a .term file,
then using the open command to launch the .term file (see "open" in Section 1.5.4, later in this chapter).
You should save the .term file someplace where you can find it later, such as ~/bin or ~/Documents.
If you save it in ~/Library/Application Support/Terminal, the .term file will show up in Terminal's File Library menu.
To create a .term file, open a new Terminal window, and then open the Inspector (File Show Info, or -I)
and set the desired attributes, such as window size, fonts, and colors. When the Terminal's attributes
have been set, save the Terminal session (File Save, or -S) to a .term file (for example, ~/Documents/proto.term).
Now, any time you want to launch a Terminal window from the command line, you can issue the following command:
*/
var termfile = new File(path + "/" + term_file_name + ".term");
termfile.open("w");
termfile.writeln(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" +
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
"<plist version=\"1.0\">\n" +
"<dict>\n" +
"<key>WindowSettings</key>\n" +
"<array>\n" +
" <dict>\n" +
"<key>CustomTitle</key>\n" +
"<string>My first termfile</string>\n" +
"<key>ExecutionString</key>\n" +
"<string>python\nprint \"Hello World\"\nexit()</string>\n" +
"</dict>\n" +
"</array>\n" +
"</dict>\n" +
"</plist>\n");
termfile.close();
return termfile;
};

Resources