原创|产品更新|编辑:龚雪|2014-12-19 10:04:43.000|阅读 300 次
概述:Aspose.Cells for .NET 8.3.1于近日发布。除了添加一些有用的功能和提升之外,其中一大亮点便是新增支持大家期盼已久的ODF 1.2模块。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
【年终大促 巅峰盛慧】FusionCharts XT及套包<8折> 截 止日期2014/12/31
Aspose.Cells for .NET 8.3.1于近日发布。除了添加一些有用的功能和提升之外,其中一大亮点便是新增支持大家期盼已久的ODF 1.2模块。主要更新内容如下:
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"); }
狂欢继续!【年终大促 巅峰盛"慧" 】促销火热进行中 iPhone 6 Plus、 iPhone 6、iPad Air满就送,还不赶快买买买!
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn