Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Problem inserting a picture with an accent in an Excel file

$
0
0
Hello folks !

I create an Excel file with PHPExcel. I need to insert a file for every line.
I first download the file from a third party web site. I record it on the current file system.
Then I insert it in the Excel file;
                $photoProd = getPhotoProduit($db, $planVenteCourant->id_produit);    
                $objDrawingVignette = new PHPExcel_Worksheet_Drawing(); 
                $objDrawingVignette->setName('Logo'); 
                $objDrawingVignette->setDescription('Logo');
                if(isset($photoProd)) {
                    if($photoProd->path!="") {
                        // Si la photo existe, on l'affiche
                        $opts = array(
                          'http'=>array(
                            'method'=>"GET",
                            'header'=>"Accept-language: fr\r\n" .
                                      "Cookie: foo=bar\r\n"
                          )
                        );

                        $context = stream_context_create($opts);

                        // Accès à un fichier HTTP avec les entêtes HTTP indiqués ci-dessus
                        if(!file_exists($tmpFilePath.'/'.$photoProd->attachmentsid.'_'.$photoProd->name)) {
                            $file = file_get_contents('http://galy.preprod-evencom.fr/crm/'.$photoProd->path.$photoProd->attachmentsid.'_'.utf8_encode($photoProd->name), false, $context);

                            if(!($file === FALSE)) {
                                file_put_contents($tmpFilePath.'/'.$photoProd->attachmentsid.'_'.$photoProd->name, $file);
'.$tmpFilePath.'/'.$photoProd->attachmentsid.'_'.$photoProd->name."\n";
                                $objDrawingVignette->setPath($tmpFilePath.'/'.$photoProd->attachmentsid.'_'.$photoProd->name);                      
                            } else {
                                $objDrawingVignette->setPath('./images/no-photo.gif');
                            }
                        } else {
                            $objDrawingVignette->setPath($tmpFilePath.'/'.$photoProd->attachmentsid.'_'.$photoProd->name);
                        }
                        
                    } else {
                        $objDrawingVignette->setPath('./images/no-photo.gif');
                    }
                }else{
                    $objDrawingVignette->setPath('./images/no-photo.gif');
                }
                
                // Corrige l'alignement
                $objDrawingVignette->setWidth(24);
                $objDrawingVignette->setHeight(36);
                $objDrawingVignette->setOffsetX(2);
                $objDrawingVignette->setOffsetY(1);
                $objDrawingVignette->setWorksheet($sheet);
                                $objDrawingVignette->setCoordinates(PHPExcel_Cell::stringFromColumnIndex(1).$numLigne);
I have some troubles when the file contains an accent. For exemple one file is called : 2349_nectar_pêche_2l.jpg.

There is not any error during the process. But I get a message when I open the Excel file :
"Excel has met an unreadable content in the file. Do you want to restore the sheet ? If the sheet source is reliable, ckick on Yes".
Then I get the message :
Excel a terminé la validation et la réparation de niveau fichier. Certaines parties du classeur peuvent avoir été réparées ou abandonnées.
Enregistrements réparés: Dessin dans la partie /xl/drawings/drawing1.xml (Forme de dessin)
The error log file is :
<recoveryLog>
 <logFileName>error037320_01.xml</logFileName>
 <summary>Des erreurs ont été détectées dans le fichier « C:\Users\EVENCO~1\AppData\Local\Temp\Plan Ventes Gamme SCAOUEST 2014-03-06-5.xlsx »</summary>
<additionalInfo>
 <info>Excel a terminé la validation et la réparation de niveau fichier. Certaines parties du classeur peuvent avoir été réparées ou abandonnées.</info>
 </additionalInfo>
<repairedRecords summary="Liste des réparations :">
 <repairedRecord>Enregistrements réparés: Dessin dans la partie /xl/drawings/drawing1.xml (Forme de dessin)</repairedRecord>
 </repairedRecords>
 </recoveryLog>
I have unzipped the Excel File.
In the folder /xl/media, the file is renamed to : 2349_nectar_pÛche_2l45.jpg

In the folder / xl/drawings/_rels, the file drawing1.xml.rels containe the file name : 2349_nectar_pêche_2l45.jpg
<Relationship Id="rId45" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/2349_nectar_pêche_2l45.jpg"/>
Has anybody any idea to fix this problem ?

Thanks in advance for your help.

Regard,

Xavier

Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>