void GenerateTotalRow(IXlSheet sheet, int firstDataRowIndex)
        {
            // Skip one row before starting to generate the total row.
            sheet.SkipRows(1);

            // Create the total row.
            using (IXlRow row = sheet.CreateRow()) {
                // Set the row height to 28 pixels.
                row.HeightInPixels = 28;
                // Set font characteristics for the row cells.
                row.ApplyFormatting(infoFont.Clone());
                row.Formatting.Font.Bold = true;

                // Skip six successive cells in the total row.
                row.SkipCells(6);

                // Create the "Total" cell.
                using (IXlCell cell = row.CreateCell())
                    cell.Value = "TOTAL";

                // Create the cell that displays the total amount.
                using (IXlCell cell = row.CreateCell()) {
                    // Set the formula to calculate the total amount.
                    cell.SetFormula(string.Format("SUM(H{0}:H{1})", firstDataRowIndex + 1, row.RowIndex - 1));
                    // Set the cell background color.
                    cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(217, 217, 217)));
                }

                // Create the empty cell.
                using (IXlCell cell = row.CreateCell())
                    // Set the cell background color.
                    cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(217, 217, 217)));
            }
        }
        void InitializeFormatting()
        {
            // Specify formatting settings for the even rows.
            evenRowFormatting                  = new XlCellFormatting();
            evenRowFormatting.Font             = new XlFont();
            evenRowFormatting.Font.Name        = "Century Gothic";
            evenRowFormatting.Font.SchemeStyle = XlFontSchemeStyles.None;
            evenRowFormatting.Fill             = XlFill.SolidFill(Color.White);

            // Specify formatting settings for the odd rows.
            oddRowFormatting = new XlCellFormatting();
            oddRowFormatting.CopyFrom(evenRowFormatting);
            oddRowFormatting.Fill = XlFill.SolidFill(Color.FromArgb(242, 242, 242));

            // Specify formatting settings for the header row.
            headerRowFormatting = new XlCellFormatting();
            headerRowFormatting.CopyFrom(evenRowFormatting);
            headerRowFormatting.Font.Bold  = true;
            headerRowFormatting.Font.Color = Color.White;
            headerRowFormatting.Fill       = XlFill.SolidFill(Color.FromArgb(192, 0, 0));
            // Set borders for the header row.
            headerRowFormatting.Border = new XlBorder();
            // Specify the top border and set its color to white.
            headerRowFormatting.Border.TopColor = Color.White;
            // Specify the medium border line style.
            headerRowFormatting.Border.TopLineStyle = XlBorderLineStyle.Medium;
            // Specify the bottom border for the header row.
            // Set the bottom border color to dark gray.
            headerRowFormatting.Border.BottomColor = Color.FromArgb(89, 89, 89);
            // Specify the medium border line style.
            headerRowFormatting.Border.BottomLineStyle = XlBorderLineStyle.Medium;

            // Specify formatting settings for the invoice header.
            panelFont             = new XlFont();
            panelFont.Name        = "Century Gothic";
            panelFont.SchemeStyle = XlFontSchemeStyles.None;
            panelFont.Color       = Color.White;

            // Set font attributes for the row displaying the invoice label and company name.
            titleFont      = panelFont.Clone();
            titleFont.Size = 26;

            // Specify formatting settings for the worksheet range containing the name and contact details of the seller (the "Vader Enterprises" panel).
            leftPanelFormatting = new XlCellFormatting();
            // Set the cell background color to dark gray.
            leftPanelFormatting.Fill         = XlFill.SolidFill(Color.FromArgb(89, 89, 89));
            leftPanelFormatting.Alignment    = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom);
            leftPanelFormatting.NumberFormat = XlNumberFormat.General;
            // Set the right border for this range.
            leftPanelBorder = new XlBorder();
            // Set the right border color to white.
            leftPanelBorder.RightColor = Color.White;
            // Specify the medium border line style.
            leftPanelBorder.RightLineStyle = XlBorderLineStyle.Medium;

            // Specify formatting settings for the worksheet range containing general information about the invoice:
            // its date, reference number and service description (the "Invoice" panel).
            rightPanelFormatting = new XlCellFormatting();
            // Set the cell background color to dark red.
            rightPanelFormatting.Fill         = XlFill.SolidFill(Color.FromArgb(192, 0, 0));
            rightPanelFormatting.Alignment    = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom);
            rightPanelFormatting.NumberFormat = XlNumberFormat.General;

            // Specify formatting settings and font attributes for the worksheet range containing buyer's contact information (the "Bill To" panel).
            infoFormatting = new XlCellFormatting();
            // Set the cell background color to light gray.
            infoFormatting.Fill         = XlFill.SolidFill(Color.FromArgb(217, 217, 217));
            infoFormatting.Alignment    = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom);
            infoFormatting.NumberFormat = XlNumberFormat.General;
            infoFont       = panelFont.Clone();
            infoFont.Color = Color.Black;
        }