public override void Start()
        {
            base.Start();

            IStack stack = Platform.Current.Create <IStack>();

            ILabel lblLabel = Platform.Current.Create <ILabel>();

            lblLabel.Text   = "Visit";
            lblLabel.Height = 30;
            stack.Children.Add(lblLabel);

            IHyperLink hplUrl = Platform.Current.Create <IHyperLink>();

            hplUrl.Text = "http://www.okhosting.com";
            hplUrl.Uri  = new Uri("http://www.okhosting.com");
            hplUrl.Name = "okhosting.com";
            stack.Children.Add(hplUrl);

            IButton cmdClose = Platform.Current.Create <IButton>();

            cmdClose.Text   = "Close";
            cmdClose.Click += CmdClose_Click;
            stack.Children.Add(cmdClose);

            Platform.Current.Page.Title   = "Test label";
            Platform.Current.Page.Content = stack;
        }
        /// <summary>
        /// Start this instance.
        /// <para xml:lang="es">
        /// Inicia esta instancia de objeto.
        /// </para>
        /// </summary>
        public override void Start()
        {
            base.Start();

            // Create an Stack
            IStack stack = Platform.Current.Create <IStack>();

            // Creates an Label with text and a specific size and adds it to the stack.
            ILabel lblLabel = Platform.Current.Create <ILabel>();

            lblLabel.Text   = "Visit";
            lblLabel.Height = 30;
            stack.Children.Add(lblLabel);

            // Creates an HyperLink with an text, Url and name specific and adds it to the Stack
            IHyperLink hplUrl = Platform.Current.Create <IHyperLink>();

            hplUrl.Text = "http://www.okhosting.com";
            hplUrl.Uri  = new Uri("http://www.okhosting.com");
            hplUrl.Name = "okhosting.com";
            stack.Children.Add(hplUrl);

            // Creates the Button cmdClose with text specific, with the event also click and adds it to the stack.
            IButton cmdClose = Platform.Current.Create <IButton>();

            cmdClose.Text   = "Close";
            cmdClose.Click += CmdClose_Click;
            stack.Children.Add(cmdClose);

            // Establishes the content and title of the page
            Platform.Current.Page.Title   = "Test label";
            Platform.Current.Page.Content = stack;
        }
