简体   繁体   English

禁用PHP中的弹出消息

[英]Disable popup message in php

When i upload a excel file, i have used COM() to open and automate converting it to xml. 当我上传一个excel文件时,我已经使用COM()打开并自动将其转换为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. 它工作正常,但是当我运行它时,它总是显示来自Microsoft Excel的消息:此位置已存在一个名为“''的文件。 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(). 更新这是使用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. 如果您总是要覆盖,最简单的方法可能就是先删除文件,然后再让Excel打开它。 The PHP function to delete a file is unlink() 用于删除文件的PHP函数是unlink()

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

$ex->application->displayAlerts = 0; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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