Click here to Skip to main content
12,352,055 members (33,858 online)
Rate this:
 
Please Sign up or sign in to vote.
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.

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 22-Jun-12 0:27am
Edited 22-Jun-12 4:48am
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100