Exemple #3
0
        private static void InsertText(IWorksheet worksheet, string cellId, string content, string hyperLink = null)
        {
            var cell = worksheet.Range[cellId];

            if (string.IsNullOrEmpty(hyperLink) == false)
            {
                IHyperLink hyperlink = worksheet.HyperLinks.Add(cell);
                hyperlink.Type          = ExcelHyperLinkType.Url;
                hyperlink.Address       = hyperLink;
                hyperlink.ScreenTip     = hyperLink;
                hyperlink.TextToDisplay = content;
            }
            else
            {
                cell.Text = content;
            }
            cell.WrapText = true;
            //cell.Borders.Value = ExcelLineStyle.al
        }
        protected void EmployeesGrid_ServerExcelColumnTemplateInfo(object arg1, object arg2)
        {
            IRange range = (IRange)arg1;
            object templatevalue;

            foreach (var ds in arg2.GetType().GetProperties())
            {
                if (range.Value.Contains(ds.Name))
                {
                    templatevalue = arg2.GetType().GetProperty(ds.Name).GetValue(arg2, null);
                    range.Value   = range.Value.Replace(ds.Name, templatevalue.ToString());
                    var        regex     = new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")", RegexOptions.IgnoreCase);
                    var        urls      = regex.Matches(range.Value.ToString()).OfType <Match>().Select(m => m.Groups["href"].Value).SingleOrDefault();
                    IHyperLink hyperlink = (range.Parent as Syncfusion.XlsIO.Implementation.WorksheetImpl).HyperLinks.Add(range);
                    hyperlink.Type          = ExcelHyperLinkType.Url;
                    hyperlink.TextToDisplay = templatevalue.ToString();
                    hyperlink.Address       = urls;
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            // The instantiation process consists of two steps.

            // Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            // Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            // Check if user opts for Excel 2007
            if (this.rdButtonxlsx.IsChecked.Value)
            {
                application.DefaultVersion = ExcelVersion.Excel2007;
                color1 = System.Drawing.Color.FromArgb(255, 255, 230);
            }
            else if (this.rdButtonexcel2010.IsChecked.Value)
            {
                application.DefaultVersion = ExcelVersion.Excel2010;
                color1 = System.Drawing.Color.FromArgb(255, 255, 230);
            }
            else if (this.rdButtonexcel2013.IsChecked.Value)
            {
                application.DefaultVersion = ExcelVersion.Excel2013;
                color1 = System.Drawing.Color.FromArgb(255, 255, 230);
            }
            else
            {
                color1 = System.Drawing.Color.FromArgb(255, 255, 204);
            }

            // A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
            // Workbook created with two worksheets
            IWorkbook workbook = application.Workbooks.Create(2);
            // The first worksheet object in the worksheets collection is accessed.
            // (0 based index)
            IWorksheet sheet2 = workbook.Worksheets[1];

            //Assigning the array content to cells
            // by passing row and column position
            for (int i = 0; i < onlinePayments.Length; i++)
            {
                sheet2.SetValue(i + 1, 1, onlinePayments[i]);
            }

            // The first worksheet object in the worksheets collection is accessed.
            IWorksheet sheet = workbook.Worksheets[0];

#if NETCORE
            sheet.Pictures.AddPicture(2, 3, @"..\..\..\..\..\..\..\Common\Images\XlsIO\contact_sales.gif");
#else
            sheet.Pictures.AddPicture(2, 3, @"..\..\..\..\..\..\Common\Images\XlsIO\contact_sales.gif");
#endif
            sheet[4, 3].Text = "Phone";
            sheet[4, 3].CellStyle.Font.Bold = true;
            sheet[5, 3].Text  = "Toll Free";
            sheet[5, 5].Text  = "1-888-9DOTNET";
            sheet[6, 5].Text  = "1-888-936-8638";
            sheet[7, 5].Text  = "1-919-481-1974";
            sheet[8, 3].Text  = "Fax";
            sheet[8, 5].Text  = "1-919-573-0306";
            sheet[9, 3].Text  = "Email";
            sheet[10, 3].Text = "Sales";
            //Creating the hyperlink in the 10th column and
            //5th row of the sheet
            IHyperLink link = sheet.HyperLinks.Add(sheet[10, 5]);
            link.Type    = ExcelHyperLinkType.Url;
            link.Address = "mailto:[email protected]";

            sheet[12, 3].Text = "Please fill out all required fields.";
            sheet[14, 5].Text = "First Name*";
            sheet[14, 5].CellStyle.Font.Bold = true;
            sheet[14, 8].Text = "Last Name*";
            sheet[14, 8].CellStyle.Font.Bold = true;

            //Create textbox for respective field
            //textbox to get First Name
            ITextBoxShape textBoxShape = sheet.TextBoxes.AddTextBox(15, 5, 23, 190);
            textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
            textBoxShape.Fill.ForeColor = color1;

            //textbox to get Last Name
            textBoxShape = sheet.TextBoxes.AddTextBox(15, 8, 23, 195);
            textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
            textBoxShape.Fill.ForeColor = color1;

            sheet[17, 3].Text           = "Company*";
            textBoxShape                = sheet.TextBoxes.AddTextBox(17, 5, 23, 385);
            textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
            textBoxShape.Fill.ForeColor = color1;
            sheet[19, 3].Text           = "Phone*";
            textBoxShape                = sheet.TextBoxes.AddTextBox(19, 5, 23, 385);
            textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
            textBoxShape.Fill.ForeColor = color1;
            sheet[21, 3].Text           = "Email*";
            textBoxShape                = sheet.TextBoxes.AddTextBox(21, 5, 23, 385);
            textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
            textBoxShape.Fill.ForeColor = color1;
            sheet[23, 3].Text           = "Website";
            textBoxShape                = sheet.TextBoxes.AddTextBox(23, 5, 23, 385);

            ICheckBoxShape chkBoxProducts = sheet.CheckBoxes.AddCheckBox(25, 5, 20, 75);
            chkBoxProducts.Text = "";
            sheet[25, 3].Text   = "Multiple products?";

            sheet[27, 3, 28, 3].Merge();
            sheet[27, 3].Text = "Product(s)*";
            sheet[27, 3].MergeArea.CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
            // Create a checkbox for each product
            ICheckBoxShape chkBoxProduct;
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 5, 20, 75);
            chkBoxProduct.Text           = "Studio";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 6, 20, 75);
            chkBoxProduct.Text           = "Calculate";
            chkBoxProduct.IsSizeWithCell = true;
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 7, 20, 75);
            chkBoxProduct.Text           = "Chart";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 8, 20, 75);
            chkBoxProduct.Text           = "Diagram";
            chkBoxProduct.IsSizeWithCell = true;
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 9, 20, 75);
            chkBoxProduct.Text           = "Edit";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 10, 20, 75);
            chkBoxProduct.Text           = "XlsIO";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 5, 20, 75);
            chkBoxProduct.Text           = "Grid";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 6, 20, 75);
            chkBoxProduct.Text           = "Grouping";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 7, 20, 75);
            chkBoxProduct.Text           = "HTMLUI";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 8, 20, 75);
            chkBoxProduct.Text           = "PDF";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 9, 20, 75);
            chkBoxProduct.Text           = "Tools";
            chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 10, 20, 75);
            chkBoxProduct.Text           = "DocIO";
            chkBoxProducts.CheckState    = ExcelCheckState.Mixed;

            //generate the link to linked cell property and formula
            GenerateFormula(excelEngine);


            sheet[30, 3].Text = "Selected Products Count";
            //counts the selected product
            sheet[30, 5].Formula = "Sum(AA2:AA13)";
            //align the cell content
            sheet[30, 5].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;
            //create the textbox for additional information
            sheet[35, 3].Text = "Additional Information";
            textBoxShape      = sheet.TextBoxes.AddTextBox(32, 5, 150, 385);


            if (!this.rdButtonxls.IsChecked.Value)
            {
                sheet[43, 3].Text = "Online Payment";

                // Create combobox
                IComboBoxShape comboBox1 = sheet.ComboBoxes.AddComboBox(43, 5, 20, 100);

                // Assign range to display in dropdown list
                comboBox1.ListFillRange = sheet2["A1:A2"];

                // select 1st item from the list
                comboBox1.SelectedIndex = 1;

                sheet[46, 3].Text = "Card Type";
                IOptionButtonShape optionButton1 = sheet.OptionButtons.AddOptionButton(46, 5);
                optionButton1.Text       = "American Express";
                optionButton1.CheckState = ExcelCheckState.Checked;

                optionButton1      = sheet.OptionButtons.AddOptionButton(46, 7);
                optionButton1.Text = "Master Card";

                optionButton1      = sheet.OptionButtons.AddOptionButton(46, 9);
                optionButton1.Text = "Visa";
            }
            //column alignment
            sheet.Columns[0].AutofitColumns();
            sheet.Columns[3].ColumnWidth = 12;
            sheet.Columns[4].ColumnWidth = 10;
            sheet.Columns[5].ColumnWidth = 10;
            sheet.IsGridLinesVisible     = false;
            // Assign the filename depends upon the version
            if ((this.rdButtonxlsx.IsChecked.Value) || (this.rdButtonexcel2010.IsChecked.Value) || (this.rdButtonexcel2013.IsChecked.Value))
            {
                fileName = "FormControls.xlsx";
            }
            else
            {
                fileName = "FormControls.xls";
            }

            try
            {
                // Save the file
                workbook.SaveAs(fileName);
                //closes the workbook
                workbook.Close();
                excelEngine.Dispose();

                //Message box confirmation to view the created spreadsheet.
                if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
                                    MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo(fileName)
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        Process.Start(fileName);
#endif

                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Excel 2007 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch
            {
                MessageBox.Show("Sorry, Excel can't open two workbooks with the same name at the same time.\nPlease close the workbook and try again.", "File is already open", MessageBoxButton.OK);
            }
        }
