Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET SQL-Server ADO.NET Excel , +
Hi,
 
I am actually creating a C# windows app that will be generating an excel from a data-table which is the output of a query. The excel needs to be formatted with some specific fonts for each column and the headers.. I know how to create excel but how to format it is not known to me. Can anyone help.
 
after the excel is created, i need to fetch the file and select some particular columns and then paste them in an outlook mail and send it....is is possible??
 
ANY POINTERS WOULD BE HELPFUL...THANKS........
Posted 22-Jun-12 21:52pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The way I have done this sort of things in the past was by using Automation.
 
This sort of programs:
//Start Excel and get Application object.
    oXL = new Excel.Application();
    oXL.Visible = true;
 
    //Get a new workbook.
    oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));
    oSheet = (Excel._Worksheet)oWB.ActiveSheet;
 
    //Add table headers going cell by cell.
    oSheet.Cells[1, 1] = "First Name";
    oSheet.Cells[1, 2] = "Last Name";
    oSheet.Cells[1, 3] = "Full Name";
    oSheet.Cells[1, 4] = "Salary";
 

This is quite easy to generate this sort of code with Word.
Generally I use record a macro and then I look at the code it generated code.
I assume you can perhaps do the same with EXcel.
 
more details:
http://support.microsoft.com/kb/302084[^]
  Permalink  
v2
Comments
Jashobanta at 26-Jun-12 14:58pm
   
I actually want to use Interop.Excel as I am using .net and the company where I work will not permit me to use any 3rd party application when there is already a way to do that.
@Pascal: so, if I need more than one one sheet in a single excel file, is it possible to work in the same way? Can it be formatted?? I did not get time to try this on,but your suggestions seem to be really helpful.
Thanks in Advance......
Pascal Ganaye at 26-Jun-12 16:03pm
   
Yes you can create more than one sheet.
From memory:
sheet1 = oWB.Sheets.Add("Sheet1");
sheet2 = oWB.Sheets.Add("Sheet2");
Then something like
sheet1.Cells[1,2].Font.Bold = True;
I am sure it works but not of the syntax (and I don't have Excel here).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Pascal is suggesting to use Excel.Interop. I direct you to see a 3d party [^]
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 26 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