private void button3_Click(object sender, EventArgs e) { ReflectOffice.Excel.Application app = new ReflectOffice.Excel.Application(); //app.DisplayAlerts = false; Workbook book = app.Workbooks.Add(); Worksheets sheets = book.Worksheets.get_Worksheets(); Worksheet sheet = sheets.AddWorksheet(); sheet = sheets[2]; sheet.Cells[1, 1].Value2 = app.InchesToPoints2(1.3).ToString(); sheet.PageSetup.LeftMargin = app.InchesToPoints2(1.3); sheet.Cells[2, 2].FormulaR1C1 = "4,1"; sheet.get_Range("A1", "D3").Font.Size = 20; sheet.get_Range("A1", "D3").Font.Name = "宋体"; sheet.get_Range("A1", "D3").Font.Underline = ReflectOffice.Excel.XlUnderlineStyle.xlUnderlineStyleSingle; sheet.get_Range("A1", "D3").Font.FontStyle = "加粗 倾斜"; sheet.get_Range("A1", "D3").ColumnWidth = 19; sheet.get_Range("A1", "D3").RowHeight = 15; sheet.get_Range("A1", "D3").Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlContinuous; sheet.get_Range("A1", "D3").Borders[XlBordersIndex.xlEdgeBottom].Weight = ReflectOffice.Excel.XlBorderWeight.xlThick; sheet.get_Range("A1", "D3").HorizontalAlignment = ReflectOffice.Excel.XlHAlign.xlHAlignCenter; sheet.get_Range("A1", "D3").VerticalAlignment = ReflectOffice.Excel.XlVAlign.xlVAlignCenter; sheet.get_Range("A1", "D3").Rows.AutoFit(); sheet.get_Range("A1", "D3").Columns.AutoFit(); book.SaveAs(@"r:\abc.xls", XlFileFormat.xlExcel8); book.Close(); app.Release(); //Microsoft.Office.Interop.Excel.XlUnderlineStyle; }
//My excel private void button5_Click(object sender, EventArgs e) { string _strFileName = @"r:\abcd.xlsx"; ReflectOffice.Excel.Application app = new ReflectOffice.Excel.Application(); //app.Visible = true; textBox1.Text = app.InchesToPoints(5).ToString(); app.DisplayAlerts = false; app.Visible = false; Workbook book = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); //Worksheet sheet = new Worksheet(book.Worksheets.Add()); Worksheet sheet = app.ActiveSheet; sheet.Cells[1, 1].Value2 = app.InchesToPoints2(1.3).ToString(); sheet.PageSetup.LeftMargin = app.InchesToPoints2(1.3); sheet.Cells[2, 3].FormulaR1C1 = "4,1"; sheet.get_Range("A1", "D3").Font.Size = 20; sheet.get_Range("A1", "D3").Font.Name = "宋体"; sheet.get_Range("A1", "D3").Font.Underline = ReflectOffice.Excel.XlUnderlineStyle.xlUnderlineStyleSingle; sheet.get_Range("A1", "D3").Font.FontStyle = "加粗 倾斜"; sheet.get_Range("A1", "D3").ColumnWidth = 19; sheet.get_Range("A1", "D3").RowHeight = 15; sheet.get_Range("A1", "D3").Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlContinuous; sheet.get_Range("A1", "D3").Borders[XlBordersIndex.xlEdgeBottom].Weight = ReflectOffice.Excel.XlBorderWeight.xlThick; sheet.get_Range("A1", "D3").HorizontalAlignment = ReflectOffice.Excel.XlHAlign.xlHAlignCenter; sheet.get_Range("A1", "D3").VerticalAlignment = ReflectOffice.Excel.XlVAlign.xlVAlignCenter; sheet.get_Range("A1", "D3").Rows.AutoFit(); sheet.get_Range("A1", "D3").Columns.AutoFit(); sheet.get_Range("A1", "D3").Merge(); sheet.Select(); sheet.get_Range(sheet.Cells[5, 5], sheet.Cells[6, 6]).ColumnWidth = 50; sheet.get_Range("A1:E5").CopyPicture(); sheet.get_Range("A1").CopyPicture(); Range rng = sheet.get_Range("A11", "D13"); rng.Merge(); app.Windows[1].Zoom = 110; app.Visible = true; //book.SaveAs(_strFileName); //app.Release(); }