Exemple #6
0
 public static void ExpandUri(this IHyperLink href, UriString requestUri, UriString pathBase)
 {
     DoExpandUri(href.Href, requestUri, pathBase);
 }
        /// <summary>
        /// Create the Excel document with form controls
        /// </summary>
        /// <returns>Return the created excel document as stream</returns>
        public MemoryStream FormControlsXlsIO(string version)
        {
            onlinePayments = new string[] { "Credit Card", "Net Banking" };
            //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Step 2 : Instantiate the excel application object
                IApplication application = excelEngine.Excel;

                //Check if user opts for XLSX
                if (version == "XLSX")
                {
                    application.DefaultVersion = ExcelVersion.Excel2016;
                    color1 = Color.FromArgb(255, 255, 230);
                }
                //Check if user opts for XLS
                else
                {
                    color1 = Color.FromArgb(255, 255, 204);
                }

                //A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]
                //Workbook created with two worksheets
                IWorkbook workbook = application.Workbooks.Create(2);

                //The first worksheet object in the worksheets collection is accessed.
                //(0 based index)
                IWorksheet sheet2 = workbook.Worksheets[1];

                //Assigning the array content to cells
                //by passing row and column position
                for (int i = 0; i < onlinePayments.Length; i++)
                {
                    sheet2.SetValue(i + 1, 1, onlinePayments[i]);
                }

                //The first worksheet object in the worksheets collection is accessed.
                IWorksheet sheet = workbook.Worksheets[0];

                FileStream imageStream = new FileStream(ResolveApplicationImagePath("contact_sales.gif"), FileMode.Open, FileAccess.Read);
                sheet.Pictures.AddPicture(2, 3, imageStream);

                sheet[4, 3].Text = "Phone";
                sheet[4, 3].CellStyle.Font.Bold = true;
                sheet[5, 3].Text  = "Toll Free";
                sheet[5, 5].Text  = "1-888-9DOTNET";
                sheet[6, 5].Text  = "1-888-936-8638";
                sheet[7, 5].Text  = "1-919-481-1974";
                sheet[8, 3].Text  = "Fax";
                sheet[8, 5].Text  = "1-919-573-0306";
                sheet[9, 3].Text  = "Email";
                sheet[10, 3].Text = "Sales";

                //Creating the hyperlink in the 10th column and
                //5th row of the sheet
                IHyperLink link = sheet.HyperLinks.Add(sheet[10, 5]);
                link.Type    = ExcelHyperLinkType.Url;
                link.Address = "mailto:[email protected]";

                sheet[12, 3].Text = "Please fill out all required fields.";
                sheet[14, 5].Text = "First Name*";
                sheet[14, 5].CellStyle.Font.Bold = true;
                sheet[14, 8].Text = "Last Name*";
                sheet[14, 8].CellStyle.Font.Bold = true;

                //Create textbox for respective field
                //textbox to get First Name
                ITextBoxShape textBoxShape = sheet.TextBoxes.AddTextBox(15, 5, 23, 190);
                textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
                textBoxShape.Fill.ForeColor = color1;

                //textbox to get Last Name
                textBoxShape = sheet.TextBoxes.AddTextBox(15, 8, 23, 195);
                textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
                textBoxShape.Fill.ForeColor = color1;

                sheet[17, 3].Text           = "Company*";
                textBoxShape                = sheet.TextBoxes.AddTextBox(17, 5, 23, 385);
                textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
                textBoxShape.Fill.ForeColor = color1;
                sheet[19, 3].Text           = "Phone*";
                textBoxShape                = sheet.TextBoxes.AddTextBox(19, 5, 23, 385);
                textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
                textBoxShape.Fill.ForeColor = color1;
                sheet[21, 3].Text           = "Email*";
                textBoxShape                = sheet.TextBoxes.AddTextBox(21, 5, 23, 385);
                textBoxShape.Fill.FillType  = ExcelFillType.SolidColor;
                textBoxShape.Fill.ForeColor = color1;
                sheet[23, 3].Text           = "Website";
                textBoxShape                = sheet.TextBoxes.AddTextBox(23, 5, 23, 385);

                ICheckBoxShape chkBoxProducts = sheet.CheckBoxes.AddCheckBox(25, 5, 20, 75);
                chkBoxProducts.Text = "";

                sheet[25, 3].Text = "Multiple products?";

                sheet[27, 3, 28, 3].Merge();
                sheet[27, 3].Text = "Product(s)*";
                sheet[27, 3].MergeArea.CellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;

                //Create a checkbox for each product
                ICheckBoxShape chkBoxProduct;
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 5, 20, 75);
                chkBoxProduct.Text           = "Studio";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 6, 20, 75);
                chkBoxProduct.Text           = "Calculate";
                chkBoxProduct.IsSizeWithCell = true;
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 7, 20, 75);
                chkBoxProduct.Text           = "Chart";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 8, 20, 75);
                chkBoxProduct.Text           = "Diagram";
                chkBoxProduct.IsSizeWithCell = true;
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 9, 20, 75);
                chkBoxProduct.Text           = "Edit";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(27, 10, 20, 75);
                chkBoxProduct.Text           = "XlsIO";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 5, 20, 75);
                chkBoxProduct.Text           = "Grid";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 6, 20, 75);
                chkBoxProduct.Text           = "Grouping";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 7, 20, 75);
                chkBoxProduct.Text           = "HTMLUI";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 8, 20, 75);
                chkBoxProduct.Text           = "PDF";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 9, 20, 75);
                chkBoxProduct.Text           = "Tools";
                chkBoxProduct                = sheet.CheckBoxes.AddCheckBox(28, 10, 20, 75);
                chkBoxProduct.Text           = "DocIO";
                chkBoxProducts.CheckState    = ExcelCheckState.Mixed;

                //generate the link to linked cell property and formula
                GenerateFormula(excelEngine);

                sheet[30, 3].Text = "Selected Products Count";

                //counts the selected product
                sheet[30, 5].Formula = "Sum(AA2:AA13)";

                //align the cell content
                sheet[30, 5].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;

                //create the textbox for additional information
                sheet[35, 3].Text = "Additional Information";
                textBoxShape      = sheet.TextBoxes.AddTextBox(32, 5, 150, 385);

                if (!(version == "XLS"))
                {
                    sheet[43, 3].Text = "Online Payment";

                    //Create combobox
                    IComboBoxShape comboBox1 = sheet.ComboBoxes.AddComboBox(43, 5, 20, 100);

                    //Assign range to display in dropdown list
                    comboBox1.ListFillRange = sheet2["A1:A2"];

                    //select 1st item from the list
                    comboBox1.SelectedIndex = 1;

                    sheet[46, 3].Text = "Card Type";
                    IOptionButtonShape optionButton1 = sheet.OptionButtons.AddOptionButton(46, 5);
                    optionButton1.Text       = "American Express";
                    optionButton1.CheckState = ExcelCheckState.Checked;

                    optionButton1      = sheet.OptionButtons.AddOptionButton(46, 7);
                    optionButton1.Text = "Master Card";

                    optionButton1      = sheet.OptionButtons.AddOptionButton(46, 9);
                    optionButton1.Text = "Visa";
                }

                //column alignment
                sheet.Columns[0].AutofitColumns();
                sheet.Columns[3].ColumnWidth = 12;
                sheet.Columns[4].ColumnWidth = 10;
                sheet.Columns[5].ColumnWidth = 10;
                sheet.IsGridLinesVisible     = false;

                sheet.DeleteRow(40);
                sheet.DeleteRow(41);
                sheet.DeleteRow(42);
                sheet.DeleteRow(45);

                //Save the document as a stream and retrun the stream
                using (MemoryStream stream = new MemoryStream())
                {
                    //Save the created Excel document to MemoryStream
                    workbook.SaveAs(stream);
                    return(stream);
                }
            }
        }
