Thursday, April 5, 2012

Modify Excel Properties through C#


            Excel._Application app=new Excel.Application();
            Excel.Workbooks Wbs=app.Workbooks;;
            Excel.Workbook Wb= Wbs.Add(1);;
            //Excel.Worksheets Osheets;
            Excel.Worksheet Osheet=(Excel.Worksheet)Wb.ActiveSheet;
           
                Osheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;

                Osheet.PageSetup.LeftMargin = double.Parse("42.05");//left margin(0.58) * 72.5
                Osheet.PageSetup.RightMargin = double.Parse("31.09");//right margin(0.44) * 72.5
                Osheet.PageSetup.TopMargin = double.Parse("42.05");
                Osheet.PageSetup.BottomMargin = double.Parse("31.09");
                Osheet.PageSetup.HeaderMargin = double.Parse("0");
                Osheet.PageSetup.FooterMargin = double.Parse("0");

                Range oRng = Osheet.get_Range(Osheet.Cells[1, 1], Osheet.Cells[1, 10]);
                oRng.Merge(Type.Missing);              
                           
                Osheet.Cells[1, 1] = "Nishant";                                       
                Range oRng = (Range)Osheet.Cells[1, 1]
                oRng.EntireColumn.Font.Name = "Arial";
                oRng.EntireColumn.Font.Size = "11";
                oRng.Font.Bold = true;
                oRng.Font.Underline = true;
                oRng.EntireColumn.WrapText = true;
                oRng.EntireColumn.NumberFormat = "@";
                oRng.EntireColumn.VerticalAlignment = XlVAlign.xlVAlignCenter;
                oRng.HorizontalAlignment = XlHAlign.xlHAlignCenter;

No comments:

Post a Comment