• 大小: 4.2MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-28
  • 语言: C#
  • 标签: wpf  npoi  

资源简介

使用微软新一代桌面窗口技术WPF做的桌面小应用程序,调用NPOI快速读取导出Excel文件,适合大量Excel快速合并导出的应用情况。

资源截图

代码片段和文件信息

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOILib
{
    public class NPOIExcel
    {
        private IWorkbook m_objExcelWorkBook;
        private ISheet m_objExcelWorkSheet;

        public NPOIExcel()
        {

        }

        public void CreateExcelFile()
        {
            m_objExcelWorkBook = new HSSFWorkbook();//office2003
        }

        public void CreateExcelFile2()
        {
            m_objExcelWorkBook = new XSSFWorkbook();//office2007 会报错
        }

        public void OpenExcelFile(string p_strExcelFileName)
        {
            m_objExcelWorkBook = new HSSFWorkbook(new FileStream(p_strExcelFileName FileMode.Open));//office2003
        }

        public void OpenExcelFile2(string p_strExcelFileName)
        {
            m_objExcelWorkBook = new XSSFWorkbook(new FileStream(p_strExcelFileName FileMode.Open));//office2007
        }

        public void CreateSheet(string p_strSheetName)
        {
            m_objExcelWorkSheet = m_objExcelWorkBook.CreateSheet(p_strSheetName);
            m_objExcelWorkSheet.ForceFormulaRecalculation = true;
        }

        public void SelectSheet(string p_strSheetName)
        {
            m_objExcelWorkSheet = m_objExcelWorkBook.GetSheet(p_strSheetName) as HSSFSheet;//office2003
            m_objExcelWorkSheet.ForceFormulaRecalculation = true;
        }

        public void SelectSheet2(string p_strSheetName)
        {
            m_objExcelWorkSheet = m_objExcelWorkBook.GetSheet(p_strSheetName) as XSSFSheet;//office2007
            m_objExcelWorkSheet.ForceFormulaRecalculation = true;
        }

        public void SetCellString(int p_intRows int p_intColumn string p_strValue)
        {
            if (p_intRows <= 65528)
            {
                m_objExcelWorkSheet.GetRow(p_intRows).GetCell(p_intColumn).SetCellValue(p_strValue);
            }
        }

        public void SetCellDouble(int p_intRows int p_intColumn string p_strValue)
        {
            if (p_intRows <= 65528)
            {
                if (!string.IsNullOrWhiteSpace(p_strValue))
                {
                    double d = Convert.ToDouble(p_strValue);
                    m_objExcelWorkSheet.GetRow(p_intRows).GetCell(p_intColumn).SetCellValue(d);
                }
            }
        }

        public void SetCellDatetime(int p_intRows int p_intColumn string p_strValue)
        {
            if (p_intRows <= 65528)
            {
                if (!string.IsNullOrWhiteSpace(p_strValue))
                {
                    DateTime d = Convert.ToDateTime(p_strValue);
                    m_objExcelWorkSheet.GetRow(p_intRows).GetCell(p_intColumn).SetCellValue(d);
                }
            }
        }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    1679360  2017-11-29 14:57  packages\NPOI.dll

     文件     536064  2017-11-29 14:57  packages\NPOI.OOxml.dll

     文件      91136  2017-11-29 14:57  packages\NPOI.Openxml4Net.dll

     文件    2121728  2017-11-29 14:57  packages\NPOI.OpenxmlFormats.dll

     文件    2254144  2017-11-29 14:57  packages\NPOI.xml

     文件       7680  2018-10-17 15:45  packages\NPOILib.dll

     文件      39936  2018-07-23 16:03  packages\WpfAnimatedGif.1.4.17\lib\net\WpfAnimatedGif.dll

     文件      11262  2018-07-23 16:03  packages\WpfAnimatedGif.1.4.17\lib\net\WpfAnimatedGif.xml

     文件      21595  2018-10-26 11:32  packages\WpfAnimatedGif.1.4.17\WpfAnimatedGif.1.4.17.nupkg

     文件        362  2018-10-26 11:28  wpf1\App.xaml

     文件        300  2018-10-26 11:28  wpf1\App.xaml.cs

     文件    1679360  2017-11-29 14:57  wpf1\bin\Debug\NPOI.dll

     文件     536064  2017-11-29 14:57  wpf1\bin\Debug\NPOI.OOxml.dll

     文件      91136  2017-11-29 14:57  wpf1\bin\Debug\NPOI.Openxml4Net.dll

     文件    2121728  2017-11-29 14:57  wpf1\bin\Debug\NPOI.OpenxmlFormats.dll

     文件       7680  2018-10-26 13:35  wpf1\bin\Debug\NPOILib.dll

     文件      17920  2018-10-26 13:35  wpf1\bin\Debug\NPOILib.pdb

     文件     164864  2018-10-26 14:30  wpf1\bin\Debug\wpf1.exe

     文件      30208  2018-10-26 14:30  wpf1\bin\Debug\wpf1.pdb

     文件      22696  2018-10-26 14:32  wpf1\bin\Debug\wpf1.vshost.exe

     文件      39936  2018-07-23 16:03  wpf1\bin\Debug\WpfAnimatedGif.dll

     文件      11262  2018-07-23 16:03  wpf1\bin\Debug\WpfAnimatedGif.xml

     文件        378  2018-10-26 13:28  wpf1\ExcelFile.cs

     文件      67646  2018-10-24 08:45  wpf1\images\exe.ico

     文件      18178  2018-10-26 14:20  wpf1\images\exit.ico

     文件       3897  2018-10-25 15:54  wpf1\images\loading.gif

     文件      18525  2018-10-26 14:19  wpf1\images\output.ico

     文件      37778  2018-10-26 14:18  wpf1\images\read.ico

     文件         33  2018-10-26 11:33  wpf1\install.txt

     文件       4166  2018-10-26 14:30  wpf1\MainWindow.xaml

............此处省略110个文件信息

评论

共有 条评论