Pan*_*kaj 2 passwords excel perl
请告诉我一个抑制密码提示excel文件的解决方案.
use Win32::OLE;
my $xlApp = Win32::OLE->new('Excel.Application');
$xlApp->{Visible} = 0;
$xlApp->{DisplayAlerts} = 0;
# Open excel file.
my $xlBook = $xlApp->Workbooks->Open("C:\\Documents and Settings\\username\\Desktop\\testfile.xls");
my $Sheet1 = $xlBook->Worksheets(1);
my $row = 1;
my $col = 1;
$Sheet1->Cells($row,$col)->{'Value'} = 5;
if (Win32::OLE->LastError)
{
print "File protected";
}
$xlBook ->Close();
undef $xlBook;
Run Code Online (Sandbox Code Playgroud)
如果您知道密码,则可以使用open命令的密码和/或writerespassword参数提供这些密码.如果以这种方式提供密码,Excel将不会提示输入密码.
如果您不知道密码但想要阻止出现对话框,则可以在这些参数中提供虚拟密码(例如,"ThisIsNotAPassword").我没有在文档中找到它,但在Excel 2003中进行了测试: