I am working on my web project using Codeigniter. I want to generate an excel file by setting the data in the file, for now that's cool.
but I have a problem is that the site uses Arabic as a primary language, and I would set the title and description in the properties of excel file.
when I open the excel file and I open the properties, it does not display the title and description in Arabic, but like this:
هل تعتقد أن النظام السوري سيستجيب لشروط خاطÙÂي نساء وأطÙÂال من العلوين؟
I tried utf8_decode function but it does not work
thank you
the problem is that the excel file is saved version 5, then I should Register with the 2007 version (. xlsx) and the Arabic values appear correctly in file properities:
$obj_writer = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
$obj_writer->save('php://output');
Related
I am using phpword TemplateProcessor to open dotx. Then, do variable replacement. At last, I want to save as docx. Once I saved as docx, the file could not be opened in microsoft word.
office open XML output.docx could not be opened in microsoft word 2007 because there are problem with contents.
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\TemplateProcessor;
use PhpOffice\PhpWord\IOFactory;
$templateProcessor = new TemplateProcessor('template.dotx');
$templateProcessor->setValue('var1', 'val1');
$templateProcessor->saveAs('output.docx');
//$templateProcessor->saveAs('output.dotx');
//$templateProcessor->saveAs('output.doc');
When I save as dotx, the file can be opened in microsoft word 2007.
When I search for this error, this link explain:
This problem occurs if the following conditions are true:
The mail merge document was saved in the .docx file format.
Note This problem does not occur if you open a mail merge document that was saved in the .doc file format.
The mail merge document uses a separate header source.
This problem occurs because Word 2007 does not support the .docx file
format for a mail merge document that uses a separate header file.
Then, I have saveAs('output.doc'). That file can be opened in microsoft word 2007 without any error.
But, my requirement is to save as docx.
Thank you
I have PDF download functionality in my Laravel application.
It works perfectly when the PDF filename is English, the problem is with other languages.
$pdf = new Pdf();
...
$pdf->generateFromHtml(View::make('invoices.download'.$preferences->invoice_template, $data), $pdf_file_loc);
return Response::download($pdf_file_loc);
In the above code, $pdf_file_loc has a full path of PDF file as well as the PDF filename. Currently, for instance, when the filename is "Förderverein_für.pdf" (it is German), the real name of created PDF file is "Frderverein_fr.pdf".
In other words, the generateFromHtml function is not creating the PDF file with correct German filename.
But after that, as $pdf_file_loc is containing the correct German name, it is trying to download the "Förderverein_für.pdf" file which isn't exist (in the return Response::download($pdf_file_loc)).
So it is showing an error page when I try to download the PDF file
This is causing a serious problem in my live application as the PDF filename contains our customer's company name and it is often written by foreign languages (not English).
As the generateFromHtml function is not creating the file with other languages (not English), I didn't include other languages in the filename but tried to reset the filename with other language while downloading the file.
So, now the $pdf_file_loc doesn't include other language and it is stored with only English in the app store but convert it to other language while downloading.
return Response::download($pdf_file_loc, $filename);
I don't think this is best answer but as long as the purpose is to get the PDF filename with other language, this solves my problem.
I have code for converting xls to xlsx via PHPExcel:
$objPHPexcel = PHPExcel_IOFactory::load('file.xlsx');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
$objWriter->save('new_file.xls');
But when I open created xls file some cells are empty.
What could be the problem?
Thanks!
Link to download original xlsx file
you should use one of following as formate type.
1)Excel5 -> file format between Excel Version 95 to 2003
2)Excel2003XML -> file format for Excel 2003
3)Excel2007 -> file format for Excel 2007
and add following line at line no.3 in your code before save file statement.
$fileType=PHPExcel_IOFactory::identify("file.xlsx"); //We can get file reader type automatically using
it generate file as per your requirement.
I do notice that some of these cells contain references to external files, e.g. cell A23 contains
='[Форма 1-2 от 15.12 ЯНВАРЬ екат.xls]НТТЗМ'!A77
Logically, PHPExcel can't simply access that external file (Форма 1-2 от 15.12 ЯНВАРЬ екат.xls) to retrieve data; nor can it handle references to external files... the file may not even exist; and if it did, there is a major overhead in loading (recursively) every external file that might be referenced in formulae.
While you haven't indicated which cells might be blank in the newly saved file, it would be my guess that they're the cells that contain these external file references
I wanted to append data in the pre formated excel sheet that is basically header footer in the excel sheet I wanted to append the contents. And will create many files dynamically.
A simple workaround is:
create a html table with the formatting you need
add values in php to the table (or generate table with php)
save file as .xls (filled with content from html table)
open file (will show formatted table in Excel)
Reason:
handling XLS files is very complex and many libraries have big limits (only available on windows servers....)
html table saved as .xls can be opened in Excel.
Thanks I have found the way PHPExcel is a good library.
In order to get PHPExcel http://www.codeplex.com/PHPExcel working with CodeIgniter, there are a few steps you must take to ensure compatibility with CodeIgniter's naming standards.
1: Class names must match the file names. PHPExcel has a few files(such as PHPExcel/IOFactory.php) that have names like PHPExcel_IOFactory. Change these names by removing the "PHPExcel_" part. These constructors in these files must be public in order for CI to access them.
$this->load->library('phpexcel');
$this->load->library('PHPExcel/iofactory');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("title")
->setDescription("description");
// Assign cell values
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');
// Save it as an excel 2003 file
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("nameoffile.xls");
I am using PHP to export html table layout into excel format (.xls), well the html format opens up fine in Excel but distorted in OpenOffice..
do i have to add any special config to make html format work in OpenOffice?
Any suggesion would be helpful..
I use the below code
header("Content-Type: application/ms-excel");
header("Content-Disposition: attachment;filename=invoice.xls");
It's my practice to create HTML tables and save them as files with names like something.xls
Then both Excel and OpenOffice will open them as spreadsheets.
I don't use PHP, I use Perl, but no Content headers are involved.