本文介绍了在C#中以编程方式使用epplus创建新的Excel电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我想根据编号动态创建新的Excel电子表格。图像文件夹里面有图像。如果有10张图片,我将在同一个excel工作簿中创建10个excel电子表格,依此类推。我在网上进行了研究,但只能找到如何添加1个特定的Excel电子表格。 这是我的代码: hi all,I want to create new excel spreadsheet dynamically based on the no. of images there are inside my Image folder. If there are 10 images, I will have to create 10 excel spreadsheet in the same excel workbook and so on. I went researched online but only able to find how to add in 1 specific excel spreadsheet.This is my codes:FileInfo newFile = new FileInfo("export.xlsx"); ExcelPackage package = new ExcelPackage(); string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Test")); int count = 0; foreach (string img in filesindirectory) { count++; ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet"); 我想遍历Image文件夹并为文件夹中的每个图像创建新的Excel电子表格。 问题:如何使用epplus动态创建新的excel电子表格? 感谢有人可以指导我,谢谢。I want to loop through the Image folder and create new excel spreadsheet for each image inside the folder.Question: How to create new excel Spreadsheet dynamically using epplus?Appreciate if someone can guide me on this, thanks.推荐答案 我认为这就是你想要的,你可以将计数附加到Sheet名称,如下所示: I think this is what you want, you can append the count to Sheet name like below:int count = 0;foreach (string img in filesindirectory) { count++; ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet " + count); //work on your sheet} 如果你想保留对其他用途的工作表的引用,可以使用数组: If you want to hold reference to the worksheets for other use you can use an array:ExcelWorksheet[] worksheets = new ExcelWorksheet[no. of images]int count = 0;foreach (string img in filesindirectory) { worksheet[count] = package.Workbook.Worksheets.Add("Sheet " + (count + 1)); //work on your sheet count++;} 这篇关于在C#中以编程方式使用epplus创建新的Excel电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 16:27