LPCRoy
LPCRoy

Reputation: 945

Pass Data into a 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?

Upvotes: 0

Views: 1194

Answers (2)

Bogdan Verbenets
Bogdan Verbenets

Reputation: 26936

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";

Upvotes: 1

PerlDev
PerlDev

Reputation: 437

Use database or isolated storage for to exchange data between your host and hostee.

Upvotes: 0

Related Questions