最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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 總燈數
 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 匯總燈數
 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 非匯總燈數
 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#實現WPF項目復制和移動文件夾

    C#實現WPF項目復制和移動文件夾

    這篇文章介紹了C#實現WPF項目復制和移動文件夾的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#調用WinRar執(zhí)行rar、zip壓縮的方法

    C#調用WinRar執(zhí)行rar、zip壓縮的方法

    這篇文章主要介紹了C#調用WinRar執(zhí)行rar、zip壓縮的方法,涉及C#針對winrar的判斷與調用技巧,需要的朋友可以參考下
    2015-05-05
  • C#寫差異文件備份工具的示例

    C#寫差異文件備份工具的示例

    這篇文章主要介紹了C#寫差異文件備份工具的示例,幫助大家利用c#備份,管理文件,感興趣的朋友可以了解下
    2020-10-10
  • C#多態(tài)的三種實現方式(小結)

    C#多態(tài)的三種實現方式(小結)

    這篇文章主要介紹了C#多態(tài)的三種實現方式(小結),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • 使用C#實現自己封裝的Modbus工具類庫

    使用C#實現自己封裝的Modbus工具類庫

    Modbus通訊協議在工控行業(yè)的應用是很多的,并且也是上位機開發(fā)的基本技能之一,所以本文主要為大家介紹了如何使用C#封裝一個Modbus工具類庫,需要的可以參考下
    2024-02-02
  • C#簡單實現文件上傳功能

    C#簡單實現文件上傳功能

    這篇文章主要介紹了C#簡單實現文件上傳功能,利用MVC+EF+LigerUI 實現的upload上傳功能,感興趣的小伙伴們可以參考一下
    2016-03-03
  • C#實現獲取文件大小并進行比較

    C#實現獲取文件大小并進行比較

    這篇文章主要為大家詳細介紹了C#如何實現獲取文件大小進行單位轉換與文件大小比較功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下
    2023-03-03
  • C# NullReferenceException解決案例講解

    C# NullReferenceException解決案例講解

    這篇文章主要介紹了C# NullReferenceException解決案例講解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下
    2021-08-08
  • c#委托與事件(詳解)

    c#委托與事件(詳解)

    本文中,我將通過兩個范例由淺入深地講述什么是委托、為什么要使用委托、事件的由來、.Net Framework中的委托和事件、委托和事件對Observer設計模式的意義,對它們的中間代碼也做了討論
    2021-07-07
  • C# 6.0的屬性(Property)的語法與初始值詳解

    C# 6.0的屬性(Property)的語法與初始值詳解

    下面小編就為大家?guī)硪黄狢# 6.0的屬性(Property)的語法與初始值詳解。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-07-07

最新評論

桃园市| 容城县| 长岭县| 陵川县| 油尖旺区| 同仁县| 涿州市| 越西县| 白玉县| 亚东县| 红安县| 闵行区| 应城市| 克拉玛依市| 鞍山市| 仲巴县| 右玉县| 嘉善县| 屯留县| 大连市| 南陵县| 崇左市| 镇巴县| 佛山市| 陵川县| 介休市| 北安市| 福鼎市| 上思县| 论坛| 封丘县| 宜良县| 栖霞市| 恩施市| 洛扎县| 甘孜县| 临湘市| 新建县| 延庆县| 襄城县| 桐乡市|