关于Aspose强大的应用--EXECL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | protected void btnConfirg_Click( object sender, EventArgs e) { genExcel(); } //设置内容文字色 表中有一个蓝色文字列和绿色文字列 protected Aspose.Cells.Style get_content_style(Workbook workbook, Color clrmy) { Aspose.Cells.Style styleTitleBlue = workbook.Styles[workbook.Styles.Add()]; styleTitleBlue.HorizontalAlignment = TextAlignmentType.Center; styleTitleBlue.Font.Name = "Arial" ; styleTitleBlue.Font.Size = 11; styleTitleBlue.IsTextWrapped = true ; styleTitleBlue.Font.Color = clrmy; return styleTitleBlue; } //一般标题样式 protected Aspose.Cells.Style get_title_style(Workbook workbook, Color clrmy) { Aspose.Cells.Style styleTitle = workbook.Styles[workbook.Styles.Add()]; styleTitle.HorizontalAlignment = TextAlignmentType.Center; //标题居中对齐 styleTitle.VerticalAlignment = TextAlignmentType.Bottom; //垂直底对齐 styleTitle.Font.Name = "Arial" ; //字体 styleTitle.Font.Size = 11; //字体大小 styleTitle.IsTextWrapped = true ; //自动换行 styleTitle.Font.Color = clrmy; return styleTitle; } //------------------------------------------------------------------------ // 工作表标题行,第一行样式 //------------------------------------------------------------------------ protected Aspose.Cells.Style set_title_style(Workbook workbook, TextAlignmentType aliCenter) { Aspose.Cells.Style style_top = workbook.Styles[workbook.Styles.Add()]; style_top.HorizontalAlignment = aliCenter; //标题居中对齐 style_top.Font.Size = 18; //字体大小 style_top.Font.Color = System.Drawing.Color.Blue; style_top.Font.IsBold = true ; return style_top; } protected void genExcel() { Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; Cells cells = sheet.Cells; //居中对齐样式 Aspose.Cells.Style style_H_c = workbook.Styles[workbook.Styles.Add()]; style_H_c.HorizontalAlignment = TextAlignmentType.Center; //标题居中对齐 //------------------------------------------------------------------------ // 字段表头黄背前红标题样式 //------------------------------------------------------------------------ Aspose.Cells.Style styleTitleYR = workbook.Styles[workbook.Styles.Add()]; styleTitleYR.HorizontalAlignment = TextAlignmentType.Center; styleTitleYR.VerticalAlignment = TextAlignmentType.Bottom; styleTitleYR.Font.Name = "Arial" ; styleTitleYR.Font.IsBold = true ; //加粗 styleTitleYR.Font.Size = 11; styleTitleYR.IsTextWrapped = true ; styleTitleYR.Font.Color = Color.Red; //字色为红 styleTitleYR.ForegroundColor = Color.FromArgb(255, 255, 153); ; // Color.Yellow; styleTitleYR.Pattern = BackgroundType.Solid; //------------------------------------------------------------------------ // 字段内容黄背前红标题样式 //------------------------------------------------------------------------ Aspose.Cells.Style styleTitleYR_nr = workbook.Styles[workbook.Styles.Add()]; styleTitleYR_nr.HorizontalAlignment = TextAlignmentType.Center; styleTitleYR_nr.Font.Name = "Arial" ; styleTitleYR_nr.Font.Size = 11; styleTitleYR_nr.IsTextWrapped = true ; styleTitleYR_nr.Font.Color = Color.Black; styleTitleYR_nr.ForegroundColor = Color.FromArgb(255, 255, 153); //Color.Yellow; styleTitleYR_nr.Pattern = BackgroundType.Solid; //行高列宽设置------------------------------------- cells.SetRowHeight(0, 23.25); cells.SetRowHeight(1, 45); cells.SetColumnWidth(0, 16.29); cells.SetColumnWidth(1, 10.43); cells.SetColumnWidth(2, 28.43); cells.SetColumnWidth(3, 7); cells.SetColumnWidth(4, 9.43); cells.SetColumnWidth(5, 17.71); cells.SetColumnWidth(6, 18); cells.SetColumnWidth(7, 7.86); cells.SetColumnWidth(8, 15.43); cells.SetColumnWidth(9, 15.43); cells.SetColumnWidth(10, 13.43); cells.SetColumnWidth(11, 43.71); cells.SetColumnWidth(12, 15.29); cells.SetColumnWidth(13, 28.86); cells.SetColumnWidth(14, 13.57); cells.SetColumnWidth(15, 17.43); cells.SetColumnWidth(16, 15.14); cells.SetColumnWidth(17, 6.57); cells.SetColumnWidth(18, 18.14); //表头样式设置------------------------------------- cells[0, 0].PutValue( "Yellow column filled by garment factory" ); cells[0, 0].SetStyle(set_title_style(workbook, TextAlignmentType.Left)); cells[0, 5].PutValue( "Date" ); cells[0, 5].SetStyle(set_title_style(workbook, TextAlignmentType.Center)); cells[0, 6].PutValue( "10/20/2013" ); cells[0, 6].SetStyle(set_title_style(workbook, TextAlignmentType.Center)); cells[1, 0].PutValue( "Garment Style" ); cells[1, 0].SetStyle(styleTitleYR); cells[1, 12].SetStyle(styleTitleYR); cells[1, 12].PutValue( "Handover date" ); cells[1, 13].SetStyle(styleTitleYR); cells[1, 13].PutValue( "ship mode" ); cells[1, 14].SetStyle(styleTitleYR); cells[1, 14].PutValue( "ship mode cfm by" ); cells[1, 15].SetStyle(styleTitleYR); cells[1, 15].PutValue( "AIR APPD BY (PRODUCTION TEAM)" ); cells[1, 1].PutValue( "Factory#" ); cells[1, 2].PutValue( "GV PO" ); cells[1, 3].PutValue( "Supplier#" ); cells[1, 4].PutValue( "Supplier PI#" ); cells[1, 5].PutValue( "Trims ref#" ); cells[1, 6].PutValue( "Color-Size" ); cells[1, 7].PutValue( "Qty#" ); cells[1, 8].PutValue( "Read date" ); cells[1, 9].PutValue( "P/I Confirm Date" ); cells[1, 10].PutValue( "Remarks" ); cells[1, 11].PutValue( "Estimate Weight(kgs)" ); cells[1, 16].PutValue( "Our Ref No." ); cells[1, 17].PutValue( "Index" ); cells[1, 18].PutValue( "Wight" ); Range title_normal = sheet.Cells.CreateRange(1, 1, 1, 11); //普通表头标题 title_normal.SetStyle(get_title_style(workbook, Color.Black)); Range title_normal_end = sheet.Cells.CreateRange(1, 16, 1, 3); //普通表头标题 title_normal_end.SetStyle(get_title_style(workbook, Color.Black)); Range title_content_b = sheet.Cells.CreateRange(2, 8, 65535, 1); //蓝色内容 title_content_b.SetStyle(get_content_style(workbook, Color.Blue)); //styleTitleBlue); Range title_contne_g = sheet.Cells.CreateRange(2, 10, 65535, 1); //绿色内容 title_contne_g.SetStyle(get_content_style(workbook, Color.Green)); //styleTitleGreen); cells[1, 10].SetStyle(get_title_style(workbook, Color.Green)); cells[1, 8].SetStyle(get_title_style(workbook, Color.Blue)); //列背景色设置-------------------------------------- Range range = sheet.Cells.CreateRange(2, 0, 65535, 1); Range range1 = sheet.Cells.CreateRange(2, 12, 65535, 4); range.SetStyle(styleTitleYR_nr); range1.SetStyle(styleTitleYR_nr); //内容设置------------------------------------------ for ( int i = 0; i < 10; i++) { cells[i + 2, 1].PutValue(i.ToString(), true ); cells[i + 2, 2].PutValue(i.ToString(), true ); cells[i + 2, 3].PutValue(i.ToString(), true ); cells[i + 2, 4].PutValue(i.ToString(), true ); cells[i + 2, 5].PutValue(i.ToString(), true ); cells[i + 2, 7].PutValue(i.ToString(), true ); cells[i + 2, 11].PutValue(i.ToString(), true ); cells[i + 2, 16].PutValue(i.ToString(), true ); cells[i + 2, 17].PutValue((i + 1).ToString(), true ); cells[i + 2, 18].PutValue(i.ToString(), true ); cells[i + 2, 1].SetStyle(style_H_c); cells[i + 2, 2].SetStyle(style_H_c); cells[i + 2, 3].SetStyle(style_H_c); cells[i + 2, 4].SetStyle(style_H_c); cells[i + 2, 5].SetStyle(style_H_c); cells[i + 2, 7].SetStyle(style_H_c); cells[i + 2, 11].SetStyle(style_H_c); cells[i + 2, 16].SetStyle(style_H_c); cells[i + 2, 17].SetStyle(style_H_c); cells[i + 2, 18].SetStyle(style_H_c); } System.IO.MemoryStream ms = workbook.SaveToStream(); byte [] bt = ms.ToArray(); workbook.Save( @"d:\test.xls" ); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步