将数据传递到VSTO Excel工作簿中? [英] Pass Data into a VSTO Excel Workbook?

查看:35
本文介绍了将数据传递到VSTO Excel工作簿中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VSTO Excel Workbook项目,我正在使用该项目从用户那里收集信息.该工作簿是从主机应用程序内部启动的,但是我需要在打开工作簿之前将一些参数传递给工作簿,以便它知道显示什么以及如何显示它.最好的方法是什么?

I've got an VSTO Excel Workbook project that I'm using to gather information from a user. This workbook is being launched from inside of a host application, but I need to pass some parameters to the workbook before opening it so it knows what to display and how to display it. What's the best way to do this?

推荐答案

有一种方法可以将数据传递给我本人并不喜欢的工作簿,但也许适合您.基本上,您可以为工作簿中的特定单元格设置值,然后在Excel的事件处理程序中处理这些值:

There is a way of passing data to a workbook which personally I don't really like, but maybe it can suit you. Basically, you set values for specific cells in the workbook, and then process those values in Excel's event handler:

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(filepath);
                var sheet = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
                var range = sheet.Range["A1"];
                range.Value2 = "some value";

这篇关于将数据传递到VSTO Excel工作簿中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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