欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于NPOI用C#開發(fā)的Excel以及表格設置

 更新時間:2022年02月21日 11:10:43   作者:ezreal_pan  
這篇文章主要為大家詳細介紹了基于NPOI用C#開發(fā)的Excel以及表格設置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了基于NPOI用C#開發(fā)的Excel以及表格設置,供大家參考,具體內容如下

最近在項目中需要導出Excel。在這里做個記錄。在網上查閱了一些資料。將自己最終的代碼分享在這里,以供自己日后查閱,如果能給陌生的你帶來方便,那便更好。

開發(fā)的過程中也遇到了一個問題,設置字體會導致打開Excel時報錯(錯誤:此文件中的某些文本格式可能已經更改,因為它已經超出最多允許的字體數),并且設置失敗。這個問題產生的原因是因為頻繁的創(chuàng)建字體,這個在我參考的代碼中是有問題,我做了些改善。如果你有更優(yōu)的方案,期待向你學習。

public class ExcelDAL
? ? {
? ? ? ? #region 定義單元格常用到樣式的枚舉
? ? ? ? public enum stylexls
? ? ? ? {
? ? ? ? ? ? 頭,
? ? ? ? ? ? 列標題,
? ? ? ? ? ? url,
? ? ? ? ? ? 時間,
? ? ? ? ? ? 數字,
? ? ? ? ? ? 錢,
? ? ? ? ? ? 百分比,
? ? ? ? ? ? 中文大寫,
? ? ? ? ? ? 科學計數法,
? ? ? ? ? ? 默認
? ? ? ? }
? ? ? ? #endregion
? ? ? ? //定義工作薄
? ? ? ? private static IWorkbook m_workbook;?
? ? ? ? //定義sheet表
? ? ? ? private static ISheet m_sheet;
? ? ? ? //表名
? ? ? ? private static List<string> m_sheets=new List<string>();
? ? ? ? private static ICellStyle m_cellStyle;
? ? ? ? private static IDataFormat m_datastyle;
? ? ? ? //字體
? ? ? ? private static IFont m_font20;
? ? ? ? //字體
? ? ? ? private static IFont m_font12;
? ? ? ? //字體
? ? ? ? private static IFont m_font;
? ? ? ? /// <summary>
? ? ? ? /// 創(chuàng)建Excel表
? ? ? ? /// </summary>
? ? ? ? /// <param name="dt">傳遞datatable數據類型</param>
? ? ? ? /// <param name="filePath">文件保存路徑</param>
? ? ? ? /// <param name="sheetName">工作表名</param>
? ? ? ? /// <param name="headerName">表格標題名</param>
? ? ? ? /// <returns></returns>
? ? ? ? public static bool ExportExcel(System.Data.DataTable dt, string filePath, string sheetName,string headerName="考勤表")
? ? ? ? {
? ? ? ? ? ? ICellStyle cellstytle = null;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //如果Excel存在就獲取IWorkbook對象,否則就重新創(chuàng)建
? ? ? ? ? ? ? ? if (File.Exists(filePath))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
? ? ? ? ? ? ? ? ? ? if (filePath.IndexOf(".xlsx") > 0) // 2007版本
? ? ? ? ? ? ? ? ? ? ? ? m_workbook = new XSSFWorkbook(fs);
? ? ? ? ? ? ? ? ? ? else if (filePath.IndexOf(".xls") > 0) // 2003版本
? ? ? ? ? ? ? ? ? ? ? ? m_workbook = new HSSFWorkbook(fs);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //創(chuàng)建一個工作簿
? ? ? ? ? ? ? ? ? ? m_workbook = new HSSFWorkbook();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (m_workbook != null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //獲取所有SheetName
? ? ? ? ? ? ? ? ? ? int count = m_workbook.NumberOfSheets;
? ? ? ? ? ? ? ? ? ? //如果該工作簿不存在表就創(chuàng)建新表
? ? ? ? ? ? ? ? ? ? if (count < 1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? //創(chuàng)建一個 sheet 表
? ? ? ? ? ? ? ? ? ? ? ? m_sheet = m_workbook.CreateSheet(sheetName);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? m_sheets.Clear();
? ? ? ? ? ? ? ? ? ? ? ? for (int i = 0; i < count; i++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? m_sheet = m_workbook.GetSheetAt(i);
? ? ? ? ? ? ? ? ? ? ? ? ? ? m_sheets.Add(m_sheet.SheetName);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? if(m_sheets.Contains(sheetName))
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? m_sheet = m_workbook.CreateSheet(sheetName+System.DateTime.Now.ToString("HH-mm-ss")+"副本");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? m_sheet = m_workbook.CreateSheet(sheetName);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? #region 打印設置
? ? ? ? ? ? ? ? m_sheet.PrintSetup.Copies = 3;
? ? ? ? ? ? ? ? m_sheet.PrintSetup.Landscape = false;
? ? ? ? ? ? ? ? m_sheet.PrintSetup.Scale = 100;
? ? ? ? ? ? ? ? //紙張設置,A4紙
? ? ? ? ? ? ? ? m_sheet.PrintSetup.PaperSize = 9;
? ? ? ? ? ? ? ? //打印網格線
? ? ? ? ? ? ? ? m_sheet.IsPrintGridlines = true;
? ? ? ? ? ? ? ? #endregion
?
? ? ? ? ? ? ? ? #region 設置表頭
? ? ? ? ? ? ? ? m_sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, dt.Columns.Count-1)); //合并單元格
? ? ? ? ? ? ? ? IRow row0 = m_sheet.CreateRow(0); ?//創(chuàng)建一行
? ? ? ? ? ? ? ? row0.Height = 50 * 20;
? ? ? ? ? ? ? ? ICell icelltop0 = row0.CreateCell(0); ?//創(chuàng)建一個單元格
? ? ? ? ? ? ? ? IFont font = m_workbook.CreateFont();
? ? ? ? ? ? ? ? font.FontHeightInPoints = 30;
? ? ? ? ? ? ? ? icelltop0.CellStyle = Getcellstyle(m_workbook, stylexls.頭);
? ? ? ? ? ? ? ? icelltop0.SetCellValue(headerName);
? ? ? ? ? ? ? ? #endregion
?
? ? ? ? ? ? ? ? #region 設置列
? ? ? ? ? ? ? ? IRow rowH = m_sheet.CreateRow(1);
? ? ? ? ? ? ? ? cellstytle= Getcellstyle(m_workbook, stylexls.列標題);
? ? ? ? ? ? ? ? //設置列名
? ? ? ? ? ? ? ? foreach (DataColumn col in dt.Columns)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //創(chuàng)建單元格并設置單元格內容
? ? ? ? ? ? ? ? ? ? rowH.CreateCell(col.Ordinal).SetCellValue(col.Caption);
?
? ? ? ? ? ? ? ? ? ? //設置單元格格式
? ? ? ? ? ? ? ? ? ? rowH.Cells[col.Ordinal].CellStyle = cellstytle;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? #endregion
?
? ? ? ? ? ? ? ? //寫入數據
? ? ? ? ? ? ? ? cellstytle = Getcellstyle(m_workbook, stylexls.默認);
? ? ? ? ? ? ? ? for (int i = 0; i < dt.Rows.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //跳過前兩行,第一行為標題,第二行為列名?
? ? ? ? ? ? ? ? ? ? IRow row = m_sheet.CreateRow(i + 2);
? ? ? ? ? ? ? ? ? ? ICell cell = row.CreateCell(0);
? ? ? ? ? ? ? ? ? ? for (int j = 0; j < dt.Columns.Count; j++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? cell = row.CreateCell(j);
? ? ? ? ? ? ? ? ? ? ? ? cell.SetCellValue(dt.Rows[i][j].ToString());
? ? ? ? ? ? ? ? ? ? ? ? cell.CellStyle = cellstytle;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //獲取當前列的寬度,然后對比本列的長度,取最大值
? ? ? ? ? ? ? ? for (int columnNum = 0; columnNum <= dt.Rows.Count; columnNum++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int columnWidth = m_sheet.GetColumnWidth(columnNum) / 256;
? ? ? ? ? ? ? ? ? ? for (int rowNum = 1; rowNum <= m_sheet.LastRowNum; rowNum++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? IRow currentRow;
? ? ? ? ? ? ? ? ? ? ? ? //當前行未被使用過
? ? ? ? ? ? ? ? ? ? ? ? if (m_sheet.GetRow(rowNum) == null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? currentRow = m_sheet.CreateRow(rowNum);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? currentRow = m_sheet.GetRow(rowNum);
? ? ? ? ? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? ? ? ? ? if (currentRow.GetCell(columnNum) != null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ICell currentCell = currentRow.GetCell(columnNum);
? ? ? ? ? ? ? ? ? ? ? ? ? ? int length = Encoding.Default.GetBytes(currentCell.ToString()).Length;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (columnWidth < length)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? columnWidth = length + 10;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? m_sheet.SetColumnWidth(columnNum, columnWidth * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(0, 30 * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(1, 10 * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(2, 25 * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(3, 25 * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(4, 10 * 256);
? ? ? ? ? ? ? ? ? ? //m_sheet.SetColumnWidth(5, 10 * 256);
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? //創(chuàng)建文件
? ? ? ? ? ? ? ? FileStream file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
?
? ? ? ? ? ? ? ? //創(chuàng)建一個 IO 流
? ? ? ? ? ? ? ? MemoryStream ms = new MemoryStream();
?
? ? ? ? ? ? ? ? //寫入到流
? ? ? ? ? ? ? ? m_workbook.Write(ms);
?
? ? ? ? ? ? ? ? //轉換為字節(jié)數組
? ? ? ? ? ? ? ? byte[] bytes = ms.ToArray();
?
? ? ? ? ? ? ? ? file.Write(bytes, 0, bytes.Length);
? ? ? ? ? ? ? ? file.Flush();
?
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? //釋放資源
? ? ? ? ? ? ? ? bytes = null;
?
? ? ? ? ? ? ? ? ms.Close();
? ? ? ? ? ? ? ? ms.Dispose();
?
? ? ? ? ? ? ? ? file.Close();
? ? ? ? ? ? ? ? file.Dispose();
?
? ? ? ? ? ? ? ? m_workbook.Close();
? ? ? ? ? ? ? ? m_sheet = null;
? ? ? ? ? ? ? ? m_workbook = null;
? ? ? ? ? ? ? ? m_cellStyle = null;
? ? ? ? ? ? ? ? m_datastyle = null;
? ? ? ? ? ? ? ? m_font = null;
? ? ? ? ? ? ? ? m_font12 = null;
? ? ? ? ? ? ? ? m_font20 = null;
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? #region 定義單元格常用到樣式
? ? ? ? static ICellStyle Getcellstyle(IWorkbook wb, stylexls str)
? ? ? ? {
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //CreateFont()不能頻繁創(chuàng)建,會導致打開EXCEL表的時候報如下錯誤:
? ? ? ? ? ? ? ? //此文件中的某些文本格式可能已經更改,因為它已經超出最多允許的字體數。
? ? ? ? ? ? ? ? if (m_font20 == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? m_font20 = wb.CreateFont();
? ? ? ? ? ? ? ? ? ? m_font20.FontHeightInPoints = 20;
? ? ? ? ? ? ? ? ? ? m_font20.FontName = "微軟雅黑";
? ? ? ? ? ? ? ? ? ? m_font20.Boldweight = (short)FontBoldWeight.Bold;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (m_font12 == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? m_font12 = wb.CreateFont();
? ? ? ? ? ? ? ? ? ? m_font12.FontHeightInPoints = 12;
? ? ? ? ? ? ? ? ? ? m_font12.FontName = "微軟雅黑";
? ? ? ? ? ? ? ? ? ? m_font12.Boldweight = (short)FontBoldWeight.Bold;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (m_font == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? m_font = wb.CreateFont();
? ? ? ? ? ? ? ? ? ? m_font.FontName = "微軟雅黑";
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? //if (m_cellStyle == null)
? ? ? ? ? ? ? ? //{
? ? ? ? ? ? ? ? ? ? m_cellStyle = wb.CreateCellStyle();
? ? ? ? ? ? ? ? ? ? //邊框 ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
? ? ? ? ? ? ? ? ? ? m_cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
? ? ? ? ? ? ? ? ? ? m_cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
? ? ? ? ? ? ? ? ? ? m_cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;
? ? ? ? ? ? ? ? ? ? //邊框顏色 ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.BottomBorderColor = HSSFColor.OliveGreen.Blue.Index;
? ? ? ? ? ? ? ? ? ? m_cellStyle.TopBorderColor = HSSFColor.OliveGreen.Blue.Index;
?
? ? ? ? ? ? ? ? ? ? //背景圖形
? ? ? ? ? ? ? ? ? ? //cellStyle.FillBackgroundColor = HSSFColor.OLIVE_GREEN.BLUE.index; ?
? ? ? ? ? ? ? ? ? ? //cellStyle.FillForegroundColor = HSSFColor.OLIVE_GREEN.BLUE.index; ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.FillForegroundColor = HSSFColor.White.Index;
? ? ? ? ? ? ? ? ? ? // cellStyle.FillPattern = FillPatternType.NO_FILL; ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.FillBackgroundColor = HSSFColor.Blue.Index;
?
? ? ? ? ? ? ? ? ? ? //水平對齊 ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
?
? ? ? ? ? ? ? ? ? ? //垂直對齊 ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.VerticalAlignment = VerticalAlignment.Center;
?
? ? ? ? ? ? ? ? ? ? //自動換行 ?
? ? ? ? ? ? ? ? ? ? m_cellStyle.WrapText = false;
?
? ? ? ? ? ? ? ? ? ? //縮進
? ? ? ? ? ? ? ? ? ? //cellStyle.Indention = 0;
? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? //創(chuàng)建格式
? ? ? ? ? ? ? ? if (m_datastyle == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? m_datastyle = wb.CreateDataFormat();
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? //上面基本都是設共公的設置 ?
? ? ? ? ? ? ? ? //下面列出了常用的字段類型 ?
? ? ? ? ? ? ? ? switch (str)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case stylexls.頭:
? ? ? ? ? ? ? ? ? ? ? ? //cellStyle.FillPattern = FillPatternType.LEAST_DOTS; ?
? ? ? ? ? ? ? ? ? ? ? ? //設置為文本格式,也可以為 text,即 dataFormat.GetFormat("text");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = m_datastyle.GetFormat("@");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font20);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.列標題:
? ? ? ? ? ? ? ? ? ? ? ? // cellStyle.FillPattern = FillPatternType.LEAST_DOTS;
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = m_datastyle.GetFormat("@");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font12);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.時間:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = m_datastyle.GetFormat("yyyy/mm/dd");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.數字:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.錢:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = m_datastyle.GetFormat("¥#,##0");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.url:
? ? ? ? ? ? ? ? ? ? ? ? //IFont fontcolorblue = wb.CreateFont();
? ? ? ? ? ? ? ? ? ? ? ? //fontcolorblue.Color = HSSFColor.OliveGreen.Blue.Index;
? ? ? ? ? ? ? ? ? ? ? ? //fontcolorblue.IsItalic = true;//下劃線 ?
? ? ? ? ? ? ? ? ? ? ? ? fontcolorblue.Underline = 1;
? ? ? ? ? ? ? ? ? ? ? ? //fontcolorblue.FontName = "微軟雅黑";
? ? ? ? ? ? ? ? ? ? ? ? //m_cellStyle.SetFont(fontcolorblue);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.百分比:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.中文大寫:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = m_datastyle.GetFormat("[DbNum2][$-804]0");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.科學計數法:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00E+00");
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case stylexls.默認:
? ? ? ? ? ? ? ? ? ? ? ? m_cellStyle.SetFont(m_font);
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return m_cellStyle;
? ? ? ? ? ? }
? ? ? ? ? ? catch
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return m_cellStyle;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? #endregion ?
? ? }

創(chuàng)建的表格的效果如圖所示:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 完成OSS.Http底層HttpClient重構封裝 支持標準庫

    完成OSS.Http底層HttpClient重構封裝 支持標準庫

    OSS.Http項目對于.Net Standard標準庫的支持已經遷移完畢,OSS開源系列兩個最底層的類庫已經具備跨運行時支持的能力。本篇文章主要包含 1. HttpClient的介紹,2. 重構的思路, 3. 容易遇到的問題。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • C#歸并排序的實現方法(遞歸,非遞歸,自然歸并)

    C#歸并排序的實現方法(遞歸,非遞歸,自然歸并)

    C#歸并排序的實現方法(遞歸,非遞歸,自然歸并),需要的朋友可以參考一下
    2013-04-04
  • C#實現改變DataGrid某一行和單元格顏色的方法

    C#實現改變DataGrid某一行和單元格顏色的方法

    這篇文章主要介紹了C#實現改變DataGrid某一行和單元格顏色的方法,主要涉及DataGrid控件的添加與使用、數據源的綁定、單元格與行的獲取等操作。需要的朋友可以參考下
    2014-09-09
  • C# 批處理調用方法

    C# 批處理調用方法

    當批處理和aspx不在同一目錄中時,最好用WorkingDirectory設置啟動的進程的初始目錄為批處理所在目錄,否則如上例中批處理新建的目錄就應在aspx所在目錄中而不是批處理所在目錄了!
    2008-12-12
  • C#使用log4net打日志

    C#使用log4net打日志

    本文主要介紹了C#使用log4net打日志,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • C#實現動態(tài)顯示及動態(tài)移除圖片方法

    C#實現動態(tài)顯示及動態(tài)移除圖片方法

    這篇文章主要介紹了C#實現動態(tài)顯示及動態(tài)移除圖片方法,對于C#的初學者了解圖像操作有一定的幫助,需要的朋友可以參考下
    2014-07-07
  • c#實現ini文件讀寫類分享

    c#實現ini文件讀寫類分享

    c#實現ini文件讀寫類分享,大家參考使用吧
    2013-12-12
  • C#畫圖之餅圖折線圖的實現方法

    C#畫圖之餅圖折線圖的實現方法

    這篇文章主要介紹了C#畫圖之餅圖折線圖的實現方法,以實例形式講述了C#畫圖的完整實現過程,是非常實用的技巧,有不錯的借鑒價值,需要的朋友可以參考下
    2014-09-09
  • C#多線程學習之(三)生產者和消費者用法分析

    C#多線程學習之(三)生產者和消費者用法分析

    這篇文章主要介紹了C#多線程學習之生產者和消費者用法,實例分析了C#中線程沖突的原理與資源分配的技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • C# DataTable常見用法匯總

    C# DataTable常見用法匯總

    這篇文章主要介紹了C# DataTable常見用法,幫助大家更好的理解和學習c#,感興趣的朋友可以了解下
    2020-08-08

最新評論