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?
我有一个VSTO Excel工作簿项目,我用它来收集用户的信息。此工作簿是从宿主应用程序内部启动的,但我需要在打开它之前将一些参数传递给工作簿,以便它知道要显示什么以及如何显示它。最好的方法是什么?
2 个解决方案
#1
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:
有一种方法可以将数据传递给我个人并不喜欢的工作簿,但也许它可以适合你。基本上,您为工作簿中的特定单元格设置值,然后在Excel的事件处理程序中处理这些值:
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";
#2
Use database or isolated storage for to exchange data between your host and hostee.
使用数据库或隔离存储来在主机和托管服务器之间交换数据。
#1
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:
有一种方法可以将数据传递给我个人并不喜欢的工作簿,但也许它可以适合你。基本上,您为工作簿中的特定单元格设置值,然后在Excel的事件处理程序中处理这些值:
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";
#2
Use database or isolated storage for to exchange data between your host and hostee.
使用数据库或隔离存储来在主机和托管服务器之间交换数据。