導出excel設置樣式(Aspose.Cells)

Aspose.Cells.Style style = xlBook.Styles[xlBook.Styles.Add()];
style1.Pattern = Aspose.Cells.BackgroundType.Solid;//單元格的線:實線
style1.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;//字體居中
style1.Font.Name = "宋體";//文字字體
style1.Font.Size = 8;//文字大小
style1.IsTextWrapped = true;//單元格內容自動換行
style1.ForegroundColor = System.Drawing.Color.FromArgb(50, 205, 50);//設置背景色 能夠參考顏色代碼對照表
style1.Font.IsBold = true;//粗體
Cells.Merge(1, 2, 2, 2);//合併單元格
Cells.SetRowHeight(0, 38);//設置行高
Cells.SetColumnWidth(0, 25);//設置列寬
Cells[0, 1].PutValue("2016年中科核安(標準產品)名稱型號庫存對照表");//添加內容
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;//應用邊界線 下邊界線

//excel數據列 循環列添加樣式
for (int i = 0; i < dgv.ColumnCount-1; i++)
{
Cells[0, i].SetStyle(style1);
}
//excel數據行 循環行添加樣式
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < 10; j++)
{
xlSheet.Cells[i + 1, j].SetStyle (style2);
Cells[i+1, 0].SetStyle(style3);
}
}app

/// <summary>
/// 設置上標
/// </summary>
public static void SetSuperscript(this Cell cell)
{

//Setting the font name to "Times New Roman"
Style style = cell.GetStyle();字體

Font font = style.Font;
font.IsSuperscript = true;
// font.setSuperscript(true);this

cell.SetStyle(style);
}
/// <summary>
/// 設置下標
/// </summary>
public static void SetSubscript(this Cell cell)
{

//Setting the font name to "Times New Roman"
Style style = cell.GetStyle();excel

Font font = style.Font;
font.IsSubscript = true;
// font.setSuperscript(true);ip

cell.SetStyle(style);
}產品

相關文章
相關標籤/搜索