Beginning VSTO Development

2019-01-08 05:34发布

问题:

I'm quite confused with what are the necessary tools for VSTO develpment. Specifically I want to manipulate Excel 2003/2007 documents programmatically. I did quite a lot of VBA before, if you want to relate any answer to that.

Few questions I have about VSTO:

  1. Can I use Visual Studio 2008 Express Edition C#/C++ for this?
  2. Do I need to have .NET framework installed?
  3. Does the resulting VSTO program need to have a copy of Office installed in the same system to run?

Direct links to the relevant tools/plugins/IDE will be appreciated.

Note: I'm totally new to VSTO and .NET but an Office power user. I have experience with COM programming.

回答1:

Yeah, it can get confusing, especially given the skip-level naming conventions, etc. Essentially, you'll need:

  • Full version (not Express) of Visual Studio and the .NET version you're targetting.
  • One of the VSTO run times (VSTO 2003, VSTO 2005, VSTO 2005 SE, VSTO 2008, VSTO 2010). For what your asking, VSTO 2005 SE is probably your best bet.
  • When distributing your app, you'll need more, like the PIAs and the .NET version you've targetted. For VSTO 2010, you don't need the PIAs (just what you're using will be packaged with your app automatically).

A couple of tips:

  • Going from the VBE inside of Office to VSTO should be a smooth-ish move if you've used .NET to much extent.
  • The VSTO versions of the object models for any given program (Excel, PowerPoint, etc.) there may be a few more ways of doing things that are different/better than in the VBA version of the object model. For example, the Bookmark control for Word in VSTO 2008 is not the same as the one that is native to one accessed via VBA.
  • Distributing your app can be a pain. This is the very reason that that VSTO for Visual Studio 2010 does not require you to include the full interop (PIA) files with your package.
  • Targetting different versions of Office with the same solution is not officially supported for pre-VSTO 2010. There are ways around this issue that some folks have talked about, but you won't get much support from MSFT on it.

There are some sites that you should take a look at:

  • Requirements VSTO solutions. This is older, but is helpful to read regarding the differences between the 2005 and 2005 SE versions. This one is also decent in that it includes the 2008 version.
  • Online resources for VSTO. This is a good 'jump' site for learning more about VSTO.
  • Getting Started (Visual Studio Tools for Office). This, and it's sister link pages, are good jump pages. Not that useful if you're just coming up to speed with VSTO, but good for a little bit later.
  • Can you build one add-in for multiple versions of Office?. This is older, but discusses some of the issues around building for multiple versions of Office.
  • This site used to be better organized, but I've always found that videos are a very fast way to learn. Most of these videos use one version of VSTO.

Finally, to save the best for last, this is the book I read when I was just starting out and it was very helpful: VSTO for Mere Mortals(TM): A VBA Developer's Guide to Microsoft Office Development Using Visual Studio 2005 Tools for Office



回答2:

SpreadsheetGear for .NET is an Excel compatible spreadsheet component for .NET which will work with Visual Studio Express editions, requires .NET 2.0 or higher, does not require Office or Excel to be installed, and does permit royalty free distribution to an unlimited number of client and / or server computers.

You can see live samples here and download the free trial here.

Disclaimer: I own SpreadsheetGear LLC



回答3:

You can create excel with Express Edition using this Excel .NET component. It doesn't require VSTO, ADO or MS Excel automation.

Excel Jetcell .NET component allows to read write excel spreadsheet. Here you can find many Excel VB.NET and C# examples. For example see VB.NET code to create excel spreadsheet from array:

Imports DTG.Spreadsheet
...
Dim WBook = New ExcelWorkbook()
WBook.Worksheets.Add("ArrayValues")
For i As Short = 0 To 10
   For j As Short = 0 To 10
      WBook.Worksheets(0).Cells[i,j].Value = arr(i,j)
      j = j + 1
   Next j
   i = i + 1
Next i
WBook.WriteXLSX("ExcelSpreadsheet.xlsx")