Show / Interactive / Visible ClosedXML Excel.XLWorkbook Without Saving - openxml

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.)

Related

How can I close the report window after code generation using rtwbuild() for a Simulink model from the command line?

I'm trying to automate the building process of my Simulink models. I achieve to handle the configuration of these models as I want.
Then I start generation using the command :
rtwbuild('system', 'Mode', 'ExportFunctionCalls');
That's working pretty well. At the end of the generation, a window appears showing a report of the generation allowing me to browse the just generated code.
My script builds several models and I would like to close this window after each model generation in order to don't disturb the user with all those reports "poping out".
An even better solution would be to not even show this window. I don't need to see it in my generation process and I don't want the user to click the OK button for each report.
So, is there a way to prevent rtwbuild() command to show this report when it's done ? Or at least, is there a way to close this window from the command line after the generation ?
As suggested by #Navan in the comments, there is a model parameter for that.
So to disable the generation of the report (and therefore the opening of the report window), you can simply use the command :
set_param(system, 'GenerateReport', 'Off')
I also got some more information from the MATLAB support. It is also possible to generate this report but prevent the window from opening using these commands :
set_param(system, 'GenerateReport', 'On')
set_param(system, 'LaunchReport', 'Off')
I was using MATLAB R2011a. But since R2012, there are some dedicated methods to open/close code report :
coder.report.open
coder.report.close()

MATLAB Automate GUI

I currently have a GUI that outputs a single text file based on various input parameters. However, I need to modify my application such that the GUI outputs multiple text files based on N inputs. The original GUI designer is no longer available and the main m-file has over 5k lines of code making it difficult to troubleshoot (not to mention the code is very unorganized and not commented). Does anyone have any suggestions on how I can run the GUI N times based on the N inputs and output N text files without modifying the original m-file?
Assume your gui is called myApp and your callback to s called myButton_Callback.
I also assumng that the tag of the uicontrol is 'myButton'.
Here is the caller script:
myApp_h = myApp();
myApp_handles = guidata(myApp_h);
myButton_h = myApp_handles.myButton;
MyApp('myButton_Callback', myButton_h, myApp_handles);
You can automate any gui control by this method.

reading password protected excel file using 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.

how to stop macros running when opening a Word document using OLE Interop?

As the title suggests, I have a .Net application which uses interop to open documents in Word. I have set
app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
before opening the document. According to the documentation, thhis "Disables all macros in all files opened programmatically, without showing any security alerts"
However, when I attempt to open one specific document I get a dialog box on the screen that says "could not load an object because it is not available on this machine". It's a customer document but I believe it contains a macro with references to a COM object which I don't have installed.
Am I doing something stupid? is there any way to actually disable macros when opening a Word document?
Try:
WordBasic.DisableAutoMacros 1
Bizarrely, this relies on a throwback to pre-VBA days, but still seems to be the most-reliable way to ensure that no auto macros are triggered (in any document - you may want to turn it back using the parameter "0").
I recently had a project where I had to process 6,000 Word templates (yes, templates, not documents) many of which had oddball stuff like macros, etc. I was able to process all but 6 using this technique. (I never did figure out what the problem was with those 6).
EDIT: for a discussion of how to call this from C#, see: http://www.dotnet247.com/247reference/msgs/56/281785.aspx
For c# you can use
(_wordApp.WordBasic as dynamic).DisableAutoMacros();
The whole code I'm using is:
using Word = Microsoft.Office.Interop.Word;
private Word.Application _wordApp;
...
_wordApp = new Word.Application
{
Visible = false,
ScreenUpdating = false,
DisplayAlerts = Word.WdAlertLevel.wdAlertsNone,
FileValidation = MsoFileValidationMode.msoFileValidationSkip
};
_wordApp.Application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
(_wordApp.WordBasic as dynamic).DisableAutoMacros();

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.