Exemple #8
0
        private void btnCreate_Click(object sender, System.EventArgs e)
        {
            #region Workbook Initialize
            //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;
            //Set the Default version as Excel 97to2003
            if (this.rdbExcel97.Checked)
            {
                application.DefaultVersion = ExcelVersion.Excel97to2003;
                fileName = "InteractiveFeatures.xls";
            }
            //Set the Default version as Excel 2007
            else if (this.rdbExcel2007.Checked)
            {
                application.DefaultVersion = ExcelVersion.Excel2007;
                fileName = "InteractiveFeatures.xlsx";
            }
            //Set the Default version as Excel 2010
            else if (this.rdbExcel2010.Checked)
            {
                application.DefaultVersion = ExcelVersion.Excel2010;
                fileName = "InteractiveFeatures.xlsx";
            }
            //Set the Default version as Excel 2013
            else if (this.rdbExcel2013.Checked)
            {
                application.DefaultVersion = ExcelVersion.Excel2013;
                fileName = "InteractiveFeatures.xlsx";
            }
            //A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
            //The new workbook will have 3 worksheets
            IWorkbook workbook = application.Workbooks.Create(3);
            //The first worksheet object in the worksheets collection is accessed.
            IWorksheet sheet = workbook.Worksheets[0];
            #endregion

            sheet.IsGridLinesVisible = false;

            sheet.Range["B2"].Text = "Interactive features";
            sheet.Range["B2"].CellStyle.Font.Bold = true;
            sheet.Range["B2"].CellStyle.Font.Size = 14;

            sheet.Range["A4"].Text = "Some Useful links";
            sheet.Range["A4"].CellStyle.Font.Bold = true;
            sheet.Range["A4"].CellStyle.Font.Size = 12;

            sheet.Range["A20"].Text = "Comments";
            sheet.Range["A20"].CellStyle.Font.Bold = true;
            sheet.Range["A20"].CellStyle.Font.Size = 12;

            sheet.Range["B5"].Text  = "Feature page";
            sheet.Range["B7"].Text  = "Support Email Id";
            sheet.Range["B9"].Text  = "Samples";
            sheet.Range["B11"].Text = "Read the comment about XlsIO";
            sheet.Range["B13"].Text = "Read the Comment about Interactive features";
            sheet.Range["B20"].Text = "XlsIO";
            sheet.Range["B22"].Text = "Interactive features";

            #region Hyperlink
            //Creating Hyperlink for a Website
            IHyperLink hyperlink = sheet.HyperLinks.Add(sheet.Range["C5"]);
            hyperlink.Type      = ExcelHyperLinkType.Url;
            hyperlink.Address   = "http://www.syncfusion.com/products/windows-forms/xlsio";
            hyperlink.ScreenTip = "To know more About XlsIO go through this link";

            //Creating Hyperlink for e-mail
            IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["C7"]);
            hyperlink1.Type      = ExcelHyperLinkType.Url;
            hyperlink1.Address   = "mailto:[email protected]";
            hyperlink1.ScreenTip = "Send Mail to this id for your queries";

            //Creating Hyperlink for Opening Files using type as  File
            IHyperLink hyperlink2 = sheet.HyperLinks.Add(sheet.Range["C9"]);
            hyperlink2.Type = ExcelHyperLinkType.File;

            hyperlink2.Address       = "../../../";
            hyperlink2.ScreenTip     = "File path";
            hyperlink2.TextToDisplay = "Hyperlink for files using File as type";

            //Creating Hyperlink to another cell using type as Workbook
            IHyperLink hyperlink4 = sheet.HyperLinks.Add(sheet.Range["C11"]);
            hyperlink4.Type          = ExcelHyperLinkType.Workbook;
            hyperlink4.Address       = "Sheet1!B20";
            hyperlink4.ScreenTip     = "Click here";
            hyperlink4.TextToDisplay = "Click here to move to the cell with Comments about XlsIO";

            IHyperLink hyperlink5 = sheet.HyperLinks.Add(sheet.Range["C13"]);
            hyperlink5.Type          = ExcelHyperLinkType.Workbook;
            hyperlink5.Address       = "Sheet1!B22";
            hyperlink5.ScreenTip     = "Click here";
            hyperlink5.TextToDisplay = "Click here to move to the cell with Comments about this sample";

            #endregion

            #region Comments

            //Insert Comments
            //Adding comments to a cell.
            sheet.Range["B20"].AddComment().Text = "XlsIO is a Backoffice product with high performance!";

            //Add RichText Comments
            IRange range = sheet.Range["B22"];
            range.AddComment().RichText.Text = "Great Sample!";
            IRichTextString rtf = range.Comment.RichText;

            //Formatting first 4 characters
            IFont greyFont = workbook.CreateFont();
            greyFont.Bold     = true;
            greyFont.Italic   = true;
            greyFont.RGBColor = Color.FromArgb(333365);
            rtf.SetFont(0, 3, greyFont);

            //Formatting last 4 characters
            IFont greenFont = workbook.CreateFont();
            greenFont.Bold     = true;
            greenFont.Italic   = true;
            greenFont.RGBColor = Color.Green;
            rtf.SetFont(4, 7, greenFont);

            //Set column width
            sheet.Columns[0].ColumnWidth = 30;

            #endregion

            #region Autofit the UsedRanges
            sheet.UsedRange.AutofitRows();
            sheet.UsedRange.AutofitColumns();
            #endregion

            #region Save the Workbook
            //Saving the workbook to disk.
            workbook.SaveAs(fileName);
            #endregion

            #region Workbook Close and Dispose
            //Close the workbook.
            workbook.Close();

            //No exception will be thrown if there are unsaved workbooks.
            excelEngine.ThrowNotSavedOnDestroy = false;
            excelEngine.Dispose();
            #endregion

            #region View the Workbook
            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo(fileName)
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                Process.Start(fileName);
#endif
                //Exit
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
            #endregion
        }
