大家好,我要开发一个Word插件,上面有一个按钮,在点击按钮时,我想获取当前打开的Word信息,比如获取到当前打开的Word的二进制流,请问各位有什么办法啊,谢了!
去研究一下dsoframer的源码试试,它是用c++写的,看看是否有帮助。
你可以获取到当前打开文件的路径,然后通过文件api来读取该文件,这样就可以获取到二进制流了
Microsoft.Office.Interop.Word.Application wapp =applicationObject as Microsoft.Office.Interop.Word.Application;
Microsoft.Office.Interop.Excel.Application eapp = applicationObject as Microsoft.Office.Interop.Excel.Application;
Microsoft.Office.Interop.PowerPoint.Application papp = applicationObject as Microsoft.Office.Interop.PowerPoint.Application;
Microsoft.Office.Interop.Visio.Application vapp = applicationObject as Microsoft.Office.Interop.Visio.Application;
Microsoft.Office.Interop.MSProject.Application mapp = applicationObject as Microsoft.Office.Interop.MSProject.Application;
string fullName = "";
if (wapp != null)
{
fullName = wapp.ActiveDocument.FullName;//获取Word的路径名
}
if (eapp != null)
{
fullName = eapp.ActiveWorkbook.FullName;
}
if (papp != null)
{
fullName = papp.ActivePresentation.FullName;
}
if (vapp != null)
{
fullName = vapp.ActiveDocument.FullName;
}
if (mapp != null)
{
fullName = mapp.ActiveProject.FullName;
}
if (!string.IsNullOrEmpty(fullName))
{
LoginForm lf = new LoginForm(fullName);
lf.Show();
}
else
{
MessageBox.Show("系统咱不支持目前版本","消息提示");
}
office 2007以后,存储的是半开源的XML格式,完全可以获取。但是2003及以前版本仍然是二进制文件格式,需要查找相应的API,比较困难些。