Column Import

Is there a method to import an array into a column (as opposed to adding row by row) ?

Hi,

No, but you can easily add this extension method:
 static class ExcelFileHelper
    {
        public static void AddColumn(this XlsFile xls, int startRow, int col, IEnumerable<object> data)
        {
            int r = startRow;
            foreach (var d in data)
            {
                xls.SetCellValue(r, col, d);
                r++;
            }
        }
    }

Then you would call it like:

            XlsFile xls = new XlsFile(1, true);
            xls.AddColumn(1, 3, new object[] { "a", 2, 1 });
            xls.Save(@"r:\testr.xlsx");

In general, we try to implement those methods that are necessary to complete the tasks, but not every variation out there since the number of methods would grow exponentially. (you might also want to add a column of strings, or a row, etc).

But nothing prevents you from defining your own convenience extension methods that make it easier for you to work with FlexCel. In fact, this is the whole idea: FlexCel provides the basics, and you can build from there with the methods you want.

A last note: Please keep in mind that when working with FlexCel, there is 0 advantage on setting an array into a column instead of adding it row by row. I want to emphasize this because people coming from OLE automation has the opposite idea. In OLE automation, OLE automation calls are expensive so you try to minimize them. So a common "trick" to speed up is to fill an array, then set that array into Excel in a single OLE Automation call. But that trick in the FlexCel case makes things worse: You are now spending time (and memory) filling the array, and then when you set the array, FlexCel has to loop over the cells anyway to set the values. We don't have a "divide" with slow and fast methods, everything is C#, and it will be as fast if you do it in an extension method that if we do it in a built in method.

I would prefer to add Row by Row, but my datasource delivers the data in arrays that represent a column and each column can be of a different size - which is why I need to load via column.


Thanks for the information.