4

I've started using EPPlus and I was wondering if there is a way to insert a row all in one go instead of having to populate cell by cell.

For example let's say my row number 6 is populated with various number, could I insert all cells in the row by separating the values with something like a comma or a tab? Something like:

ws.Row(6).Value = "12,45,76,12,1";

(I know the syntax above doesn't work, just wondering if there is a way to do something similar). Thank you!

Gep
  • 848
  • 13
  • 29
  • No, how should epplus know that this is not a single value or what happens with `1,"2,3",3`? Populate all cells, very readable and efficient. – Tim Schmelter Mar 10 '16 at 13:16
  • no but im sure you could code up a method to do that for you. something like PopRow("values comma separated starting at 0 index) in could even enhance by parsing in the column index. – Seabizkit Mar 10 '16 at 13:20
  • @TimSchmelter that wouldn't be hard to do. They could add a method called PopRow in the library as suggested by Seabizkit. Of course I can write one myself, but I wanted to make sure it doesn't exist already. – Gep Mar 10 '16 at 13:50

1 Answers1

9

You mean like this:

ws.Cells[6, 1].LoadFromText("12,45,76,12,1");

The Cells object has an overload to specify Row, Column. LoadFromText has 5 overloads so you can get very specific on how it loads the text. The above will give this:

enter image description here

Ernie S
  • 13,902
  • 4
  • 52
  • 79
  • That's exactly it! Thank you @Ernie, I hate to reinvent the wheel even it's a 3 lines method. If you could point me to some good documentation of the EPPlus API that would be really appreciated. I could only find a couple of examples on epplus.codeplex.com – Gep Mar 10 '16 at 15:06
  • @Gep No problem. Just be careful with the `LoadFrom*` methods when it comes to performance and very large datasets - I have actually written my own `for` loops because they can add so much overhead. There isnt much documentation when it comes to Epplus unfortunately, other then reading the source code: http://epplus.codeplex.com/SourceControl/latest#EPPhttp://stackoverflow.com/questions/35917601/how-to-insert-a-row-in-one-go-with-epplus/35919746?noredirect=1#lus/ExcelRangeBase.cs. ExcelRangeBase.cs contains the `LoadFromText` overloads and tags. – Ernie S Mar 10 '16 at 15:11
  • 1
    Sorry, that link is bad due to the formatting: http://epplus.codeplex.com/SourceControl/latest#EPPlus/ExcelRangeBase.cs – Ernie S Mar 10 '16 at 15:20