Пример #1
0
 static void GenerateData(List <SalesData> data, string state)
 {
     foreach (string product in products)
     {
         SalesData item = new SalesData(state, product,
                                        Math.Round(random.NextDouble() * 5000 + 3000),
                                        Math.Round(random.NextDouble() * 4000 + 5000),
                                        Math.Round(random.NextDouble() * 6000 + 5500),
                                        Math.Round(random.NextDouble() * 5000 + 4000));
         data.Add(item);
     }
 }
        void GenerateDataRow(IXlSheet sheet, SalesData data)
        {
            // Create the row to display sales information for each sale item.
            using (IXlRow row = sheet.CreateRow()) {
                // Skip the first row in the cell.
                row.SkipCells(1);

                // Create the cell to display the product name and specify its format settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = data.Product;
                    cell.ApplyFormatting(dataRowFormatting);
                    cell.Formatting.Fill = XlFill.SolidFill(XlColor.FromTheme(XlThemeColor.Accent2, 0.8));
                }

                // Create the cell to display sales amount in the first quarter and specify its format settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = data.Q1;
                    cell.ApplyFormatting(dataRowFormatting);
                }

                // Create the cell to display sales amount in the second quarter and specify its format settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = data.Q2;
                    cell.ApplyFormatting(dataRowFormatting);
                }

                // Create the cell to display sales amount in the third quarter and specify its format settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = data.Q3;
                    cell.ApplyFormatting(dataRowFormatting);
                }

                // Create the cell to display sales amount in the fourth quarter and specify its format settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = data.Q4;
                    cell.ApplyFormatting(dataRowFormatting);
                }

                // Create the cell to display annual sales for the product. Use the SUM function to add product sales in each quarter.
                using (IXlCell cell = row.CreateCell()) {
                    cell.SetFormula(XlFunc.Sum(XlCellRange.FromLTRB(2, row.RowIndex, 5, row.RowIndex)));
                    cell.ApplyFormatting(dataRowFormatting);
                    cell.ApplyFormatting(XlFill.SolidFill(XlColor.FromTheme(XlThemeColor.Light2, 0.0)));
                }
            }
        }