Exemple #9
0
        //
        // GET: /InteractiveFeatures/

        public ActionResult InteractiveFeatures(string Saveoption)
        {
            if (Saveoption == null)
            {
                return(View());
            }

            //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            // Default version is set as Excel 2007
            if (Saveoption == "Xls")
            {
                application.DefaultVersion = ExcelVersion.Excel97to2003;
            }
            else
            {
                application.DefaultVersion = ExcelVersion.Excel2016;
            }

            //A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]
            //The new workbook will have 3 worksheets
            IWorkbook workbook = application.Workbooks.Create(3);
            //The first worksheet object in the worksheets collection is accessed.
            IWorksheet sheet = workbook.Worksheets[0];

            sheet.IsGridLinesVisible = false;

            sheet.Range["B2"].Text = "Interactive features";
            sheet.Range["B2"].CellStyle.Font.Bold = true;
            sheet.Range["B2"].CellStyle.Font.Size = 14;

            sheet.Range["A4"].Text = "Some Useful links";
            sheet.Range["A4"].CellStyle.Font.Bold = true;
            sheet.Range["A4"].CellStyle.Font.Size = 12;

            sheet.Range["A20"].Text = "Comments";
            sheet.Range["A20"].CellStyle.Font.Bold = true;
            sheet.Range["A20"].CellStyle.Font.Size = 12;

            sheet.Range["B5"].Text  = "Feature page";
            sheet.Range["B7"].Text  = "Support Email Id";
            sheet.Range["B11"].Text = "Read the comment about XlsIO";
            sheet.Range["B13"].Text = "Read the Comment about Interactive features";
            sheet.Range["B20"].Text = "XlsIO";
            sheet.Range["B22"].Text = "Interactive features";

            #region Hyperlink
            //Creating Hyperlink for a Website
            IHyperLink hyperlink = sheet.HyperLinks.Add(sheet.Range["C5"]);
            hyperlink.Type      = ExcelHyperLinkType.Url;
            hyperlink.Address   = "http://www.syncfusion.com/products/windows-forms/xlsio";
            hyperlink.ScreenTip = "To know more About XlsIO go through this link";

            //Creating Hyperlink for e-mail
            IHyperLink hyperlink1 = sheet.HyperLinks.Add(sheet.Range["C7"]);
            hyperlink1.Type      = ExcelHyperLinkType.Url;
            hyperlink1.Address   = "mailto:[email protected]";
            hyperlink1.ScreenTip = "Send Mail to this id for your queries";

            //Creating Hyperlink to another cell using type as Workbook
            IHyperLink hyperlink4 = sheet.HyperLinks.Add(sheet.Range["C11"]);
            hyperlink4.Type          = ExcelHyperLinkType.Workbook;
            hyperlink4.Address       = "Sheet1!B20";
            hyperlink4.ScreenTip     = "Click here";
            hyperlink4.TextToDisplay = "Click here to move to the cell with Comments about XlsIO";

            IHyperLink hyperlink5 = sheet.HyperLinks.Add(sheet.Range["C13"]);
            hyperlink5.Type          = ExcelHyperLinkType.Workbook;
            hyperlink5.Address       = "Sheet1!B22";
            hyperlink5.ScreenTip     = "Click here";
            hyperlink5.TextToDisplay = "Click here to move to the cell with Comments about this sample";

            #endregion

            #region Comments

            //Insert Comments
            //Adding comments to a cell.
            sheet.Range["B20"].AddComment().Text = "XlsIO is a Backoffice product with high performance!";

            //Add RichText Comments
            IRange range = sheet.Range["B22"];
            range.AddComment().RichText.Text = "This sample describes the Essential XlsIO interactive.";
            IRichTextString rtf = range.Comment.RichText;

            //Formatting first 4 characters
            IFont greyFont = workbook.CreateFont();
            greyFont.Bold     = true;
            greyFont.Italic   = true;
            greyFont.RGBColor = Color.FromArgb(333365);
            rtf.SetFont(0, 54, greyFont);
            #endregion

            sheet.UsedRange.AutofitColumns();

            try
            {
                //Saving the workbook to disk.

                if (Saveoption == "Xls")
                {
                    return(excelEngine.SaveAsActionResult(workbook, "InteractiveFeatures.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97));
                }
                else
                {
                    return(excelEngine.SaveAsActionResult(workbook, "InteractiveFeatures.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
                }
            }
            catch (Exception)
            {
            }

            //Close the workbook.
            workbook.Close();
            excelEngine.Dispose();
            return(View());
        }
Exemple #10
0
        private void btnCreateReport_Click(object sender, EventArgs e)
        {
            #region Initialize Workbook
            ExcelEngine  excelEngine = new ExcelEngine();
            IApplication application = excelEngine.Excel;
            // A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
            // The number of default worksheets is the application setting in MS Excel.
            myWorkbook = excelEngine.Excel.Workbooks.Add(dataDirectory.FullName + "Template.xls");

            //Set the Default version as Excel 97to2003
            if (this.rdbExcel97.Checked)
            {
                myWorkbook.Version = ExcelVersion.Excel97to2003;
                fileName           = "StockPortfolioOutput.xls";
            }
            //Set the Default version as Excel 2007
            else if (this.rdbExcek2007.Checked)
            {
                myWorkbook.Version = ExcelVersion.Excel2007;
                fileName           = "StockPortfolioOutput.xlsx";
            }
            //Set the Default version as Excel 2010
            else if (this.rdbExcel2010.Checked)
            {
                myWorkbook.Version = ExcelVersion.Excel2010;
                fileName           = "StockPortfolioOutput.xlsx";
            }
            //Set the Default version as Excel 2013
            else if (this.rdbExcel2013.Checked)
            {
                myWorkbook.Version = ExcelVersion.Excel2013;
                fileName           = "StockPortfolioOutput.xlsx";
            }

            IChart chart = myWorkbook.Worksheets[1].Charts[0];
            chart.PrimaryCategoryAxis.NumberFormat     = "m/d/yyyy";
            chart.PrimaryValueAxis.NumberFormat        = "\"$\"#,##0.00";
            chart.SecondaryValueAxis.NumberFormat      = "\"$\"#,##0.00";
            chart.SecondaryValueAxis.TickLabelPosition = ExcelTickLabelPosition.TickLabelPosition_High;

            // Adding new worksheets in workbook's sheets collection
            for (int count = 1; count < StockList.SelectedItems.Count; count++)
            {
                myWorkbook.Worksheets.AddCopyAfter(myWorkbook.Worksheets[1], myWorkbook.Worksheets[0]);
            }

            // Adding hyperlinks to menu sheet
            IWorksheet menu_sheet = myWorkbook.Worksheets[0];
            #endregion

            int InsertIndex = DEF_FST_ROW_NUM_SC - 3;

            menu_sheet.HyperLinks.RemoveAt(0);
            menu_sheet.Range["G21"].Text = "";

            #region Insert Hyperlinks for Stock items
            for (int count = 0; count < StockList.SelectedItems.Count; count++)
            {
                menu_sheet.InsertRow(InsertIndex, 2, ExcelInsertOptions.FormatAsBefore);
                IHyperLink report_hyperlink = menu_sheet.HyperLinks.Add(menu_sheet.Range["G" + InsertIndex + ":I" + InsertIndex]);
                report_hyperlink.Type          = ExcelHyperLinkType.Workbook;
                report_hyperlink.Address       = StockList.SelectedItems[count].ToString() + "!A1";
                report_hyperlink.TextToDisplay = StockList.SelectedItems[count].ToString();

                InsertIndex += 2;
            }
            #endregion

            #region Creating Stock report

            int itemIndex = 1;

            foreach (Object StockListItem in StockList.SelectedItems)
            {
                CreateStockReport(StockListItem.ToString(), itemIndex);
                FillAnalysisPortfolioSheet(StockListItem.ToString());
                itemIndex += 1;
            }
            #endregion

            #region Save the Workbook
            myWorkbook.Worksheets[0].Activate();
            // Saving the workbook to disk.
            myWorkbook.SaveAs(reportDirectory + "\\" + fileName);
            #endregion

            #region Dispose the Excel Engine
            // No exception will be thrown if there are unsaved workbooks. No use here since we are
            // saving the workbook.
            excelEngine.ThrowNotSavedOnDestroy = false;
            excelEngine.Dispose();
            #endregion

            #region View the Workbook
            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                System.Diagnostics.Process.Start(reportDirectory + "\\" + fileName);
                //Exit
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
            #endregion
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            DateTime MaxDate = new DateTime(2008, 1, 29);
            DateTime MinDate = new DateTime(2008, 1, 1);

            if (Calendar2.SelectedDate > MaxDate || Calendar2.SelectedDate < MinDate || Calendar1.SelectedDate < MinDate || Calendar1.SelectedDate > MaxDate)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Selected Date is not valid.Please select the date between 1st Jan 2008 and 29th Jan 2008!');", true);
            }
            else
            {
                ExcelEngine  excelEngine = new ExcelEngine();
                IApplication application = excelEngine.Excel;
                // A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]
                // The number of default worksheets is the application setting in Microsoft Excel.
                myWorkbook = excelEngine.Excel.Workbooks.Add(XlsIOHelper.ResolveApplicationDataPath("Template.xls", Request));
                ListItem[] StockList;// = new ListItem();
                //  ArrayList[] StockList;
                int index = 0;
                foreach (ListItem lItem in CheckBoxList1.Items)
                {
                    if (lItem.Selected)
                    {
                        index++;
                    }
                }
                StockList = new ListItem[index];
                int stockItem = 0;
                foreach (ListItem lItem in CheckBoxList1.Items)
                {
                    if (lItem.Selected)
                    {
                        StockList[stockItem] = lItem;
                        stockItem++;
                    }
                }
                IChart chart = myWorkbook.Worksheets[1].Charts[0];
                chart.PrimaryCategoryAxis.NumberFormat     = "m/d/yyyy";
                chart.PrimaryValueAxis.NumberFormat        = "\"$\"#,##0.00";
                chart.SecondaryValueAxis.NumberFormat      = "\"$\"#,##0.00";
                chart.SecondaryValueAxis.TickLabelPosition = ExcelTickLabelPosition.TickLabelPosition_High;

                // Adding new worksheets in workbook's sheets collection
                for (int count = 1; count < StockList.Length; count++)
                {
                    myWorkbook.Worksheets.AddCopyAfter(myWorkbook.Worksheets[1], myWorkbook.Worksheets[0]);
                }

                // Adding hyperlinks to menu sheet
                IWorksheet menu_sheet  = myWorkbook.Worksheets[0];
                int        InsertIndex = DEF_FST_ROW_NUM_SC - 3;

                menu_sheet.HyperLinks.RemoveAt(0);
                menu_sheet.Range["G21"].Text = "";

                for (int count = 0; count < StockList.Length; count++)
                {
                    menu_sheet.InsertRow(InsertIndex, 2, ExcelInsertOptions.FormatAsBefore);
                    IHyperLink report_hyperlink = menu_sheet.HyperLinks.Add(menu_sheet.Range["G" + InsertIndex + ":I" + InsertIndex]);
                    report_hyperlink.Type          = ExcelHyperLinkType.Workbook;
                    report_hyperlink.Address       = StockList[count].Text + "!A1";
                    report_hyperlink.TextToDisplay = StockList[count].Text;

                    InsertIndex += 2;
                }

                // Creating Stock report
                int itemIndex = 1;

                foreach (Object StockListItem in StockList)
                {
                    CreateStockReport(StockListItem.ToString(), itemIndex);
                    FillAnalysisPortfolioSheet(StockListItem.ToString());
                    itemIndex += 1;
                }
                myWorkbook.Worksheets[0].Activate();
                //Saving the workbook to disk.


                if (rBtnXls.Checked == true)
                {
                    myWorkbook.Version = ExcelVersion.Excel97to2003;
                    myWorkbook.SaveAs(reportDirectory + "\\Sample.xls", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog);
                }
                else
                {
                    myWorkbook.Version = ExcelVersion.Excel2016;
                    myWorkbook.SaveAs(reportDirectory + "\\Sample.xlsx", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016);
                }
                //No exception will be thrown if there are unsaved workbooks.
                excelEngine.ThrowNotSavedOnDestroy = false;
                excelEngine.Dispose();
            }
        }
Exemple #12
0
        public MemoryStream CreateExcel()
        {
            //Create an instance of ExcelEngine
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                //Create a workbook
                IWorkbook  workbook  = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];


                //Disable gridlines in the worksheet
                worksheet.IsGridLinesVisible = false;

                //Enter values to the cells from A3 to A5
                worksheet.Range["A3"].Text = "46036 Michigan Ave";
                worksheet.Range["A4"].Text = "Canton, USA";
                worksheet.Range["A5"].Text = "Phone: +1 231-231-2310";

                //Make the text bold
                worksheet.Range["A3:A5"].CellStyle.Font.Bold = true;

                //Merge cells
                worksheet.Range["D1:E1"].Merge();

                //Enter text to the cell D1 and apply formatting.
                worksheet.Range["D1"].Text = "INVOICE";
                worksheet.Range["D1"].CellStyle.Font.Bold     = true;
                worksheet.Range["D1"].CellStyle.Font.RGBColor = Color.FromArgb(42, 118, 189);
                worksheet.Range["D1"].CellStyle.Font.Size     = 35;

                //Apply alignment in the cell D1
                worksheet.Range["D1"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignRight;
                worksheet.Range["D1"].CellStyle.VerticalAlignment   = ExcelVAlign.VAlignTop;

                //Enter values to the cells from D5 to E8
                worksheet.Range["D5"].Text   = "INVOICE#";
                worksheet.Range["E5"].Text   = "DATE";
                worksheet.Range["D6"].Number = 1028;
                worksheet.Range["E6"].Value  = "12/31/2018";
                worksheet.Range["D7"].Text   = "CUSTOMER ID";
                worksheet.Range["E7"].Text   = "TERMS";
                worksheet.Range["D8"].Number = 564;
                worksheet.Range["E8"].Text   = "Due Upon Receipt";

                //Apply RGB backcolor to the cells from D5 to E8
                worksheet.Range["D5:E5"].CellStyle.Color = Color.FromArgb(42, 118, 189);
                worksheet.Range["D7:E7"].CellStyle.Color = Color.FromArgb(42, 118, 189);

                //Apply known colors to the text in cells D5 to E8
                worksheet.Range["D5:E5"].CellStyle.Font.Color = ExcelKnownColors.White;
                worksheet.Range["D7:E7"].CellStyle.Font.Color = ExcelKnownColors.White;

                //Make the text as bold from D5 to E8
                worksheet.Range["D5:E8"].CellStyle.Font.Bold = true;

                //Apply alignment to the cells from D5 to E8
                worksheet.Range["D5:E8"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
                worksheet.Range["D5:E5"].CellStyle.VerticalAlignment   = ExcelVAlign.VAlignCenter;
                worksheet.Range["D7:E7"].CellStyle.VerticalAlignment   = ExcelVAlign.VAlignCenter;
                worksheet.Range["D6:E6"].CellStyle.VerticalAlignment   = ExcelVAlign.VAlignTop;

                //Enter value and applying formatting in the cell A7
                worksheet.Range["A7"].Text                 = "  BILL TO";
                worksheet.Range["A7"].CellStyle.Color      = Color.FromArgb(42, 118, 189);
                worksheet.Range["A7"].CellStyle.Font.Bold  = true;
                worksheet.Range["A7"].CellStyle.Font.Color = ExcelKnownColors.White;

                //Apply alignment
                worksheet.Range["A7"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignLeft;
                worksheet.Range["A7"].CellStyle.VerticalAlignment   = ExcelVAlign.VAlignCenter;

                //Enter values in the cells A8 to A12
                worksheet.Range["A8"].Text  = "Steyn";
                worksheet.Range["A9"].Text  = "Great Lakes Food Market";
                worksheet.Range["A10"].Text = "20 Whitehall Rd";
                worksheet.Range["A11"].Text = "North Muskegon,USA";
                worksheet.Range["A12"].Text = "+1 231-654-0000";

                //Create a Hyperlink for e-mail in the cell A13
                IHyperLink hyperlink = worksheet.HyperLinks.Add(worksheet.Range["A13"]);
                hyperlink.Type      = ExcelHyperLinkType.Url;
                hyperlink.Address   = "*****@*****.**";
                hyperlink.ScreenTip = "Send Mail";

                //Merge column A and B from row 15 to 22
                worksheet.Range["A15:B15"].Merge();
                worksheet.Range["A16:B16"].Merge();
                worksheet.Range["A17:B17"].Merge();
                worksheet.Range["A18:B18"].Merge();
                worksheet.Range["A19:B19"].Merge();
                worksheet.Range["A20:B20"].Merge();
                worksheet.Range["A21:B21"].Merge();
                worksheet.Range["A22:B22"].Merge();

                //Enter details of products and prices
                worksheet.Range["A15"].Text   = "  DESCRIPTION";
                worksheet.Range["C15"].Text   = "QTY";
                worksheet.Range["D15"].Text   = "UNIT PRICE";
                worksheet.Range["E15"].Text   = "AMOUNT";
                worksheet.Range["A16"].Text   = "Cabrales Cheese";
                worksheet.Range["A17"].Text   = "Chocos";
                worksheet.Range["A18"].Text   = "Pasta";
                worksheet.Range["A19"].Text   = "Cereals";
                worksheet.Range["A20"].Text   = "Ice Cream";
                worksheet.Range["C16"].Number = 3;
                worksheet.Range["C17"].Number = 2;
                worksheet.Range["C18"].Number = 1;
                worksheet.Range["C19"].Number = 4;
                worksheet.Range["C20"].Number = 3;
                worksheet.Range["D16"].Number = 21;
                worksheet.Range["D17"].Number = 54;
                worksheet.Range["D18"].Number = 10;
                worksheet.Range["D19"].Number = 20;
                worksheet.Range["D20"].Number = 30;
                worksheet.Range["D23"].Text   = "Total";

                //Apply number format
                worksheet.Range["D16:E22"].NumberFormat = "$.00";
                worksheet.Range["E23"].NumberFormat     = "$.00";

                //Apply incremental formula for column Amount by multiplying Qty and UnitPrice
                application.EnableIncrementalFormula = true;
                worksheet.Range["E16:E20"].Formula   = "=C16*D16";

                //Formula for Sum the total
                worksheet.Range["E23"].Formula = "=SUM(E16:E22)";

                //Apply borders
                worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle    = ExcelLineStyle.Thin;
                worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
                worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color        = ExcelKnownColors.Grey_25_percent;
                worksheet.Range["A16:E22"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color     = ExcelKnownColors.Grey_25_percent;
                worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle    = ExcelLineStyle.Thin;
                worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
                worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeTop].Color        = ExcelKnownColors.Black;
                worksheet.Range["A23:E23"].CellStyle.Borders[ExcelBordersIndex.EdgeBottom].Color     = ExcelKnownColors.Black;

                //Apply font setting for cells with product details
                worksheet.Range["A3:E23"].CellStyle.Font.FontName = "Arial";
                worksheet.Range["A3:E23"].CellStyle.Font.Size     = 10;
                worksheet.Range["A15:E15"].CellStyle.Font.Color   = ExcelKnownColors.White;
                worksheet.Range["A15:E15"].CellStyle.Font.Bold    = true;
                worksheet.Range["D23:E23"].CellStyle.Font.Bold    = true;

                //Apply cell color
                worksheet.Range["A15:E15"].CellStyle.Color = Color.FromArgb(42, 118, 189);

                //Apply alignment to cells with product details
                worksheet.Range["A15"].CellStyle.HorizontalAlignment     = ExcelHAlign.HAlignLeft;
                worksheet.Range["C15:C22"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
                worksheet.Range["D15:E15"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;

                //Apply row height and column width to look good
                worksheet.Range["A1"].ColumnWidth    = 36;
                worksheet.Range["B1"].ColumnWidth    = 11;
                worksheet.Range["C1"].ColumnWidth    = 8;
                worksheet.Range["D1:E1"].ColumnWidth = 18;
                worksheet.Range["A1"].RowHeight      = 47;
                worksheet.Range["A2"].RowHeight      = 15;
                worksheet.Range["A3:A4"].RowHeight   = 15;
                worksheet.Range["A5"].RowHeight      = 18;
                worksheet.Range["A6"].RowHeight      = 29;
                worksheet.Range["A7"].RowHeight      = 18;
                worksheet.Range["A8"].RowHeight      = 15;
                worksheet.Range["A9:A14"].RowHeight  = 15;
                worksheet.Range["A15:A23"].RowHeight = 18;

                //Save the document as a stream and retrun the stream.
                using (MemoryStream stream = new MemoryStream())
                {
                    //Save the created Excel document to MemoryStream
                    workbook.SaveAs(stream);
                    return(stream);
                }
            }
        }