tags:

views:

49

answers:

2

Hi, i want to format excel sheet generating by my c# application, as per template excel / source excel sheet which is.

A: 

I have done this using Linq to XML and the SpreadsheetML format used when you save an Excel workbook as XML. Basically, you create the format spreadsheet however you need it. Then, you save it as XML. You find the areas that you want to programatically alter, and use Linq to XML to do so. The easiest way to identify interesting areas in the spreadsheet is to use labelled cells.

The SpreadsheetML can get pretty complicated, but this method has worked for me in the past.

jkohlhepp
A: 

Using the Interop.Excel assembly (How to), you can load your excel template when creating the new Workbook:

Microsoft.Office.Interop.Excel.Application xlApp = new Application();
Microsoft.Office.Interop.Excel.Workbook wb = xlApp.Workbooks.Open("excelTemplateFile.xls",
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing);
DrDro