当前位置:网站首页>[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;
}
边栏推荐
- 【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
- QPushButton 样式使用示例(以及按钮setmenu添加下拉菜单的方法)
- Platform management background and merchant menu resource management: access control design of platform management background
- She said she was tired! So tired! I want to change my career
- LeetCode——226. 翻转二叉树(BFS)
- 手写promise.all
- 二分查找-2
- Can Luo Yonghao succeed in entering the AR field this time?
- 有依赖的背包问题
- Microservice architecture practice: business management background and SSO design, SSO client design
猜你喜欢

14《MySQL 教程》INSERT 插入数据

Leetcode HOT100 (22--- bracket generation)

二分查找法-1

【推荐系统学习】推荐系统架构

Web3 decentralized storage ecological landscape

Treasure and niche CTA animation material website sharing
![[recommendation system learning] technology stack of recommendation system](/img/ff/afc6f4b0997cfcb9e01ffbebf2a872.png)
[recommendation system learning] technology stack of recommendation system

SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System

Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC

Getting started with mongodb
随机推荐
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)
[recommendation system learning] recommendation system architecture
sql中ROUND和TRUNCATE的区别(四舍五入还是截取小数点后几位)
[qt learning notes]qt inter thread data communication and data sharing
力扣每日一题-第28天-566.重塑矩阵
Using redis for user access data statistics hyperloglog and bitmap advanced data types
Redis' 43 serial cannons, try how many you can carry
mysql Add column 失败 因为之前有数据,不是默认null 不行
手写promise.all
Platform management background and merchant menu resource management: merchant registration management design
When I was in the library, I thought of the yuan sharing mode
The high concurrency system is easy to play, and Alibaba's new 100 million level concurrent design quick notes are really fragrant
Vue--vuerouter cache routing component
MySql 导出数据库中的全部表索引
接水面试题
Redis and database data consistency
有依赖的背包问题
Knapsack problem with dependency
背包问题求方案数
Community ownership of NFT trading market is unstoppable