How to disable save confirmation?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedrovarela
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2008 10:40 am

How to disable save confirmation?

Post by pedrovarela »

I have a PHP macro that opens existing Excel files and adds some data. It repeats the rotine on 300 Excel files. If the Excel file doesn't exists it runs smoothly. But if the Excel exists it prompts me a confirmation. I don't want to confirm 300 times... How can I disable the "save" confirmation?

The confirmation comes after:

Code: Select all

$sheet->saveas("c:\\fuste\\$secteur_chg.xls")
where $secteur_chg contains the name of the Excel file.

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: How to disable save confirmation?

Post by Hannes2k »

Hi,
delete (unlink()) the excel file (if it exists) befor calling your saveas method).
pedrovarela
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2008 10:40 am

Re: How to disable save confirmation?

Post by pedrovarela »

Thanks! I think that´s fine for new files. But if I want to modify an existing Excel file, if I delete the Excel file before doing the "saveas" won't I lose all the information? It´s an Excel with many sheets and I´m modyfing just one.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to disable save confirmation?

Post by requinix »

A basic grasp of how files work would help you.
pedrovarela wrote:if I delete the Excel file before doing the "saveas" won't I lose all the information?
Assuming the "macro" is half-decent, no you won't lose anything.
If you are using something crappy, save the file to a new place, delete the old, and move the new one to where the old used to be.
pedrovarela
Forum Newbie
Posts: 3
Joined: Tue Oct 28, 2008 10:40 am

Re: How to disable save confirmation?

Post by pedrovarela »

Thanks for the help but it doesn't work. As I'm only modyfing one sheet from each Excel Workbook, I cannot delete the entire file before the savesas.

May I ask you that next time you can simply reply without analyzing my PHP skills and the quality of my macro? It doesn't add to the solution! Maybe you had a bad day, but just try to be friendlier in your future posts.


Here is a copy of my "crappy" code...

Code: Select all

<?php
  
$fichier_full = file("Selection2.csv");
array_shift($fichier_full);
array_shift($fichier_full);
array_shift($fichier_full);
array_shift($fichier_full);
 
$secteur_chg='';
$secteur_cnt=0;
$fichier_sect='';
$cumul_quota='0';
While ($fichier = array_shift($fichier_full))
{
 
$fichier = ereg_replace(" ","",$fichier);
$fichier = ereg_replace("ETA.","",$fichier);
$fichier = explode(";",$fichier);
$fichier[6]= ereg_replace("%","",$fichier[6]);
 
if ($fichier[3]!='')
{
    if ($secteur_chg==$fichier[0] AND $secteur_cnt<16)
    {
        $quota_secteurs = round(($fichier[3]/$quota)+0.00000001,2)*100;
        $cumul_quota = $cumul_quota + $quota_secteurs;
        $fichier_sect[]="$fichier[1];$fichier[3];$fichier[5];$fichier[6];$quota_secteurs %;$cumul_quota %";
        $secteur_cnt = $secteur_cnt+1;
    }
    if ($secteur_chg!=$fichier[0])
    {
        if ($secteur_cnt>1)
        {
            //Si le fichier existe, le supprimer
        /*  if(file_exists("c:\\fuste\\$secteur_chg.xls")){
                unlink("c:\\fuste\\$secteur_chg.xls");
            } */
            $excel=new COM("Excel.application");//Instanciation de l'objet COM
            $book=$excel->Workbooks->Open("c:\\fuste\\$secteur_chg.xls");//$book contient le classeur actif
            $sheet=$book->Worksheets("Synthèse Hopital");//$sheet contient la feuille active
            $i=9;
            while($row = array_shift($fichier_sect))//Parcours du résultat de la requête
            {
                $row = explode(";",$row);
                $cell=$sheet->Range('B'.$i);
                $cell->value=$row[0];
                $cell=$sheet->Range('C'.$i);
                $cell->value=$row[1];
                $cell=$sheet->Range('D'.$i);
                $cell->value=$row[2];
                $cell=$sheet->Range('E'.$i);
                $cell->value=$row[3];
                $cell=$sheet->Range('F'.$i);
                if (isset($row[4])) $cell->value=$row[4];
                else $cell->value="";
                $cell=$sheet->Range('G'.$i);
                if (isset($row[5])) $cell->value=$row[5];
                else $cell->value="";
                $i++;
            }
            $i--;
            $selection = $sheet->range("A2:E6");//Sélection des cellules qui seront la source du graphique 
            $sheet->saveas("c:\\fuste\\$secteur_chg.xls");//Enregistrement du document
            unset($sheet);//Libération de $sheet
            unset($book);//Libération de $book
            $excel->Workbooks->Close();//Fermeture du classeur
            $excel->Quit();//On quitte Excel
            unset($excel);//Libération de l'objet $excel
        }
        $secteur_cnt=0;
        $secteur_chg='';
        $quota = $fichier[3];
        $cumul_quota=0;
        unset($fichier_sect);
        $fichier_sect[]="$fichier[0];$fichier[3];$fichier[5];$fichier[6]";
        $secteur_cnt = $secteur_cnt+1;
    }
    $secteur_chg = $fichier[0];   
}
 
}
//Si le fichier existe, le supprimer
/* if(file_exists("c:\\fuste\\$secteur_chg.xls")){
    unlink("c:\\fuste\\$secteur_chg.xls");
} */
$excel=new COM("Excel.application");//Instanciation de l'objet COM 
$book=$excel->Workbooks->Open("c:\\fuste\\$secteur_chg.xls");//$book contient le classeur actif
$sheet=$book->Worksheets("Synthèse Hopital");//$sheet contient la feuille active
$i=9;
while($row = array_shift($fichier_sect))//Parcours du résultat de la requête
{
    $row = explode(";",$row);
    $cell=$sheet->Range('B'.$i);
    $cell->value=$row[0];
    $cell=$sheet->Range('C'.$i);
    $cell->value=$row[1];
    $cell=$sheet->Range('D'.$i);
    $cell->value=$row[2];
    $cell=$sheet->Range('E'.$i);
    $cell->value=$row[3];
    $cell=$sheet->Range('F'.$i);
    if (isset($row[4])) $cell->value=$row[4];
    else $cell->value="";
    $cell=$sheet->Range('G'.$i);
    if (isset($row[5])) $cell->value=$row[5];
    else $cell->value="";
    $i++;
}
$i--;
$selection = $sheet->range("A2:E6");//Sélection des cellules qui seront la source du graphique  
$sheet->saveas("c:\\fuste\\$secteur_chg.xls");//Enregistrement du document
unset($sheet);//Libération de $sheet
unset($book);//Libération de $book
$excel->Workbooks->Close();//Fermeture du classeur
$excel->Quit();//On quitte Excel
unset($excel);//Libération de l'objet $excel
Post Reply