winform 在第二块屏幕上显示excel表
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//不可或缺
excelApp.Visible = true;
Workbook wb = excelApp.Workbooks.Open("D:/test.xls", Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
excelApp.ShowToolTips = false;
try
{
Worksheet ws = (Worksheet)wb.Worksheets[1];
bool userDidntCancel = excelApp.Dialogs[XlBuiltInDialog.xlDialogPrintPreview].Show(
123, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
GC.Collect();
GC.WaitForPendingFinalizers();
wb.Close(false, Type.Missing, Type.Missing);
excelApp.Quit();
}
catch ()
{}
以上代码是显示EXCEL的,测试过是好用的。现在我想实现一个功能,电脑在有扩展屏幕的时候,
让excel直接显示在扩展屏幕上,是试了很多方法都只能在主屏幕上显示。
下面这段代码如果是form可以在download事件中加载,试过是好使的,
但是excel没有startpostion和location属性。
private void showOnMonitor(int showOnMonitor)
{
Screen[] sc;
sc = Screen.AllScreens;
if (showOnMonitor >= sc.Length) {
showOnMonitor = 0;
}
this.StartPosition = FormStartPosition.Manual;
this.Location = new System.Drawing.Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);
// If you intend the form to be maximized, change it to normal then maximized.
this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Maximized;
}