开发者

Disable popup message in php

开发者 https://www.devze.com 2022-12-25 16:14 出处:网络
When i upload a excelfile, i have used COM开发者_Go百科() to open and automate converting it to xml.

When i upload a excel file, i have used COM开发者_Go百科() 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()


I solved it by adding this line.

$ex->application->displayAlerts = 0; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号