關於Aspose強大的應用--EXECL

來源:互聯網
上載者:User

標籤:style   color   os   io   for   cti   ar   div   

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.FromA#ffff99; ;// 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.FromA#ffff99;//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");       }    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.