I have a Dictionary in my syntax, that I want to write the results of this starting with cell A2 to Excel. At the most it will only be 50 rows. How is this done in epplus?
Asked
Active
Viewed 862 times
0
-
You just want to write 50 rows from Dictionary, right? – Tomato32 Aug 08 '17 at 02:21
-
@Tomato32 - yes, it will always be <= 50 rows – IcyPopTarts Aug 08 '17 at 02:27
-
Oh, you can use the loop for this. Just check Dictionary.Count <=50. Do you need a sample? – Tomato32 Aug 08 '17 at 02:30
-
@Tomato32 - sample would be perfect! – IcyPopTarts Aug 08 '17 at 02:32
1 Answers
0
I use console application and latest EPPlus version. The first, you need to create a file Sample.xlsx in C disk. Hope to help, my friend!
public static void WriteExcel()
{
Dictionary<int, int> dictionary =
new Dictionary<int, int>();
for (int i = 1; i <= 100; i++)
{
dictionary.Add(i, i);
}
var filePath = @"C:/Sample.xlsx";
var file = new FileInfo(filePath);
using (var package = new ExcelPackage(file))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
int k = 0;
foreach (var item in dictionary.Take(50))
{
int cell = k + 2;
worksheet.Cells["A" + cell].Value = item.Value;
k++;
}
package.Save();
}
}

Tomato32
- 2,145
- 1
- 10
- 10