1 public void OutExcel()
2 {
3 #region
4 WorkbookDesigner designer = new WorkbookDesigner();
5 Worksheet sheet = designer.Workbook.Worksheets[0];
6 Workbook book = designer.Workbook;
7
8 Aspose.Cells.Style style1 = book.Styles[book.Styles.Add()];
9 style1.Font.Name = "黑體";//文字字體
10 style1.Font.Size = 16;//文字大小
11
12 Aspose.Cells.Style style2 = book.Styles[book.Styles.Add()];
13 style2.HorizontalAlignment = TextAlignmentType.Center;
14 style2.Font.Name = "宋體";//文字字體
15 style2.Font.IsBold = true;//粗體
16 style2.Font.Size = 18;//文字大小
17
18 style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
19 style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
20 style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
21 style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
22 style2.Borders[BorderType.TopBorder].Color = Color.Black;
23 style2.Borders[BorderType.BottomBorder].Color = Color.Black;
24 style2.Borders[BorderType.LeftBorder].Color = Color.Black;
25 style2.Borders[BorderType.RightBorder].Color = Color.Black;
26
27
28
29 Aspose.Cells.Style style3 = book.Styles[book.Styles.Add()];
30 style3.HorizontalAlignment = TextAlignmentType.Center;
31 style3.Font.Name = "宋體";//文字字體
32 style3.Font.Size = 15;//文字大小
33 style2.Font.IsBold = true;//粗體
34
35
36 Aspose.Cells.Style style4 = book.Styles[book.Styles.Add()];
37 style4.HorizontalAlignment = TextAlignmentType.Center;
38 // style4.Font.Name = "黑體";//文字字體 "Arial Rounded MT Bold";//
39 style4.Font.Size = 11;//文字大小
40
41 Aspose.Cells.Style style5 = book.Styles[book.Styles.Add()];
42 style5.HorizontalAlignment = TextAlignmentType.Center;
43 style5.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
44 style5.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
45 style5.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
46 style5.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
47 style5.Borders[BorderType.TopBorder].Color = Color.Black;
48 style5.Borders[BorderType.BottomBorder].Color = Color.Black;
49 style5.Borders[BorderType.LeftBorder].Color = Color.Black;
50 style5.Borders[BorderType.RightBorder].Color = Color.Black;
51
52 //Aspose.Cells.Style style6 = book.Styles[book.Styles.Add()];
53 //style6.ForegroundColor = Color.FromArgb(153, 204, 0);//設置背景色//#DCE6F1
54 //style6.Pattern = Aspose.Cells.BackgroundType.Solid;
55
56 Aspose.Cells.Style style7 = book.Styles[book.Styles.Add()];
57 style7.HorizontalAlignment = TextAlignmentType.Center;
58 style7.Font.Name = "黑體";//文字字體
59 style7.Font.Size = 11;//文字大小
60
61 var c21 = sheet.Cells[1, 0];
62 c21.PutValue("點位");
63 c21.SetStyle(style1);
64
65 var mm=sheet.Cells[7,1];
66 mm.PutValue("中國1");
67 mm.SetStyle(style1);
68
69 var nn = sheet.Cells[7, 2];
70 nn.PutValue("中國2");
71 nn.SetStyle(style1);
72
73 Range ranget1 = sheet.Cells.CreateRange(7, 1, 1, 2);
74 ranget1.Merge();
75 ranget1.RowHeight = 20;
76
77 Cells cells = sheet.Cells;
78 cells.SetColumnWidth(1, 30);//設置列寬
79
80
81 var c22 = sheet.Cells[1, 1];
82 c22.PutValue("類型");
83 c22.SetStyle(style1);
84
85
86 for (int i = 0; i < 31; i++)
87 {
88 var c23 = sheet.Cells[1, i + 2];
89 c23.PutValue(i + 1);
90
91 c23.SetStyle(style1);
92 }
93 sheet.Cells[1, 33].PutValue("最小值"); sheet.Cells[1, 33].SetStyle(style1);
94 sheet.Cells[1, 34].PutValue("最大值"); sheet.Cells[1, 34].SetStyle(style1);
95 sheet.Cells[1, 35].PutValue("平均值"); sheet.Cells[1, 35].SetStyle(style1);
96
97 string year = "";
98 string month = "";
99 int rowcount = 0;
100
101
102
103 //添加樣式
104 //sheet.Cells[m + t + 1, 33].SetStyle(style4);
105 //sheet.Cells[m + t + 1, 34].SetStyle(style4);
106 //sheet.Cells[m + t + 1, 35].SetStyle(style4);
107 //Range ranget = sheet.Cells.CreateRange(t + k + k, 0, 2, 1);//從第幾行第幾列到結束行結束列
108 //ranget.Merge(); //合併單元格
109
110
111 Range range5 = sheet.Cells.CreateRange(0, 0, rowcount * 2 + 2, 36);
112 Aspose.Cells.StyleFlag borderStyle = new Aspose.Cells.StyleFlag();
113 borderStyle.Borders = true; //啓用Borders樣式
114 borderStyle.HorizontalAlignment = true; //啓用水平對齊樣式
115 borderStyle.Font = false;//不使用配置的字體樣式
116 range5.ApplyStyle(style5, borderStyle);
117
118
119
120 var c11 = sheet.Cells[0, 0];
121 string BiaoTi = "**監測有限公司" + year + "年" + month + "月水質監測結果彙總表";
122 c11.PutValue(BiaoTi);
123 c11.SetStyle(style2);
124
125 Range range = sheet.Cells.CreateRange(0, 0, 1, 36);
126 // Cell cell = range[0, 0];
127 range.Merge(); //合併單元格
128 range.RowHeight = 28;
129
130 Range range2 = sheet.Cells.CreateRange(2, 1, rowcount * 2 + 2, 36);
131 range2.RowHeight = 15;//設置行高
132
133 Range range3 = sheet.Cells.CreateRange(1, 0, 2, 36);
134 range3.RowHeight = 17;//設置行高
135
136
137 string XFilename = HttpUtility.UrlEncode("**環境" + year + "年" + month + "月水質監測彙總表.xls", Encoding.UTF8).ToString();
138 Aspose.Cells.SaveOptions ss = new XlsSaveOptions(SaveFormat.Excel97To2003);
139
140 designer.Workbook.Save(this.Response, XFilename, ContentDisposition.Attachment, ss);
141 #endregion
142 }