本文主要是介绍C# NPOI 替换Excel模板、插入数据、替换指定内容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
直接看效果:
模板文件:
效果图:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LaserGate.common;
using NPOI.HSSF.UserModel;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;namespace LaserGate
{public partial class FrmNPOITest : Form{public FrmNPOITest(){InitializeComponent();}private void btn_report_Click(object sender, EventArgs e){string newExcelPath = GetNewExcel();string diaFilePath=ShowSaveFileDialog();File.Copy(newExcelPath,diaFilePath,true);}private string GetNewExcel(){try{DataTable dataTable = ClientDAL.WorkPlaneLogDetailsDAL.GetWorkPlaneLogDetails();string modePath = SysConfigInfo.SYSApplicationPath + "\\xmlModel\\" + "ribao_example.xls";if (!File.Exists(modePath)){MessageBox.Show("模板文件不存在:" + modePath);return "";}string filepath = SysConfigInfo.SYSApplicationPath
这篇关于C# NPOI 替换Excel模板、插入数据、替换指定内容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!