Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 23rd, 2006, 08:25 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel cell Formating Using C#

Hi..Friends,

how to format cells patterns,Border color, Font styles,
and Rename Worksheet Name for MS-Excel.
Using C#.

Plz help meee...

Thanks & Regards,
Veeruu...


Reply With Quote
  #2 (permalink)  
Old April 5th, 2006, 05:52 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

//Variables
protected Excel.Worksheet feuilleExcel;
protected Excel.Range Cellules;
protected Excel.Range UneCellule;
protected Excel.Range DeuxCellules;
protected ExcelApplication xls;

//Open worksheet #1
this.feuilleExcel = (Excel.Worksheet)xls.__Excel.Worksheets[1];
this.feuilleExcel.Activate();
//get entire cells
this.Cellules = this.feuilleExcel.Cells;

//work on 1 cell
this.UneCellule=(Excel.Range)this.Cellules[XListe,YListe];
//value inserted
this.UneCellule.Value=this.ListeTypesCarte[i];
//cell border
this.UneCellule.BorderAround(Excel.XlLineStyle.xlC ontinuous,Excel.XlBorderWeight.xlThin,Excel.XlColo rIndex.xlColorIndexAutomatic,1);
//font style
this.UneCellule.Font.Bold=true;
//background color
this.UneCellule.Interior.Color=16777164;

//work on 2 cells
//insert values on first cell
this.Cellules[X,1]=rs.GetString(0);
//get cells
this.DeuxCellules = (Excel.Range)this.feuilleExcel.get_Range(this.Cell ules[X,1],this.Cellules[X,2]);
//cell border
this.DeuxCellules.BorderAround(Excel.XlLineStyle.x lContinuous,Excel.XlBorderWeight.xlThin,Excel.XlCo lorIndex.xlColorIndexAutomatic,1);
//background color
this.DeuxCellules.Interior.Color=10092543;
//font style
this.DeuxCellules.Font.Bold=true;

***********************************
EXCEL CLASS
***********************************
using System;
using System.Reflection;

namespace ControlOffice
{
public class ExcelApplication
    {
        public Excel.Application __Excel; // Application est une interface
        public object opt= Missing.Value;
        public string f;

        public ExcelApplication(string fich)
        {
            //
            // TODO†: ajoutez ici la logique du constructeur
            //

            __Excel=new Excel.ApplicationClass();
            __Excel.Workbooks.Open(fich,opt,opt,opt,opt,opt,op t,opt,opt,opt,opt,opt, opt);
            f =fich;


        }

        public bool Visible
        {
            get
            {
                return __Excel.Visible;
            }
            set
            {
                __Excel.Visible=value;
            }
        }

        public Excel.Workbook nomClasseur
        {
            get
            {
                return __Excel.ActiveWorkbook;
            }
        }

        public Excel.Worksheet nomFeuil
        {
            get
            {
                return (Excel.Worksheet) __Excel.ActiveWorkbook.ActiveSheet;
            }
        }

        public Excel.Range Cellules
        {
            get
            {

                return nomFeuil.Cells;

            }
        }





        public void quit(bool save)
        {

            //__Excel.ActiveWorkbook.Close(save,opt,opt);
            __Excel.ActiveWorkbook.Close(save,this.opt,this.op t);
            __Excel.Quit();

        }
    }
}

****IMPORTANT*****
Don't forget join Office and Excel references to project


Reply With Quote
  #3 (permalink)  
Old April 7th, 2006, 02:32 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi laure,
Thanks alot for your response.
"If you dont mind.." Can you please mail your application to me.
to finish my Task a bit fast..

Thanks & regards,
veeruuu...

prasad7478@yahoo.com


Reply With Quote
  #4 (permalink)  
Old March 4th, 2010, 04:42 AM
Registered User
 
Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

for easier Excel manipulation, I recommend this Excel C# component.

Here is a code snippet for all tasks you need:

Code:
var excelFile = new ExcelFile();
var worksheet = excelFile.Worksheets.Add("Worksheet1");
ws.Cells[0, 0].Value = DateTime.Now; // Type is System.DateTime

// Some Font Styles
ws.Cells[0, 0].Style.Font.Color = Color.Blue;
ws.Cells[0, 0].Style.Font.Italic = true;
ws.Cells[0, 0].Style.Font.Name = "Comic Sans MS";
ws.Cells[0, 0].Style.Font.Size = 150;

// Setting border on cell range
var mergedRange = ws.Cells.GetSubrangeAbsolute(0, 0, 10, 5);
var cellStyle = new CellStyle();
cellStyle.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Top, Color.Black, LineStyle.Thin);
mergedRange.Style = cellStyle;

// Change worksheet name
worksheet.Name = "Another name";

// Saves the excel file.
excelFile.SaveXls("excelFile.xls");
Reply With Quote
  #5 (permalink)  
Old March 9th, 2010, 01:32 AM
Authorized User
Points: 102, Level: 2
Points: 102, Level: 2 Points: 102, Level: 2 Points: 102, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2008
Location: , , .
Posts: 30
Thanks: 0
Thanked 1 Time in 1 Post
Default Excel formatting

go through the following link

http://csharp.net-informations.com/e...rmat-excel.htm

hu.
Reply With Quote
  #6 (permalink)  
Old September 21st, 2011, 02:56 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting a excel cell programtically in asp.net c#

I put this way but there is an syntax error: newSheet.Cells[i + 2, 3] = drugorder.DATE; HorizontalAlignment == ExcelAlignment.xlLeft; Error 2 'System.Windows.Forms.HorizontalAlignment' is a 'type' but is used like a 'variable' C:\ADL\ExcelReader\ExcelReader\Form1.cs 257 68 ExcelReader Error 3 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\ADL\ExcelReader\ExcelReader\Form1.cs 257 68 ExcelReader
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Excel Cell color populate .NET Framework 2.0 2 March 3rd, 2014 04:25 AM
c# and Excel cell values hardboiled C# 0 November 16th, 2007 11:12 AM
cell references excel weazy Excel VBA 0 June 21st, 2006 10:28 AM
Changing Cell-formating in Excel via VBA Gert VB How-To 4 May 10th, 2005 02:56 PM
Unprotect a cell on Excel camf650 VBScript 2 April 14th, 2004 12:26 PM



All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.