About Us      |    Site Map    |     Home                     
   
Help Center Shopping Cart  
Contact Hosting Services  

C# Sourcecode for Excel/COM Programming

This is C sharp sourcecode to provide read, write and create Microsoft Excel Workbooks.

List price: $100.00

Complete C# source code with Visual Studio 2005 solution file with royalty free rights to use and modify.

This sourcecode provides an object named 'excelhelper'.

The sourcecode is developed with the intent to instruct an Excel Workbook in batch mode, completely non-interactive. Use this code to extended your development of C# programs that are already able to contact your databases and other information sources.

Here are the public interfaces the object offers:

public bool Command(string op, string spec, string cmd, string value)
public OrderedDictionary GetValues(string range)
public OrderedDictionary GetComments(string range)
public Workbook Create(string templatefilename)
public ArrayList GetSheetNames()
public Range GetRange(string range, int sheet)
public void Close()
public void Write(Workbook workbook, string filepath)

These public interfaces are straight forward and clean. To note, the GetValues method returns an easy to reference OrderedDictionary, the keys of the collection are in the format "{column}{row}", making it easy to access the data using Column, Row addressing. The Create method is used to open a new workbook, or an existing one. In either case, the workbook returned is available for reading, writing and saving under the same name or a new name. The Command method is the most elaborate and where all of the modification operation are called to.

The Command, op statements include:

  • setactivesheet
  • The code works under the paradigm of active-sheet. All cellrange, column and row commands work on the active sheet for example.

  • addsheet
  • Example calls to the addsheet command are:

    excelhelper.Command("addsheet","0",null,"Sheet one") // add a sheet at index 0, name it "Sheet one"
    excelhelper.Command("addsheet","END",null,"Sheet LAST") // add a sheet to the end of the sheets, named "Sheet LAST"

  • renamesheet
  • Example calls to the renamesheet command are:

    excelhelper.Command("renamesheet","1",null,"New Name Here") // rename the sheet at position 1 to "New Name Here"

  • delsheet
  • Example calls to the delsheet command are:

    excelhelper.Command("delsheet","1",null,null) // delete sheet at position 1, aka: sheet 1.

  • copysheet
  • Example calls to the copysheet command are:

    excelhelper.Command("copysheet","1,0",null,"Sheet new") // copy sheet at position 1, new sheet index is 0, thus shifting the sheets on the copy.
    excelhelper.Command("copysheet","1,END",null,"Sheet END new") // copy sheet at position 1, new sheet is the last one.

  • cellrange
  • Example calls to the cellrange command are:

    excelhelper.Command("cellrange","A1,A1","setvalue","Hello World") // sets the value of cell A1 to "Hello World"
    excelhelper.Command("cellrange","A1,A1","setcomment","Test It") // sets the comment-text on the cell.
    excelhelper.Command("cellrange","A1,A20","sort","asc") // using the range given, sort the data ascending.
    excelhelper.Command("cellrange","A1,A10","copyreplace","B20") // copy the 10 cells to position B20, existing data at B20 is replaced with the copied data.
    excelhelper.Command("cellrange","A1,A10","copyinsert","B20") // copy the 10 cells to position B20, existing data at B20 is shifted down and preserved.
    excelhelper.Command("cellrange","B10,B20","setattribute:Font","Normal") // turn off bold,italic and underline on the cells in the range specified.

  • column
  • Example calls to the column command are:

    excelhelper.Command("column","A","setvalue","10.00") // set the value of all cells in column A to "10.00"

  • row
  • Example calls to the row command are:

    excelhelper.Command("row","10","setattribute:Valign","Center") // set the attribute on all cells in row 10, the VerticalAlignment to value "center"
    excelhelper.Command("row","10","setattribute:Font","Normal") // turn off bold,italic and underline on all cells in row 10.

The settable attributes currently include:

setattribute:Font values: Normal,Bold,Italic,Underline
setattribute:Valign values: Bottom,Center,Top
setattribute:Halign values: Left,Center,Right

Technologies:
Visual Studio 2005 Solution file included.
Utilizes Microsoft COM object (Microsoft.Office.Interop.Excel), which requires full installation on MS-Office Excel on runtime system.


Deployment/implementation service available. Please use our contact form to inquire.

If the object is something that is similar to what you are looking for, your purchase of the sourcecode allows you full modification rights. As well we are interested in providing custom features for your needs. Please inquire for details.


DLL-only available at a savings upon request.

Contact
11115 Margaret Way, Flagstaff, AZ 86004