-->
- Microsoft Office Interop 2013 Download
- Microsoft.office.interop.access.dao Example
- Microsoft.office.interop.access.dao.dbengine Class Not Registered
Policy.12.0.Microsoft.Office.Interop.Access.Dao files such as Policy.12.0.Microsoft.Office.Interop.Access.Dao.dll utilize the DLL file extension. This file is considered a Win32 DLL (Dynamic link library) file, and was first created by Microsoft for the Microsoft Office 2010 software package.
Visual C# has features that simplify access to Office API objects. The new features include named and optional arguments, a new type called
dynamic
, and the ability to pass arguments to reference parameters in COM methods as if they were value parameters.In this topic you will use the new features to write code that creates and displays a Microsoft Office Excel worksheet. You will then write code to add an Office Word document that contains an icon that is linked to the Excel worksheet.
- Could not load file or assembly Microsoft.Office.Interop.Access.Dao, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c or one of its dependencies. The system cannot find the file specified.
- Microsoft Office 2010: Primary Interop Assemblies Redistributable. To install the Office 2010 Primary Interop Assemblies, click the Download button, then click Save and select a location for PIARedist.exe on your computer. Run the executable to extract the O2010pia.msi file. Wrap the O2010pia.msi file in another setup package through Visual Studio.
- This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread.
To complete this walkthrough, you must have Microsoft Office Excel 2007 and Microsoft Office Word 2007, or later versions, installed on your computer.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Personalizing the IDE.
To create a new console application
- Start Visual Studio.
- On the File menu, point to New, and then click Project. The New Project dialog box appears.
- In the Installed Templates pane, expand Visual C#, and then click Windows.
- Look at the top of the New Project dialog box to make sure that .NET Framework 4 (or later version) is selected as a target framework.
- In the Templates pane, click Console Application.
- Type a name for your project in the Name field.
- Click OK.The new project appears in Solution Explorer.
To add references
- In Solution Explorer, right-click your project's name and then click Add Reference. The Add Reference dialog box appears.
- On the Assemblies page, select Microsoft.Office.Interop.Word in the Component Name list, and then hold down the CTRL key and select Microsoft.Office.Interop.Excel. If you do not see the assemblies, you may need to ensure they are installed and displayed (see How to: Install Office Primary Interop Assemblies)
- Click OK.
To add necessary using directives
- In Solution Explorer, right-click the Program.cs file and then click View Code.
- Add the following
using
directives to the top of the code file.
To create a list of bank accounts
- Paste the following class definition into Program.cs, under the
Program
class. - Add the following code to the
Main
method to create abankAccounts
list that contains two accounts.
To declare a method that exports account information to Excel
- Add the following method to the
Program
class to set up an Excel worksheet.Method Add has an optional parameter for specifying a particular template. Optional parameters, new in C# 4, enable you to omit the argument for that parameter if you want to use the parameter's default value. Because no argument is sent in the following code,Add
uses the default template and creates a new workbook. The equivalent statement in earlier versions of C# requires a placeholder argument:ExcelApp.Workbooks.Add(Type.Missing)
. - Add the following code at the end of
DisplayInExcel
. The code inserts values into the first two columns of the first row of the worksheet. - Add the following code at the end of
DisplayInExcel
. Theforeach
loop puts the information from the list of accounts into the first two columns of successive rows of the worksheet. - Add the following code at the end of
DisplayInExcel
to adjust the column widths to fit the content.Earlier versions of C# require explicit casting for these operations becauseExcelApp.Columns[1]
returns anObject
, andAutoFit
is an Excel Range method. The following lines show the casting.C# 4, and later versions, converts the returnedObject
todynamic
automatically if the assembly is referenced by the /link compiler option or, equivalently, if the Excel Embed Interop Types property is set to true. True is the default value for this property.
To run the project
- Add the following line at the end of
Main
. - Press CTRL+F5.An Excel worksheet appears that contains the data from the two accounts.
To add a Word document
- To illustrate additional ways in which C# 4, and later versions, enhances Office programming, the following code opens a Word application and creates an icon that links to the Excel worksheet.Paste method
CreateIconInWordDoc
, provided later in this step, into theProgram
class.CreateIconInWordDoc
uses named and optional arguments to reduce the complexity of the method calls to Add and PasteSpecial. These calls incorporate two other new features introduced in C# 4 that simplify calls to COM methods that have reference parameters. First, you can send arguments to the reference parameters as if they were value parameters. That is, you can send values directly, without creating a variable for each reference parameter. The compiler generates temporary variables to hold the argument values, and discards the variables when you return from the call. Second, you can omit theref
keyword in the argument list.TheAdd
method has four reference parameters, all of which are optional. In C# 4.0 and later versions, you can omit arguments for any or all of the parameters if you want to use their default values. In C# 3.0 and earlier versions, an argument must be provided for each parameter, and the argument must be a variable because the parameters are reference parameters.ThePasteSpecial
method inserts the contents of the Clipboard. The method has seven reference parameters, all of which are optional. The following code specifies arguments for two of them:Link
, to create a link to the source of the Clipboard contents, andDisplayAsIcon
, to display the link as an icon. In C# 4.0 and later versions, you can use named arguments for those two and omit the others. Although these are reference parameters, you do not have to use theref
keyword, or to create variables to send in as arguments. You can send the values directly. In C# 3.0 and earlier versions, you must supply a variable argument for each reference parameter.In C# 3.0 and earlier versions of the language, the following more complex code is required. - Add the following statement at the end of
Main
. - Add the following statement at the end of
DisplayInExcel
. TheCopy
method adds the worksheet to the Clipboard. - Press CTRL+F5.A Word document appears that contains an icon. Double-click the icon to bring the worksheet to the foreground.
To set the Embed Interop Types property
- Additional enhancements are possible when you call a COM type that does not require a primary interop assembly (PIA) at run time. Removing the dependency on PIAs results in version independence and easier deployment. For more information about the advantages of programming without PIAs, see Walkthrough: Embedding Types from Managed Assemblies.In addition, programming is easier because the types that are required and returned by COM methods can be represented by using the type
dynamic
instead ofObject
. Variables that have typedynamic
are not evaluated until run time, which eliminates the need for explicit casting. For more information, see Using Type dynamic.In C# 4, embedding type information instead of using PIAs is default behavior. Because of that default, several of the previous examples are simplified because explicit casting is not required. For example, the declaration ofworksheet
inDisplayInExcel
is written asExcel._Worksheet workSheet = excelApp.ActiveSheet
rather thanExcel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet
. The calls toAutoFit
in the same method also would require explicit casting without the default, becauseExcelApp.Columns[1]
returns anObject
, andAutoFit
is an Excel method. The following code shows the casting. - To change the default and use PIAs instead of embedding type information, expand the References node in Solution Explorer and then select Microsoft.Office.Interop.Excel or Microsoft.Office.Interop.Word.
- If you cannot see the Properties window, press F4.
- Find Embed Interop Types in the list of properties, and change its value to False. Equivalently, you can compile by using the /reference compiler option instead of /link at a command prompt.
To add additional formatting to the table
- Replace the two calls to
AutoFit
inDisplayInExcel
with the following statement.The AutoFormat method has seven value parameters, all of which are optional. Named and optional arguments enable you to provide arguments for none, some, or all of them. In the previous statement, an argument is supplied for only one of the parameters,Format
. BecauseFormat
is the first parameter in the parameter list, you do not have to provide the parameter name. However, the statement might be easier to understand if the parameter name is included, as is shown in the following code. - Press CTRL+F5 to see the result. Other formats are listed in the XlRangeAutoFormat enumeration.
- Compare the statement in step 1 with the following code, which shows the arguments that are required in C# 3.0 and earlier versions.
Example
The following code shows the complete example.
See also
-->Applies to: Access 2013, Office 2013
Creates a new Database object, saves the database to disk, and returns an opened Database object (Microsoft Access workspaces only). .
Syntax
expression .CreateDatabase(Name, Locale, Option)
expression A variable that represents a DBEngine object.
Parameters
Name | Required/optional | Data type | Description |
---|---|---|---|
Name | Required | String | A String up to 255 characters long that is the name of the database file that you're creating. It can be the full path and file name. If your network supports it, you can also specify a network path, such as 'server1share1dir1db1'. You can only create Microsoft Access database files with this method. |
Locale | Required | String |
|
Option | Optional | Variant | A constant or combination of constants that indicates one or more options, as specified in Settings. You can combine options by summing the corresponding constants. |
Remarks
You can use one of the following constants for the locale argument to specify the CollatingOrder property of text for string comparisons.
Microsoft Office Interop 2013 Download
Constant | Collating order |
---|---|
dbLangGeneral | English, German, French, Portuguese, Italian, and Modern Spanish |
dbLangArabic | Arabic |
dbLangChineseSimplified | Simplified Chinese |
dbLangChineseTraditional | Traditional Chinese |
dbLangCyrillic | Russian |
dbLangCzech | Czech |
dbLangDutch | Dutch |
dbLangGreek | Greek |
dbLangHebrew | Hebrew |
dbLangHungarian | Hungarian |
dbLangIcelandic | Icelandic |
dbLangJapanese | Japanese |
dbLangKorean | Korean |
dbLangNordic | Nordic languages (Microsoft Jet database engine version 1.0 only) |
dbLangNorwDan | Norwegian and Danish |
dbLangPolish | Polish |
dbLangSlovenian | Slovenian |
dbLangSpanish | Traditional Spanish |
dbLangSwedFin | Swedish and Finnish |
dbLangThai | Thai |
dbLangTurkish | Turkish |
You can use one or more of the following constants in the options argument to specify which version the data format should have and whether or not to encrypt the database.
Microsoft.office.interop.access.dao Example
Constant | Description |
---|---|
dbEncrypt | Creates an encrypted database. |
dbVersion10 | Creates a database that uses the Microsoft Jet database engine version 1.0 file format. |
dbVersion11 | Creates a database that uses the Microsoft Jet database engine version 1.1 file format. |
dbVersion20 | Creates a database that uses the Microsoft Jet database engine version 2.0 file format. |
dbVersion30 | Creates a database that uses the Microsoft Jet database engine version 3.0 file format (compatible with version 3.5). |
dbVersion40 | Creates a database that uses the Microsoft Jet database engine version 4.0 file format. |
dbVersion120 | Creates a database that uses the Microsoft Access database engine version 12.0 file format. |
If you omit the encryption constant, CreateDatabase creates an un-encrypted database.
Microsoft.office.interop.access.dao.dbengine Class Not Registered
Use the CreateDatabase method to create and open a new, empty database, and return the Database object. You must complete its structure and content by using additional DAO objects. If you want to make a partial or complete copy of an existing database, you can use the CompactDatabase method to make a copy that you can customize.