如何使用asp.net在网页中嵌入openoffice单词 [英] how to embed openoffice word in web page using asp.net

查看:53
本文介绍了如何使用asp.net在网页中嵌入openoffice单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在winform应用程序中执行OpenOffice Automation而不使用c#.net进行用户控制。

这是我的代码,

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Collections.ObjectModel;
使用 System.Windows.Forms;
使用 Microsoft.Win32;
使用 OOLib;

使用 System.Diagnostics;
使用 System.Runtime.InteropServices;

使用 unoidl.com.sun.star.uno;
使用 unoidl.com.sun.star.lang;
使用 unoidl.com.sun.star.frame;

命名空间示例
{
public partial class Form1:Form
{
private const int SW_SHOWNORMAL = 1 ;

[DllImport( user32.dll)]
public static extern bool ShowWindowAsync( IntPtr hWnd, int cmdShow);

[DllImport( user32.dll)]
static extern int SetParent( int hWndChild, int hWndNewParent);

public ObservableCollection< oolib.officedocument>文档{获取; private set ; }
private OOLib.ServiceManager _ServiceManager = null ;
public OOLib.Desktop Desktop { get ; private set ; }

public Form1()
{
Docs = new ObservableCollection< oolib.officedocument>();
InitializeComponent();
}

private void Form1_Load( object sender,EventArgs e)
{
}

private void Init()
{
if (_ ServiceManager == null
{
_ServiceManager = new OOLib.ServiceManager();
Desktop = _ServiceManager.CreateDesktop();
}
如果(桌面!= null
{
var doc = Desktop.CreateTextDocument(hidden = true );
Docs.Add(doc);
}
}
私有 静态 void FindOpenOffice()
{
try
{
// Process currentProcess = Process.GetCurrentProcess(); //在此行中获取MainWindowHandle。
Process [] ps = Process.GetProcessesByName( soffice);
if (ps!= null
{
if (ps.Length > 0
foreach (处理p in ps)
{
// 获取mainwindow句柄。
IntPtr pFoundWindow = p.MainWindowHandle;

// 使用句柄在普通窗口中查看。
if (!pFoundWindow.Equals( IntPtr .Zero))
{
ShowWindowAsync (pFoundWindow,SW_SHOWNORMAL);
}
}
}
else
{
MessageBox.Show( 找不到OpenOffice。是否安装了OpenOffice?);
}
}
catch (System.Exception Exp)
{
MessageBox.Show(Exp。信息);
}
}
public bool hidden {获得; set ; }

private void btnOpen_Click( object sender,EventArgs e)
{
Init();
FindOpenOffice();
}
}
}







但是在上面的代码中,MainWIndowHandle是ZERO



,如果有任何想法,请帮助我。

谢谢

解决方案

Hi,
I want to do OpenOffice Automation in winform application without using user control using c# .net.
Here is my code ,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Microsoft.Win32;
using OOLib;

using System.Diagnostics;
using System.Runtime.InteropServices;

using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.frame;

namespace Sample
{
	public partial class Form1 : Form
	{
		private const int SW_SHOWNORMAL = 1;

		[DllImport("user32.dll")]
		public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

		[DllImport("user32.dll")]
		static extern int SetParent(int hWndChild, int hWndNewParent);
		
		public ObservableCollection<oolib.officedocument> Docs { get; private set; }
		private OOLib.ServiceManager _ServiceManager = null;
		public OOLib.Desktop Desktop { get; private set; }

		public Form1()
		{
			Docs = new ObservableCollection<oolib.officedocument>();
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
		}

		private void Init()
		{
			if(_ServiceManager == null)
			{
				_ServiceManager = new OOLib.ServiceManager();
				Desktop = _ServiceManager.CreateDesktop();
			}
			if(Desktop != null)
			{
				var doc = Desktop.CreateTextDocument(hidden = true);
				Docs.Add(doc);
			}
		}
		private static void FindOpenOffice()
		{
			try
			{
				//Process currentProcess = Process.GetCurrentProcess();  //in this line getting MainWindowHandle.
				Process[] ps = Process.GetProcessesByName("soffice");
				if(ps != null)
				{
					if(ps.Length > 0)
						foreach(Process p in ps)
						{							
							// get mainwindow handle .														
							IntPtr pFoundWindow = p.MainWindowHandle;

							// Use Handle to view in normal window.
							if(!pFoundWindow.Equals(IntPtr.Zero))
							{
								ShowWindowAsync(pFoundWindow, SW_SHOWNORMAL);
							}
						}
				}
				else
				{
					MessageBox.Show("OpenOffice not found. Is OpenOffice installed?");
				}
			}
			catch(System.Exception Exp)
			{
				MessageBox.Show(Exp.Message);
			}
		}
		public bool hidden { get; set; }

		private void btnOpen_Click(object sender, EventArgs e)
		{
			Init();
			FindOpenOffice();
		}
	}
}




But in above code ,MainWIndowHandle is ZERO

, please help me if any one has idea .
Thanks

解决方案

这篇关于如何使用asp.net在网页中嵌入openoffice单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