wordpad automation file printing
7 次查看(过去 30 天)
显示 更早的评论
My problem is the following. I want to print from matlab to the default windows printer a text file created with matlab.
I have successfully open the file using
system("C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe & myfile.txt")
I can manually print the file and exit wordpad. My question is how can I programmatically open the file print and quit wordpad in a siingle command?
A single command because once system("C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe & myfile.txt") is done matlab is waiting until wordpad is closed.
Another way may be to use activeX with word. This initial choice is to avoid end user to have microsoft office.
Thanks a lot for any suggestion.
0 个评论
采纳的回答
Mario Malic
2021-2-11
编辑:Mario Malic
2021-2-15
Hi Alain,
here's the partial answer, see the Internet Explorer way.The issue is that you'll get the printer dialog box in which you'll have to press the button to print manually.
If you're able to somehow find the way to do it automatically, it'd be preety cool. There are few topics on web that are concerned with this dialog box, but in other environments, so if you're brave enough, try them in MATLAB.
Sending keystrokes to the opened application, also useful but due to the fact that printing occurs in another window, sending enter won't close the dialog box. See here.
Edit so the answer is on top:
WordPadProcess = System.Diagnostics.Process;
WordPadProcess.StartInfo.Arguments = "/p filename.txt"
WordPadProcess.StartInfo.FileName = "C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe";
WordPadProcess.StartInfo.UseShellExecute = 0; % you get the error below if run with true
WordPadProcess.Start();
while ~WordPadProcess.HasExited; pause(0.5); end % MATLAB won't proceed further until WordPad is closed
%Message: The Process object must have the UseShellExecute property set
%to false in order to use environment variables.
If one wants to close the process, it can be done with
WordPadProcess.Kill;
7 个评论
Mario Malic
2021-2-15
Great!
You can close the process by this line as well (I glanced over at the Methods, learned something new).
WordPadProcess.Kill;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!