Pass Data into a VSTO Excel Workbook?

回眸只為那壹抹淺笑 提交于 2019-12-24 20:14:11

问题


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?


回答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:

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.



来源:https://stackoverflow.com/questions/1046657/pass-data-into-a-vsto-excel-workbook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!