亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

WinForm項目開發(fā)中NPOI用法實例解析

 更新時間:2014年08月06日 17:47:54   投稿:shichen2014  
這篇文章主要介紹了WinForm項目開發(fā)中NPOI用法,有一定的實用價值,需要的朋友可以參考下

本文實例展示了WinForm項目開發(fā)中NPOI用法,對于C#初學者有一定的借鑒價值。具體實例如下:

private void ExportMergeExcel()
{
  if (File.Exists(templateXlsPath))
  {
 int i = 4, _recordNo = 1;
 using (FileStream file = new FileStream(templateXlsPath, FileMode.Open, FileAccess.Read))
 {
   HSSFWorkbook _excel = new HSSFWorkbook(file);
   ICellStyle _cellStyle = CreateCellStly(_excel);
   ISheet _sheetBasic = _excel.GetSheet(ExcelReadHelper.sheet_BasicInfo.Replace("$", ""));
   ISheet _sheetStreatLamp = _excel.GetSheet(ExcelReadHelper.sheet_LampMoreLess.Replace("$", ""));
   ISheet _sheetBasicEx = _excel.GetSheet(ExcelReadHelper.sheet_BasicExInfo.Replace("$", ""));
   ISheet _sheetStreatLampEx = _excel.GetSheet(ExcelReadHelper.sheet_LampMoreLessExInfo.Replace("$", ""));

   ISheet _sheetBasicTeamEx = _excel.GetSheet(ExcelReadHelper.sheet_BasicTeamStatistics.Replace("$", ""));
   ISheet _sheetBasicLampTypeEx = _excel.GetSheet(ExcelReadHelper.sheet_BasicTypeStatistics.Replace("$", ""));
   ISheet _sheetStreetLampMLEx = _excel.GetSheet(ExcelReadHelper.sheet_LampMoreLessTeamStatistics.Replace("$", ""));
   ISheet _sheetStreetLampTeamML = _excel.GetSheet(ExcelReadHelper.sheet_LampMoreLessTypeStatistics.Replace("$", ""));

   file.Close();

   FillBasicSheetDb(_sheetBasic, i, _recordNo);
   _recordNo = 1; i = 4;
   FillStreetLampDb(_sheetStreatLamp, i, _recordNo);

   _recordNo = 1; i = 4;
   FillBasicExSheetDb(_sheetBasicEx, i, _recordNo);

   _recordNo = 1; i = 4;
   FillStreetLampExDb(_sheetStreatLampEx, i, _recordNo);

   i = 1; IRow _rowSum = null; int _lampTotalLampCnt = 0, _colLampCnt = 0, _ncolLampCnt = 0; double _lampTotalLampPw = 0, _colLampPw = 0, _ncolLampPw = 0;
   FillBasicTeamExSheetDb(_excel, _rowSum, _sheetBasicTeamEx, _cellStyle, i, _lampTotalLampCnt, _colLampCnt, _ncolLampCnt, _lampTotalLampPw, _colLampPw, _ncolLampPw);

   i = 1; _lampTotalLampCnt = 0; _colLampCnt = 0; _ncolLampCnt = 0; _lampTotalLampPw = 0; _colLampPw = 0; _ncolLampPw = 0;
   FillbasicLampTypeExSheetDb(_excel, _rowSum, _sheetBasicLampTypeEx, _cellStyle, i, _lampTotalLampCnt, _colLampCnt, _ncolLampCnt, _lampTotalLampPw, _colLampPw, _ncolLampPw);

   _lampTotalLampCnt = 0; _lampTotalLampPw = 0; i = 1;
   FillsheetStreetLampMLSheetDb(_excel, _rowSum, _sheetStreetLampMLEx, _cellStyle, i, _lampTotalLampCnt, _lampTotalLampPw);

   _lampTotalLampCnt = 0; _lampTotalLampPw = 0; i = 1;
   FillStreetLampTeamMLSheetDb(_excel, _rowSum, _sheetStreetLampTeamML, _cellStyle, i, _lampTotalLampCnt, _lampTotalLampPw);

   OutPutMergeExcel(_excel);
 }
  }
}
private void FillBasicTeamExSheetDb(HSSFWorkbook _excel, IRow _rowSum, ISheet _sheetBasicTeamEx, ICellStyle _cellStyle, int i, int _lampTotalLampCnt, int _colLampCnt, int _ncolLampCnt, double _lampTotalLampPw, double _colLampPw, double _ncolLampPw)
{
  foreach (ExcelStatistics excelBasicEx in basicTeamExList)
  {
 IRow _row = _sheetBasicTeamEx.CreateRow(i);
 ExcelWriteHelper.CreateStatisticsExcelRow(_row, excelBasicEx, "BasicTeam");
 #region 總燈數(shù)
 int _lTotalLampCnt = 0;
 int.TryParse(excelBasicEx.LampCount, out _lTotalLampCnt);
 _lampTotalLampCnt += _lTotalLampCnt;
 #endregion
 #region 總計算功率(KW)
 double _lTotalLampPw = 0;
 double.TryParse(excelBasicEx.LampPower, out _lTotalLampPw);
 _lampTotalLampPw += _lTotalLampPw;
 #endregion
 #region 匯總燈數(shù)
 int _cLampCount = 0;
 int.TryParse(excelBasicEx.CollectCount, out _cLampCount);
 _colLampCnt += _cLampCount;
 #endregion
 #region 匯總功率(KW)
 double _cLampPw = 0;
 double.TryParse(excelBasicEx.CollectPower, out _cLampPw);
 _colLampPw += _cLampPw;
 #endregion
 #region 非匯總燈數(shù)
 int _ncLampCount = 0;
 int.TryParse(excelBasicEx.NotCollectCount, out _ncLampCount);
 _ncolLampCnt += _ncLampCount;
 #endregion
 #region 非匯總功率(KW)
 double _ncLampPw = 0;
 double.TryParse(excelBasicEx.NotCollectPower, out _ncLampPw);
 _ncolLampPw += _ncLampPw;
 #endregion
 i++;
  }
  _rowSum = _sheetBasicTeamEx.CreateRow(i);
  _rowSum.HeightInPoints = 20;

  _rowSum.CreateCell(0).SetCellValue("合計:");
  _rowSum.CreateCell(1).SetCellValue(_lampTotalLampCnt);
  _rowSum.CreateCell(2).SetCellValue(_lampTotalLampPw);
  _rowSum.CreateCell(3).SetCellValue(_colLampCnt);
  _rowSum.CreateCell(4).SetCellValue(_colLampPw);
  _rowSum.CreateCell(5).SetCellValue(_ncolLampCnt);
  _rowSum.CreateCell(6).SetCellValue(_ncolLampPw);
  SetRowStyle(_rowSum, _cellStyle);
}

