简体   繁体   中英

Disable popup message in php

When i upload a excel file, i have used COM() to open and automate converting it to xml.

It works fine, But when i run it, it always shows the message from Microsoft Excel: A file named ''' already exists in this location. Do you want to replace it? I can choose between Yes No and Cancel. normally i would choose Yes. But i dont want users to click on Yes each time. Can i disable this? Please inform me if any relevant codes need to be posted. Thanks
UPDATE Here's part of my code using unlink().

$workbook = $_FILES['file']['tmp_name']
$sheet = "Sheet1";
$ext = substr($workbook, strrpos($workbook, '.') + 1);

$ex = new COM("Excel.sheet") or die("Did not connect");

//Open the workbook that we want to use.
$wkb = $ex->application->Workbooks->Open($workbook) or die("Did not open");
$path = "D:\b2\\test1.xml";
$format = 46;
unlink($path);
$path = "D:\b2\\test1.xml";
//Create a copy of the workbook, so the original workbook will be preserved.
$ex->Application->ActiveWorkbook->SaveAs($path, $format);

Is it the right way to use it? Because it does not seem to work

If you're always going to overwrite, the simplest way is probably just to delete the file first before you get Excel to open it. The PHP function to delete a file is unlink()

我通过添加这一行来解决。

$ex->application->displayAlerts = 0; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM