麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

[C#]利用NPOI以模板形式生成EXCEL

2019-11-14 16:45:50
字體:
供稿:網(wǎng)友

在開發(fā)中,有時(shí)候需要生成的Excel樣子比較復(fù)雜,如果用代碼形式去控制EXCEL比較繁瑣費(fèi)時(shí),所以事先做好需要生成EXCEL的模板,再生成的時(shí)候往里面填充數(shù)據(jù)這樣子比較簡(jiǎn)便。

這里利用NPOI(鏈接:https://npoi.codeplex.com/)第三方東西來實(shí)現(xiàn);

代碼如下:

                if (File.Exists(templateXlsPath))                {                    int i = 4, j = 4;                    using (FileStream file = new FileStream(templateXlsPath, FileMode.Open, Fileaccess.Read))                    {                        HSSFWorkbook _excel = new HSSFWorkbook(file);                        ISheet _sheetBasic = _excel.GetSheet(sheet_basicInfo.Replace("$", ""));                        ISheet _sheetStreatLamp = _excel.GetSheet(sheet_LampMoreLess.Replace("$", ""));                        file.Close();                        foreach (ExcelBasicInfo excelBasic in basicInfoList)                        {                            IRow _row = _sheetBasic.CreateRow(i);                            _row.CreateCell(0).SetCellValue(excelBasic.Number);                            _row.CreateCell(1).SetCellValue(excelBasic.TeamName);                            _row.CreateCell(2).SetCellValue(excelBasic.CtrlCabNumber);                            _row.CreateCell(3).SetCellValue(excelBasic.CurrentStatus);                            _row.CreateCell(4).SetCellValue(excelBasic.DevicesUseTime);                            _row.CreateCell(5).SetCellValue(excelBasic.ConfirmLampCount);                            _row.CreateCell(6).SetCellValue(excelBasic.CalculateKW);                            _row.CreateCell(7).SetCellValue(excelBasic.OldDeviceNumber);                            _row.CreateCell(8).SetCellValue(excelBasic.CtrlCabType);                            _row.CreateCell(9).SetCellValue(excelBasic.InstallationSites);                            _row.CreateCell(10).SetCellValue(excelBasic.Section);                            _row.CreateCell(11).SetCellValue(excelBasic.SuperiorPower);                            _row.CreateCell(12).SetCellValue(excelBasic.TableName);                            _row.CreateCell(13).SetCellValue(excelBasic.LampCount);                            _row.CreateCell(14).SetCellValue(excelBasic.LampTypeA);                            _row.CreateCell(15).SetCellValue(excelBasic.LamppowerA);                            _row.CreateCell(16).SetCellValue(excelBasic.LampCountA);                            _row.CreateCell(17).SetCellValue(excelBasic.RunModeA);                            _row.CreateCell(18).SetCellValue(excelBasic.LampTypeB);                            _row.CreateCell(19).SetCellValue(excelBasic.LamppowerB);                            _row.CreateCell(20).SetCellValue(excelBasic.LampCountB);                            _row.CreateCell(21).SetCellValue(excelBasic.RunModeB);                            _row.CreateCell(22).SetCellValue(excelBasic.LampTypeC);                            _row.CreateCell(23).SetCellValue(excelBasic.LamppowerC);                            _row.CreateCell(24).SetCellValue(excelBasic.LampCountC);                            _row.CreateCell(25).SetCellValue(excelBasic.RunModeC);                            _row.CreateCell(26).SetCellValue(excelBasic.LampTypeD);                            _row.CreateCell(27).SetCellValue(excelBasic.LamppowerD);                            _row.CreateCell(28).SetCellValue(excelBasic.LampCountD);                            _row.CreateCell(29).SetCellValue(excelBasic.RunModeD);                            _row.CreateCell(30).SetCellValue(excelBasic.Remark);                            i++;                        }                        foreach (ExcelStreetLamp streatLamp in streatLamps)                        {                            IRow _row = _sheetStreatLamp.CreateRow(j);                            _row.CreateCell(0).SetCellValue(streatLamp.Number);                            _row.CreateCell(1).SetCellValue(streatLamp.TeamName);                            _row.CreateCell(2).SetCellValue(streatLamp.PRojectName);                            _row.CreateCell(3).SetCellValue(streatLamp.CtrlCabNumber);                            _row.CreateCell(4).SetCellValue(streatLamp.ChangeDate);                            _row.CreateCell(5).SetCellValue(streatLamp.MoreLess);                            _row.CreateCell(6).SetCellValue(streatLamp.MoreLessTotalCount);                            _row.CreateCell(7).SetCellValue(streatLamp.LampTypeA);                            _row.CreateCell(8).SetCellValue(streatLamp.LamppowerA);                            _row.CreateCell(9).SetCellValue(streatLamp.LampCountA);                            _row.CreateCell(10).SetCellValue(streatLamp.RunModeA);                            _row.CreateCell(11).SetCellValue(streatLamp.LampTypeB);                            _row.CreateCell(12).SetCellValue(streatLamp.LamppowerB);                            _row.CreateCell(13).SetCellValue(streatLamp.LampCountB);                            _row.CreateCell(14).SetCellValue(streatLamp.RunModeB);                            _row.CreateCell(15).SetCellValue(streatLamp.LampTypeC);                            _row.CreateCell(16).SetCellValue(streatLamp.LamppowerC);                            _row.CreateCell(17).SetCellValue(streatLamp.LampCountC);                            _row.CreateCell(18).SetCellValue(streatLamp.RunModeC);                            _row.CreateCell(19).SetCellValue(streatLamp.LampTypeD);                            _row.CreateCell(20).SetCellValue(streatLamp.LamppowerD);                            _row.CreateCell(21).SetCellValue(streatLamp.LampCountD);                            _row.CreateCell(22).SetCellValue(streatLamp.RunModeD);                            _row.CreateCell(23).SetCellValue(streatLamp.Remark);                            j++;                        }                        SaveFileDialog _savefileDialog = new SaveFileDialog();                        _savefileDialog.Filter = " excel files(*.xls)|*.xls|All files(*.*)|*.*";                        _savefileDialog.RestoreDirectory = true;                        _savefileDialog.FileName = string.Format("上海路燈每月增減表_{0}", DateTime.Now.ToString("yyyyMMddHHmm"));                        if (_savefileDialog.ShowDialog() == DialogResult.OK)                        {                            using (FileStream f = new FileStream(_savefileDialog.FileName.ToString().Trim(), FileMode.Create, FileAccess.ReadWrite))                            {                                _excel.Write(f);                            }                            MessageToolV2.ShowInfo("合并EXCEL成功!");                        }                    }                }

代碼效果

image


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 本站只有精品 | 成人在线视频精品 | 国产成人精品一区二区视频免费 | xxxⅹ96日本护士hd | 91精品国产综合久久婷婷香蕉 | 青青草好吊色 | 成人短视频在线观看免费 | 国产精品热 | 毛片福利| 国产精品久久久久久久久久久久久久久久 | 欧美日本一 | 国产69久久精品成人看 | 日本xxxx视频| 羞羞答答视频 | 羞羞视频免费网站男男 | 黄色网址在线免费播放 | 亚洲精品在线观看网站 | 爽毛片 | 失禁高潮抽搐喷水h | 免费在线观看成人av | 亚洲狠狠入 | 可以免费看的av | 欧美一级黄色免费看 | 91精品成人福利在线播放 | 911精品影院在线观看 | 国产亚洲黑人性受xxxx精品 | 日本一区二区高清不卡 | 悠悠成人资源亚洲一区二区 | 日操操夜操操 | 在线免费观看日韩视频 | 国产一国产一级毛片视频在线 | 久久一本日日摸夜夜添 | 欧美黄色免费视频 | 色999久久久精品人人澡69 | 九色国产 | 九九黄色 | 久色亚洲| 成人免费视频视频在线观看 免费 | 激情小说激情电影 | 黄色影院在线观看视频 | 蜜桃视频在线免费播放 |