Esempio n. 1
0
        static void FillInvoiceTable(Worksheet sheet)
        {
            int currentRowOffset = InitialRowOffset + 1;

            foreach (Ship ship in Invoices)
            {
                sheet[currentRowOffset, InitialColumnOffset].Value = ship.Description;

                Cell cell = sheet[currentRowOffset, InitialColumnOffset + 1];
                cell.Value = ship.Quantity;
                cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

                cell = sheet[currentRowOffset, InitialColumnOffset + 2];
                sheet[currentRowOffset, InitialColumnOffset + 2].Value = ship.Price;
                cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

                cell = sheet[currentRowOffset, InitialColumnOffset + 3];
                cell.NumberFormat         = "0.00%;[Red]-0.00%;;@";
                cell.Value                = CellValue.TryCreateFromObject(ship.Discount);
                cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

                cell         = sheet[currentRowOffset, InitialColumnOffset + 4];
                cell.Formula = string.Format("C{0}*D{0}*(1-E{0})", currentRowOffset + 1);
                cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

                if (currentRowOffset % 2 == 0)
                {
                    sheet.Range.FromLTRB(1, currentRowOffset, 5, currentRowOffset).FillColor = System.Drawing.Color.FromArgb(0xff, 0xF1, 0xF1, 0xF1);
                }
                currentRowOffset++;
            }
        }
        public CellValue TryConvertFromObject(object value)
        {
            if (value is DateTime)
            {
                return(((DateTime)value).ToString("MMM-dd"));
            }
            if (value is Weather)
            {
                return(value.ToString());
            }
            if (value is List <HourlyReport> )
            {
                var hourly = (List <HourlyReport>)value;
                if (hourly.Count == 0)
                {
                    return("Undefined");
                }
                var high = hourly
                           .OrderByDescending(p => p.Temperature)
                           .FirstOrDefault()
                           .Temperature;
                var low = hourly
                          .OrderBy(p => p.Temperature)
                          .FirstOrDefault()
                          .Temperature;
                return(String.Format("High - {0}, Low - {1}", high, low));
            }

            return(CellValue.TryCreateFromObject(value));
        }