简体   繁体   中英

Add a reference to WorkBook in Visual Studio (2012) VB.net Project

I have a solution in VS 2012 called T1. Under it I have several projects, mostly VB. One of those projects is an Excel template (xltx). I've added references to all sorts of other projects in the solution (carefully), but the Excel Project doesn't show up in: Add Reference ==> Solution ==> Projects

Is there a way to do this? The solution is an Excel Add-in for reference.

In addition to all my other projects (mostly devoted to data transformations), I'm hoping to: open an Excel template, add values and sheets to that template from an Access database (the sheets would ideally come from other templates), save the file with a date name, and email it to a list of email addresses (probably in OutLook).

I am specifically failing here:

Dim objWorkbook As Excel.Workbook = objApp.Workbooks.Open()

I can get that to work with a path to a local file, but I can't seem to figure out how to reference the template I'm including in the solution.

Thanks.

I am not sure how to reference a workBook. But to read Excel file, the best way for me to read/write excel is using NetOffice . You can check the document and tutorial/code for more info. Code example to read a cell is

using Excel = NetOffice.ExcelApi;


    public String GetCellValueFromSheetIndexCellID(int sheetIndex = 1, String cellID = "A1")
    {
        Excel.Application exApp = new Excel.Application();
        Excel.Workbook book = exApp.Workbooks.Open(this.path);
        Excel.Worksheet sheet = book.Worksheets[sheetIndex] as Excel.Worksheet;


        string returnVal = String.Empty;
        returnVal = GetRangeValue(sheet.Range(cellID));
        exApp.Quit();
        exApp.Dispose();
        return returnVal;
    }

With this library, you can also edit an excel file. Hopefully this helps.

I believe you have to do the following:

Dim objWorkBook = Globals.Thisworkbook

Microsoft choose not to let people know about this.

Or you will need to do the following:

Dim objWorkBook = ExApp.Workbooks.Open("full path to workbook")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM