reading password protected excel file using matlab - matlab

I am trying to read a password protected excel file, the problem I am having with the following code is it does not take care of password, but instead excel application opens but user has to go to taskbar and click excel app to see the password query.
path = fullfile(pwd,'tests.xls')
e=actxserver('excel.application');
eW = e.Workbooks;
eF = eW.Open(file3,'GSL');
[num,txt,raw] = xlsread(file3, 1);

I can think of two ways to solve the problem. I don't have access to a Windows machine so you'll have to figure out the details yourself:
Use Matlab's GUI functions to ask the user for the password. Then, supply that password to the Open method along with the filename (Excel Open method documentation).
After calling actxserver try to bring the Excel window into focus so that when you open the file, the password dialog box is visible. Something like described here should work.

Related

How to avoid opening a QuickInput when choosing files to compare in a vscode extension?

In my case I want to compare two files.
But I don't want the user to select the File in the QuickInput form, i want to choose this directly for him.
vscode.commands.executeCommand("workbench.files.action.compareFileWith", filePath)
This results in
Meaning that filePath is ignored and a QuickInput is displayed instead.
Is there a way to directly select a file programmatically instead of showing the QuickInput first?
While the compareFileWith command probably requires a QuickInput panel to use, you can use the other compare commands to do what you want:
// using the current file for the 'compareWith' file
const currentFileUri = vscode.window.activeTextEditor.document.uri;
// create a Uri from some filePath
const compareWithSelectedUri = vscode.Uri.file('C:\\Users\\Mark\\OneDrive\\Test Bed\\BAR.txt');
await vscode.commands.executeCommand('selectForCompare', currentFileUri)
await vscode.commands.executeCommand('compareFiles', compareWithSelectedUri);
This works in my testing.
Looking at compareFileWith in https://github.com/microsoft/vscode/blob/9b9361cfd1b0678f0bb0b32bf9925b6520bb9926/src/vs/workbench/contrib/files/browser/fileActions.ts I don't think there is any way to avoid the QuickInput opening.
Alternatively, what you are asking for would be "easy" if an open method were supported on TabGroups api like the close methods. You would create a tab of kind TabInputTextDiff with an original uri and a modifieed uri.
When the TabGroups api was being developed there was an open tab method but it was removed prior to release and hasn't seen any love since. See https://github.com/microsoft/vscode/commit/aa69f3d7623c464aba726d12ea0d83428f43e8b9#commitcomment-71831337.
I'll open an issue to see if it will help (and post the link here later).

Houdini flipbook default output location

I would like to set a default output location for the Houdini flipbook so that all users have a standard path to save and look for their flipbook sequences rather than everyone inputting their own save locations from the gui. Is there an option or setting for that, preferably something I could set with an environment variable?
This script might help.
Just create a new tool and paste code into script tab.
Once you click on the tool, it will load up the flipbook and save jpg sequence to disk.
Also make sure to create "resx" and "resy" here, here, and here
PS: double check if folder you are outputing JPGs to exists.
import os
import toolutils
filename = "---YOURPATH---/$HIPNAME/$HIPNAME.$F4.jpg"
scene = toolutils.sceneViewer()
setting = scene.flipbookSettings().stash()
res = (int(hou.getenv("resx")), int(hou.getenv("resy")))
range = hou.playbar.playbackRange()
setting.frameRange(range)
setting.output(filename)
setting.useResolution(True)
setting.motionBlurSegments(10)
setting.resolution(res)
setting.useMotionBlur(False)
scene.flipbook(scene.curViewport(), settings)

Show / Interactive / Visible ClosedXML Excel.XLWorkbook Without Saving

Using ClosedXML is it possible to show a new Excel.XLWorkbook() in the GUI without first saving the file?
I am using VB .Net and moving from Microsoft.Office.Interop.Excel to ClosedXML to take advantage of the increased speed.
In Excel Interop I can create a new Excel.ApplicationClass and choose whether to make Excel visible in the GUI by setting .interactive and .visible to TRUE.
Is there an equivalent for ClosedXML to show Excel in the GUI?
I cannot find anything in the ClosedXML library that would appear to affect application visibility.
Microsoft.Office.Interop.Excel:
ExcelReport = New Excel.ApplicationClass
ExcelReport.Interactive = True 'True = Excel is interactive in the GUI
ExcelReport.Visible = True 'True = Excel is visible in the GUI
ClosedXML:
Dim wb = New Excel.XLWorkbook()
wb.Visible = True (no equivalent)
I know part of the beauty of ClosedXML is that Excel is not actually required to generate the file, however I would like the ability to debug and visualise the file inside Excel during creation/writing.
I would also like the end user to decide whether or not to save the file and if so where to save it. Currently, using Excel Interop, the report is presented to to the end user in the GUI as an unsaved 'Book1' workbook. They can interact with the excel report without saving, close it, save it somewhere else.
Is this possible using ClosedXML?
Is there an equivalent for ClosedXML to show Excel in the GUI?
No, there is not. (Except when you write a complete new GUI for ClosedXML.)

