コード例 #1
0
        protected void WriteDatasetToExcel(ExcelWorksheet datasetWorksheet, IDataAnalysisProblemData problemData)
        {
            //remark the performance of EPPlus drops dramatically
            //if the data is not written row wise (from left to right) due the internal indices used.
            IDataset dataset         = problemData.Dataset;
            var      variableNames   = dataset.VariableNames.ToList();
            var      doubleVariables = new HashSet <string>(dataset.DoubleVariables);

            for (int col = 1; col <= variableNames.Count; col++)
            {
                datasetWorksheet.Cells[1, col].Value = variableNames[col - 1];
            }

            for (int row = 0; row < dataset.Rows; row++)
            {
                for (int col = 0; col < variableNames.Count; col++)
                {
                    if (doubleVariables.Contains(variableNames[col]))
                    {
                        datasetWorksheet.Cells[row + 2, col + 1].Value = dataset.GetDoubleValue(variableNames[col], row);
                    }
                    else
                    {
                        datasetWorksheet.Cells[row + 2, col + 1].Value = dataset.GetValue(row, col);
                    }
                }
            }
        }