乔山办公网我们一直在努力
您的位置:乔山办公网 > office365 > C#类库程序怎么获取已经打开的excel的对象,注意是已经打...

C#类库程序怎么获取已经打开的excel的对象,注意是已经打...

作者:乔山办公网日期:

返回目录:office365


在菜单栏中插入(insert)-项目(objective)中进入,选择copy从文件中创建(creat from file),选择浏览(browse),找到需要添加的word文档,然后点击右边的显示图标(display as icon).就可以了.
补充:要调整成你的zhidao要求,好像不可以,要么调整图标的大小(可以调整的),要么调整excel单元格的大小.不过都不是很好.

http://stackoverflow.com/questions/1118735/get-instance-of-excel-application-with-c-sharp-by-handle
public static DataTable ImportExcelToDataSet(string filePath) {
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;Imex=1'";

DataTable dt = new DataTable();
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [message$]", strConn);

try
{
oada.Fill(dt);
}
catch (Exception ex)
{
throw new Exception("该Excel文件的工作表的名字设置为 message,以便获取数据" + ex.Message);
}
return dt;
}

这个e799bee5baa6e79fa5e98193e78988e69d83361方法可以将excel的中表导出到table中 然后自己操作 上面的message就是sheet名称

http:///KB/COM/cominterop.aspx
codeproject上有一个类似的项目,是从ROT中获取activex对象的,可以参考.

我下载后稍微试验了一下,开两个文件名不同的excel,但一直取到同一个名称上,还不能实现你的效果
我的代码:
// System.Runtime.InteropServices

[DllImport("ole32.dll")]
public static extern int GetRunningObjectTable(int reserved,out System.Runtime.InteropServices.UCOMIRunningObjectTable prot);
[DllImport("ole32.dll")]
public static extern int CreateBindCtx(int reserved,out System.Runtime.InteropServices.UCOMIBindCtx ppbc);

private void btnDprocess_Click(object sender,EventArgs e)
{
List<object> list = new List<object>();
int numFetched;
UCOMIRunningObjectTable runningObjectTable;
UCOMIEnumMoniker monikerEnumerator;
UCOMIMoniker[] monikers = new UCOMIMoniker[1];
GetRunningObjectTable(0,out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while(monikerEnumerator.Next(1,monikers,out numFetched) == 0)
{
UCOMIBindCtx ctx;
CreateBindCtx(0,out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx,null,out runningObjectName);
AInfo(runningObjectName);
Guid g = new Guid();
monikers[0].GetClassID(out g);
AInfo(g.ToString());
object runningObjectVal;
runningObjectTable.GetObject(monikers[0],out runningObjectVal);
list.Add(runningObjectVal);
}
for(int i = 0;i < list.Count;i++)
{
OfficeExcel._Application xls = list[i] as OfficeExcel._Application;
if(xls == null)
continue;
try
{
this.listBox1.Items.Add(i.ToString("D3")+"\t"+xls.Workbooks[1].Name);
}
catch { }
}
}

希望对你有参考价值

又查了一下,貌似你的需求是不可能实现的
"You can't connect to a "specific" instance of an application when using
GetActiveObject, if you need this you will have to create a new instance."
不能用GetActiveObject访问特定的应用程序实例,如果需要这样,只能创建新的实例.

No, you can only connect to the single instance that was registered in the
ROT. If you have 3 instances of the "same" server application running, you
will always connect to the first application that was started as this is the
one registered.
只能访问到ROT中注册的单一实例.如果有一个服务程序同时运行了三个实例,总是会访问到启动后的第一个注册实例
If you need a private instance you will need to create a new instance (using
.... = new Excel.ApplicationClass(); )and not connect to an instance that is
already running. This is the point of automation, you should not connect to
an instance started by an interactive user.
可以用new Excel.ApplicationClass创建一个私有的新实例,但不能访问运行中的
实例.这是Automation的机e69da5e6ba90e799bee5baa6337制....
Willy Denoyette [MVP]
http://bytes.com/topic/c-sharp/answers/272571-multiple-excel-processes

相关阅读

  • Access的特点是什么?

  • 乔山办公网office365
  • 在打毕业论文不吧~这是我论文中的Access 的功能特点:Access 是微软公司推出的基于Windows的桌面关系数据库管理系统(RDBMS),是Office系列应用软件之一。它提供了表、查询、窗体、报表、
  • word2007插入-对象-新建里没有microsoft公式...

  • 乔山办公网office365
  • 你的office是2007有问题了!百建议:先用微软官方卸载工具O15CTRRemove.diagcab 卸载你现在的office 2007!百度搜索“ O15CTRRemove.diagcab ”!下载后不需安装直接运行!再百度搜索“Office 2007 SP3专
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网