Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Visual-Studio Excel , +
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 1:27am
Edited 22-Jun-12 5: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 at 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 at 25-Jun-12 10:51am
   
Can no one help me with this?
SteiniEy at 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
0 Sergey Alexandrovich Kryukov 382
1 DamithSL 275
2 OriginalGriff 245
3 Zoltán Zörgő 149
4 Dave Kreskowiak 110
0 OriginalGriff 7,575
1 DamithSL 5,529
2 Sergey Alexandrovich Kryukov 5,279
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2014
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