Home » excel » How can I open an Excel file from C#/WPF in "Full Screen"?

How can I open an Excel file from C#/WPF in "Full Screen"?

Posted by: admin March 9, 2020 Leave a comment

Questions:

Currently I’m opening files from my C#/WPF application using

System.Diagnostics.Process.Start("C:\ .... ");

Whether the application window is in full screen etc depends on the state the previous instance of the application was in when it was closed (e.g. If it was closed when full screen, it opens a new instance full screen)

What I’m trying to do is open a file in Excel and make it full screen. I looked into command line switches for Excel, seemed fairly limited since I can’t modify the excel files by adding Application.DisplayFullScreen = True into a VBA module.

Edit: Was unclear, but I meant to open it in Full Screen mode (no ribbon etc), not maximized.

Edit2: The key sequence would be alt+v,u. Looking for a way to use SendKeys to send the key sequence to the excel window

How to&Answers:

Looks like you can use SendKeys.

http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

Edit: This code worked for me

Be sure to #include System.Windows.Forms and everything else that’s needed.

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

public void Go()
{
    Process excel = new Process();
    excel.StartInfo.FileName = @"C:\Test.xlsx";
    excel.Start();

    // Need to wait for excel to start
    excel.WaitForInputIdle();

    IntPtr p = excel.MainWindowHandle;
    ShowWindow(p, 1);
    SendKeys.SendWait("%(vu)");
}

See this SO post:

How to open a PDF file by using Foxit/Adobe in full screen mode?

Answer:

Excel interop might work for you… it’s rather nasty to code with but you can do pretty much anything with it that the user can do in excel itself.

This is an overview of how to use it

http://www.dotnetperls.com/excel

This says you can use the property Application.DisplayFullScreen to get it to go full screen

http://msdn.microsoft.com/en-us/library/office/aa168292(v=office.11).aspx