当前位置:网站首页>[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;
}
边栏推荐
- Troubleshooting ideas that can solve 80% of faults!
- Uncover the secret of Agora lipsync Technology: driving portraits to simulate human speech through real-time voice
- 二分查找-2
- How about opening an account at Guojin securities? Is it safe?
- MySQL add column failed because there was data before, not null by default
- Leetcode - 226. Retourner l'arbre binaire (bfs)
- 牛客网:设计LRU缓存结构 设计LFU缓存结构
- Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
- 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)
- 二分查找法-1
猜你喜欢
When I was in the library, I thought of the yuan sharing mode
Classical synchronization problem
Fire evacuation and self rescue... This safety production and fire training is full!
Can Luo Yonghao succeed in entering the AR field this time?
Vue--vuerouter cache routing component
A simple membership card management system based on Scala
9、智慧交通项目(2)
Platform management background and merchant menu resource management: merchant registration management design
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
MySQL exports all table indexes in the database
随机推荐
Jouer avec Linux et installer et configurer MySQL facilement
如何将应用加入到deviceidle 白名单?
ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要
VSCode使用 - Remote-SSH 配置说明
The difference between round and truncate in SQL (round or truncate)
Redis and database data consistency
在国金证券开户怎么样?保障安全吗?
Demonstrate to Xiaobai the case of sub database and sub table
MySql 导出数据库中的全部表索引
物联网协议的王者:MQTT
A simple membership card management system based on Scala
MySQL add column failed because there was data before, not null by default
关于FlowUs这一款国民好笔记
二分查找法-1
[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers
[recommendation system learning] recommendation system architecture
map和filter方法对于稀缺数组的处理
Leetcode topic [array] -283- move zero
SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
How does Guosen Securities open an account? Is it safe to open a stock account through the link