定義樣式:

/// <summary>
/// 樣式創(chuàng)建
/// eg:
///private ICellStyle CreateCellStly(HSSFWorkbook _excel)
///{
///  IFont _font = _excel.CreateFont();
///  _font.FontHeightInPoints = 11;
///  _font.FontName = "宋體";
///  _font.Boldweight = (short)FontBoldWeight.Bold;
///  ICellStyle _cellStyle = _excel.CreateCellStyle();
///  //_cellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LightGreen.Index;
///  //_cellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
///  _cellStyle.SetFont(_font);
///  return _cellStyle;
///}
/// 為行設置樣式
/// </summary>
/// <param name="row">IRow</param>
/// <param name="cellStyle">ICellStyle</param>
public static void SetRowStyle(this IRow row, ICellStyle cellStyle)
{
  if (row != null && cellStyle != null)
  {
 for (int u = row.FirstCellNum; u < row.LastCellNum; u++)
 {
   ICell _cell = row.GetCell(u);
   if (_cell != null)
 _cell.CellStyle = cellStyle;
 }
  }
}

相關文章

  • C#實現(xiàn)Winform鼠標拖動窗口大小時設定窗口最小尺寸的方法

    C#實現(xiàn)Winform鼠標拖動窗口大小時設定窗口最小尺寸的方法

    這篇文章主要介紹了C#實現(xiàn)Winform鼠標拖動窗口大小時設定窗口最小尺寸的方法,涉及WinForm改變窗口大小時動態(tài)判斷當前窗口尺寸的相關技巧,非常簡單實用,需要的朋友可以參考下
    2015-11-11
  • C#使用Dictionary<string, string>拆分字符串與記錄log方法

    C#使用Dictionary<string, string>拆分字符串與記錄log方法

    這篇文章介紹了Dictionary<string, string>拆分字符串與記錄log的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • 詳解LINQ入門(上篇)

    詳解LINQ入門(上篇)

    這篇文章主要介紹了詳解LINQ入門(上篇),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • C#調用pyd的方法

    C#調用pyd的方法

    這篇文章主要介紹了C#調用pyd的方法,幫助大家在項目中實現(xiàn)c#代碼與python代碼交互,在C#中調用python,也可以在python中調用C#.
    2020-11-11
  • C#配置文件Section節(jié)點處理總結

    C#配置文件Section節(jié)點處理總結

    這篇文章主要介紹了C#配置文件Section節(jié)點處理總結,針對配置文件Section節(jié)點的處理做了較為詳細的實例總結,需要的朋友可以參考下
    2014-10-10
  • C#委托與事件初探

    C#委托與事件初探

    事件是委托的一種特殊形式,當發(fā)生有意義的事情時,事件處理對象通知過程。接下來通過本文給大家介紹C#委托與事件初探,感興趣的朋友一起學習吧
    2016-02-02
  • Unity實現(xiàn)場景漫游相機

    Unity實現(xiàn)場景漫游相機

    這篇文章主要為大家詳細介紹了Unity實現(xiàn)場景漫游相機,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • C#基于TCP協(xié)議的服務器端和客戶端通信編程的基礎教程

    C#基于TCP協(xié)議的服務器端和客戶端通信編程的基礎教程

    這篇文章主要介紹了C#基于TCP協(xié)議的服務器端和客戶端通信編程的基礎教程,文中講解了C#中TCP編程主要相關的TcpListener類與TcpClient類用法,需要的朋友可以參考下
    2016-04-04
  • C#實現(xiàn)判斷圖形文件格式的方法

    C#實現(xiàn)判斷圖形文件格式的方法

    這篇文章主要介紹了C#實現(xiàn)判斷圖形文件格式的方法,包括常見的擴展名判定及文件內容判定等,非常實用,需要的朋友可以參考下
    2014-09-09
  • 使用C#實現(xiàn)一個簡單的繪圖工具

    使用C#實現(xiàn)一個簡單的繪圖工具

    這篇文章主要為大家詳細介紹了如何使用C#開發(fā)的簡單繪圖工具,可以將簽名簡單繪圖后的效果以圖片的形式導出,有需要的小伙伴可以跟隨小編一起學習一下
    2024-02-02

最新評論