当前位置:网站首页>[npoi] C copy sheet template across workbooks to export Excel
[npoi] C copy sheet template across workbooks to export Excel
2022-06-26 17:33:00 【Guistar~~】
Copy across worksheets Sheet Template export Excel
The article introduces
- Only read xlsx Postfix file ,xls You need to add
- Because my company has built a new computer environment excel It will be encrypted automatically , So I can only read an unencrypted one first excel Templates ( You need to apply to the leader , If it is changed, it will be automatically encrypted ), Create another excel, And write the template you read in the process
Reference resources
NPOI Copy template export Excel
Use
Read the template
/// <summary>
/// Read the template
/// </summary>
/// <param name="sheetname"> Pass in a table name </param>
/// <returns></returns>
public static XSSFWorkbook SheetCopytest(string sheetname)
{
// Template address
string templetfilepath = @"C:\Users\10774114\Desktop\SHEET\Ulami Department daily report template .xlsx";// Template Excel
// Generate file address
string tpath = @"C:\Users\10774114\Desktop\SHEET\11.xlsx";// The mediation Excel, Use it as an intermediary to export , Avoid using modules directly Excel And change the format of the module
FileInfo ff = new FileInfo(tpath);
if (ff.Exists)
{
ff.Delete();
}
// Read the template
FileStream fileRead = new FileStream(templetfilepath, FileMode.Open, FileAccess.Read);
XSSFWorkbook XSSFWorkbook = new XSSFWorkbook(fileRead);
XSSFWorkbook book2 = new XSSFWorkbook();
XSSFSheet CPS = (XSSFSheet)XSSFWorkbook.GetSheetAt(1); // Get template sheet
CPS.CopyTo(book2, sheetname, true, true); // Put the template sheet Copy to the target workbook and name
return book2;
}
Generate Excel
public static string DataTableToExcel()
{
string sheetname = "20220601";
XSSFWorkbook book2 = SheetCopytest(sheetname);
using (FileStream file = new FileStream(@"C:\Users\10774114\Desktop\SHEET\11.xlsx", FileMode.Create, FileAccess.Write))
{
book2.Write(file);
file.Close();
}
return sheetname;
}
边栏推荐
- Leetcode topic [array] -283- move zero
- [dynamic planning] Jianzhi offer II 091 Paint the house
- 14 MySQL tutorial insert insert data
- Ndroid development from introduction to mastery Chapter 2: view and ViewGroup
- 在国金证券开户怎么样?保障安全吗?
- 9、智慧交通项目(2)
- 国信证券怎么开户?通过链接办理股票开户安全吗
- 一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
- How does Guosen Securities open an account? Is it safe to open a stock account through the link
- Viewing the task arrangement ability of monorepo tool from turborepo
猜你喜欢
![[C language] static modifies local variables](/img/bf/9084d2e924c3e1e244568562a83d74.jpg)
[C language] static modifies local variables

9、智慧交通项目(2)

Platform management background and merchant menu resource management: access control design of platform management background

Redis OM . Net redis object mapping framework

The high concurrency system is easy to play, and Alibaba's new 100 million level concurrent design quick notes are really fragrant

Leetcode - 226. Retourner l'arbre binaire (bfs)

Play with Linux and easily install and configure MySQL

20: Chapter 3: develop the pass service: 3: get through the redis server in the program; (it only connects with the redis server and does not involve specific business development)

Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation

Programmer's essential toolkit, please collect!
随机推荐
离婚协议中的几个重点
【推荐系统学习】推荐系统的技术栈
Byte interview: two array interview questions, please accept
Which low code platform is more friendly to Xiaobai? Here comes the professional evaluation!
Leetcode daily [2022 - 02 - 16]
Introduction to distributed cache / cache cluster
如何将应用加入到deviceidle 白名单?
Fire evacuation and self rescue... This safety production and fire training is full!
Cloud native 02: Alibaba cloud cloud efficient flow pipeline
What does the equals method compare? Who told you
ACL 2022 | zero sample multilingual extracted text summarization based on neural label search
链游系统开发技术方案设计丨NFT链游系统开发流程及源码
SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
Various types of gypsum PBR multi-channel mapping materials, please collect them quickly!
Microservice architecture practice: user login and account switching design, order query design of the mall
QPushButton 样式使用示例(以及按钮setmenu添加下拉菜单的方法)
padding百分比操作
LeetCode——226. 翻转二叉树(BFS)
[code Capriccio - dynamic planning] t583. Deleting two strings
Synchronized description of concurrency