当前位置:网站首页>[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;
}
边栏推荐
- Sandboxed container: container or virtual machine
- Comp281 explanation
- The king of Internet of things protocol: mqtt
- The high concurrency system is easy to play, and Alibaba's new 100 million level concurrent design quick notes are really fragrant
- Platform management background and merchant menu resource management: Design of platform management background data service
- [buuctf.reverse] 126-130
- Viewing the task arrangement ability of monorepo tool from turborepo
- 并发之Synchronized说明
- 在国金证券开户怎么样?开户安全吗?
- What is the difference between digital collections and NFT
猜你喜欢

14《MySQL 教程》INSERT 插入数据

Microservice architecture practice: business management background and SSO design: SSO design

Incomplete line spacing adjustment of formula display in word

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

Cache breakdown! Don't even know how to write code???

Jouer avec Linux et installer et configurer MySQL facilement

Fire evacuation and self rescue... This safety production and fire training is full!

Halcon's region: features of multiple regions (5)

Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!

Demonstrate to Xiaobai the case of sub database and sub table
随机推荐
Army chat -- registration of Registration Center
LeetCode——226. 翻轉二叉樹(BFS)
Microservice architecture practice: user login and account switching design, order query design of the mall
MySQL index
In those years, interview the abused red and black trees
Platform management background and merchant menu resource management: merchant registration management design
Detailed contract quantification system development scheme and technical description of quantitative contract system development
Some explanations for latex CJK
玩轉Linux,輕松安裝配置MySQL
What does the equals method compare? Who told you
Prometeus 2.34.0 新特性
Using redis for user access data statistics hyperloglog and bitmap advanced data types
Teach you to learn dapr - 9 Observability
Various types of gypsum PBR multi-channel mapping materials, please collect them quickly!
Viteconfigure project path alias
直播预告|程序员进击,如何提升研发效能?6月21日晚视频号、B站同步直播,不见不散!
丰富专业化产品线, 江铃福特领睿·极境版上市
Preparing for the Blue Bridge Cup and ccf-csp
二分查找-2
物联网协议的王者:MQTT