使用Aspose.Cells 過程中用過的知識

//新建工作簿
                        Workbook workbook = new Workbook(); //工作簿
                        Worksheet sheet = workbook.Worksheets[0]; //工作表
                        Cells cells = sheet.Cells;//單元格

                        sheet.Protect(ProtectionType.All, "123123", "");//保護工作表
                        sheet.Protection.IsSelectingLockedCellsAllowed = false;//設置只能選擇解鎖單元格
                        sheet.Protection.IsFormattingColumnsAllowed = true;//設置可以調整列
                        sheet.Protection.IsFormattingRowsAllowed = true;//設置可以調整行

                        Style style1 = workbook.Styles[workbook.Styles.Add()];//新增樣式
                        style1.HorizontalAlignment = TextAlignmentType.Center;//文字居中
                        style1.Font.Name = "宋體";//文字字體
                        style1.Font.Size = 12;//文字大小
                        style1.IsLocked = false;//單元格解鎖
                        style1.Font.IsBold = true;//粗體
                        style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//設置背景色
                        style1.Pattern = BackgroundType.Solid; //設置背景樣式
                        style1.IsTextWrapped = true;//單元格內容自動換行
                        style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //應用邊界線 左邊界線
                        style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //應用邊界線 右邊界線
                        style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //應用邊界線 上邊界線
                        style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //應用邊界線 下邊界線

                        cells.Merge(0, 0, 1, 5);//合併單元格
                        cells[0, 0].PutValue("內容");//填寫內容
                        cells[0, 0].SetStyle(style1);//給單元格關聯樣式
                        
                        cells.SetRowHeight(0, 38);//設置行高

                        cells.SetColumnWidth(1, 20);//設置列寬

                        cells[1, 0].Formula = "=AVERAGE(B1:E1)";//給單元格設置計算公式

                        System.IO.MemoryStream ms = workbook.SaveToStream();//生成數據流
                        byte[] bt = ms.ToArray();

                        workbook.Save(@"D:\test.xls");//保存到硬盤
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章