7

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

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
ashareef
  • 1,846
  • 13
  • 19

2 Answers2

6

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?

Community
  • 1
  • 1
Miles Watson
  • 169
  • 1
  • 8
  • I just saw your edits. Actually, I think you may be able to use `SendKeys` on another process. Check this post: http://stackoverflow.com/questions/825651/how-can-i-send-the-f4-key-to-a-process-in-c – Miles Watson Dec 02 '13 at 21:32
4

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

Enthusiast
  • 51
  • 2