Password protected excel

can we create password protected excel workbook or sheet with 'Officewriter' API? My requirement is to create pwd protected excel programatically (c#) with out having to install office in the servers.
I have tried with openXML but the when password protected the file is showing as corrupted and not opening.
Anybody let me know if this is possible with 'Officewriter'.
Note: I work for SoftArtisans, makers of OfficeWriter.
Yes, it is possible to password protect an Excel workbook programmatically with OfficeWriter.
If you are using our ExcelApplication API to programmatically manipulate a workbook, you can protect workbooks and worksheets.
Workbook.Protect(string) will protect the structure of the workbook with the supplied password. For example, users won't be able to add or remove worksheets without the password.
Worksheet.Protect(string) write-protects the worksheet so users cannot modify the worksheet in Excel without entering the password.
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Open("myWorkbook.xlsx");
wb.Protect("workbookPassword");
wb.Worksheets["Sheet1"].Protect("worksheetPassword");
xla.Save(wb, "myWorkbook_output.xlsx");
If you are using our ExcelTemplate API to bind data to a template that contains placeholder markers, you can set ExcelTemplate.EncryptPassword which will encrypt the workbook with the given password using RC4 encryption.
ExcelTemplate xlt = new ExcelTemplate();
xlt.Open("template.xlsx");
...
xlt.EncryptPassword = "MyPassword";
xlt.Process();
xlt.Save("output.xlsx");

automate excel file processing in perl and avoid dialog/UI interactions

How can a I guarantee that no pop-up dialogs will appear when I automate Microsoft Excel through OLE? I'm using a Perl module (Win32::OLE). I can avoid most dialog pop-ups using the following code:
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::OLE::Const;
my $excel_symbols = Win32::OLE::Const->Load('Microsoft Excel');
my $excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit();} );
$excel->{'Visible'} = 0;
$excel->{'DisplayAlerts'} = 0;
$excel->Workbooks->Open('c:\some_excel_file.xls',
{ 'UpdateLinks' => $excel_symbols->{'xlUpdateLinksNever'},
'ReadOnly' => 1,
'IgnoreReadOnlyRecommended' => 1
});
However for some files, I continue to get a dialog with the following text:
This file is not a recognizable
format.
If you know the file is from another program which is incompatible with
Microsoft Excel, click Cancel, then
open this file in its original
application. If you want to open the
file later in Microsoft Excel, save it
in a format that is compatible, such
as text format.
If you suspect the file is damaged, click Help for more information about
solving the problem.
If you still want to see what text is contained in the file, Click OK.
Then click Finish in the Text Import
Wizard.
OK Cancel
Sometimes a similar dialog appears that contains 'OK', 'Cancel' and 'Help' buttons.
I cannot control the quality of files that are provided to the scripts.
You could consider using Spreadsheet::ParseExcel (albeit it may lack features you need) or Apache POI (albeit it will need some wrapping to use in a Perl script) instead of calling the Excel engine over OLE. That way you won't get any Excel-generated dialogs.
I revisited this issue and found a solution.
Copy the file before processing to a temporary location. Then save the file before closing it in Excel:
File::Copy::copy('c:\some_excel_file.xls', 'c:\temp\SFO3jfd.xls');
my $book = $excel->Workbooks->Open('c:\temp\SFO3jfd.xls',
{ 'UpdateLinks' => $excel_symbols->{'xlUpdateLinksNever'},
'ReadOnly' => 1,
'IgnoreReadOnlyRecommended' => 1
});
$book->Save();
$book->Close();
Why this works:
Excel 2003 automatically recalculates the formulas in documents that were created in an older version of Excel. Furthermore, macros could be invoked when the document is opened. All of this means that there could be changes made on a document, even though your script doesn't perform any such operations.
By saving the document before closing, you avoid the dialog requesting that you save the file. Using a temporary file ensures that the original file does not get changed during the validation operation. If you aren't concerned about this, you might consider validating in-place.
Here is full documentation for Open method. I wonder if CorruptLoad parameter is what you need.
If you are trying of process all xl files in the tree, some of them may be open by other users and have the ~ prefix.