Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all, this is my first question here. I am using Visual Studio 2010 and I want to design an Excel Addin for a sales catalog. It has two forms and I got one of them working but the other one not. What I want to achieve is that I open up a Windows form through the Addin and through the form I get data from my Access database. I import the data into a datagrid and then I export the data to Excel.

I got this part working but I have problems with my next form. In that form I want to open up a Word template ( when I press a button) and then the data from the open Excel file is transferred into my Word document.
Does anybody know what would be the best way to do this?
I use OleDBConnection to get the data from the database to the datagrid. I am designing this for Office 2007 and I am programming in C#.

Thanks in advance.

Updated:
Here is part of my code. I use this part to get the data from the Excel file into a DataGrid but I want to be able to bring that data into a WordDocument.
Does anybody know what is the best way to do that.
Thanks again.

C#
DataSet da = new DataSet();
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            string workbookPath = "C:myfile.xlsx";

            Excel.Workbook wb = Globals.ThisAddIn.Application.Workbooks.Add(workbookPath);
            string ConnectionString =
            @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + workbookPath
            + @";Extended Properties=""Excel 12.0 Macro;HDR=Yes;ImpoertMixedTypes=Text;TypeGuessRows=0""";

            OleDbConnection conn = new OleDbConnection(ConnectionString);
            string strCmd = " select * from [Sheet1$A1:D4]"; //Or some other range
            OleDbCommand cmd = new OleDbCommand(strCmd, conn);

            conn.Open();
            da.Clear();
            adapter.SelectCommand = cmd;
            adapter.Fill(da);
            dataGridView1.DataSource = da.Tables[0];
Posted
Updated 22-Jun-12 4:48am
v3

1 solution

You have not told what technology you are using ASP.NET, you can change content type, it automatically takes care of exporting data to excel
 
Share this answer
 
Comments
SteiniEy 22-Jun-12 10:50am    
Hello there and thank you for your answer. I updated my question with some code example. I am using Visual Studio 2010 and I am designing an ExcelAddin that uses Windows forms. All code is in C#.
SteiniEy 25-Jun-12 10:51am    
Can no one help me with this?
SteiniEy 27-Jun-12 4:40am    
Could I use the dataSet that I put the data from Excel and fill up a table in Word?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900