//
// Copyright (c) 2016, MindFusion LLC - Bulgaria.
//

using System;
using System.Drawing;
using System.Linq;
using MindFusion.Spreadsheet.Charts;

namespace MindFusion.Spreadsheet.WinForms.Samples.CS.Demo
{
	partial class DemoForm
	{
		private void CreateData()
		{
			if (workbook.Worksheets.Count != 3)
				CreateSheets(3);
			Worksheet ws;

			#region Welcome
			ws = workbook.Worksheets[0];
			ws.Name = "Welcome";
			ws.BeginInit();

			ws.Cells["A1"].Data = "=NOW()";
			SetHyperlink(ws.Cells["A1"], HyperlinkType.ExistingFile, "HelpFile", "/NOW_0.htm");
			ws.Cells["A1"].Style.Format = "M/d/yyyy h:mm tt";
			ws.Cells["A1"].Style.HorizontalAlignment = HorizontalAlignment.Left;

			ws.Cells["A3"].Data = "Welcome to MindFusion.Spreadsheet!";

			ws.Cells["A5"].Data = "MindFusion.Spreadsheet is a spreadsheet component that can be used to create, open, manage, and export spreadsheet documents in many different formats without requiring Microsoft Excel. It is implemented as a .NET control and can be easily integrated into any application targeting the Microsoft .NET platform.";
			ws.Cells["A5"].Style.WrapText = true;

			ws.Cells["A7"].Data = "MindFusion.Spreadsheet supports:";
			ws.Cells["A8"].Data = " • Importing documents from CSV, XLSX, ODS";
			ws.Cells["A9"].Data = " • Export to PDF";
			ws.Cells["A10"].Data = " • Numerous chart types";
			ws.Cells["A11"].Data = " • Customizable cell appearance";
			ws.Cells["A12"].Data = " • Merged cells";
			ws.Cells["A13"].Data = " • Conditional formatting";
			ws.Cells["A14"].Data = " • Data validation";
			ws.Cells["A15"].Data = " • Images";
			ws.Cells["A16"].Data = " • Cell annotations";
			ws.Cells["A17"].Data = " • Previewing and printing";
			ws.Cells["A18"].Data = " • Undo and redo";
			ws.Cells["A19"].Data = " • Auxiliary forms";

			ws.Cells["A21"].Data = "MindFusion.Spreadsheet provides intuitive user-interaction model for creating or editing spreadsheet documents. Its programmatic interface is powerful and simple to use. The control has been tested with the most popular .NET development environments and programming languages, and is used by companies from all around the world to create applications in C#, VB.NET and Delphi.NET.";
			ws.Cells["A21"].Style.WrapText = true;

			ws.CellRanges["A5:I5"].Merge();
			ws.CellRanges["A21:I21"].Merge();

			ws.CellRanges[0, 0, 0x400, 0x100000].Style.Background = new MindFusion.Drawing.SolidBrush(Color.White);

			ws.Columns[0].Width = Measure.Point(185);
			ws.Rows[4].Height = Measure.Point(40);
			ws.Rows[20].Height = Measure.Point(40);
			ws.EndInit();
			#endregion

			#region Formulas
			ws = workbook.Worksheets[1];
			ws.Name = "Formula Examples";
			ws.BeginInit();

			#region Common

			ws.Cells["A1"].Data = "Commonly used formulas";
			ws.Cells["A2"].Data = "Values";
			ws.Cells["C2"].Data = "Result";
			ws.Cells["D2"].Data = "Formula";
			ws.Cells["E2"].Data = "Description";
			for (int i = 1; i <= 10; i++)
				ws.Cells[0, i + 1].Data = i;
			ws.Cells["B3"].Data = "One";
			ws.Cells["B4"].Data = "Two";
			ws.Cells["B5"].Data = "Three";
			ws.Cells["B6"].Data = "Four";
			ws.Cells["B7"].Data = "Five";
			ws.Cells["B8"].Data = "Six";
			ws.Cells["B9"].Data = "Seven";
			ws.Cells["B10"].Data = "Eight";
			ws.Cells["B11"].Data = "Nine";
			ws.Cells["B12"].Data = "Ten";
			ws.Cells["C3"].Data = "=SUM(A3:B12)";
			ws.Cells["D3"].Data = "'=SUM(A3:B12)";
			ws.Cells["E3"].Data = "Returns the sum of the specified arguments.";
			SetHyperlink(ws.Cells["E3"], HyperlinkType.ExistingFile, "HelpFile", "/SUM_0.htm");
			ws.Cells["C4"].Data = "=AVERAGE(A3:B12)";
			ws.Cells["D4"].Data = "'=AVERAGE(A3:B12)";
			ws.Cells["E4"].Data = "Returns the average of the specified arguments.";
			SetHyperlink(ws.Cells["E4"], HyperlinkType.ExistingFile, "HelpFile", "AVERAGE.htm");
			ws.Cells["C5"].Data = "=COUNT(A3:B12)";
			ws.Cells["D5"].Data = "'=COUNT(A3:B12)";
			ws.Cells["E5"].Data = "Counts the numbers in the specified cell, cells, and lists.";
			SetHyperlink(ws.Cells["E5"], HyperlinkType.ExistingFile, "HelpFile", "/COUNT_0.htm");
			ws.Cells["C6"].Data = "=COUNTIF(A3:B12, \">4\")";
			ws.Cells["D6"].Data = "'=COUNTIF(A3:B12, \">4\")";
			ws.Cells["E6"].Data = "Counts the number of cells in the specified range that meet the specified criterion.";
			SetHyperlink(ws.Cells["E6"], HyperlinkType.ExistingFile, "HelpFile", "/COUNTIF.htm");
			ws.Cells["C7"].Data = "=MAX(A3:B12)";
			ws.Cells["D7"].Data = "'=MAX(A3:B12)";
			ws.Cells["E7"].Data = "Returns the largest from the specified arguments.";
			SetHyperlink(ws.Cells["E7"], HyperlinkType.ExistingFile, "HelpFile", "/MAX_0.htm");
			ws.Cells["C8"].Data = "=VLOOKUP(4, A3:B12, 2, TRUE)";
			ws.Cells["D8"].Data = "'=VLOOKUP(4, A3:B12, 2, TRUE)";
			ws.Cells["E8"].Data = "Searches for a value in the first column of the specified table or array of values, and returns a value in the same row from another specified column in the table or array.";
			SetHyperlink(ws.Cells["E8"], HyperlinkType.ExistingFile, "HelpFile", "/VLOOKUP.htm");
			ws.Cells["C9"].Data = "=AND(A3>A4, A3<A5)";
			ws.Cells["D9"].Data = "'=AND(A3>A4, A3<A5)";
			ws.Cells["E9"].Data = "Returns TRUE if all of the specified arguments evaluate to TRUE; returns FALSE if one or more of the arguments evaluate to FALSE.";
			SetHyperlink(ws.Cells["E9"], HyperlinkType.ExistingFile, "HelpFile", "/AND.htm");
			ws.Cells["C10"].Data = "=CHOOSE(TYPE(B10), \"Number\", \"Text\")";
			ws.Cells["D10"].Data = "'=CHOOSE(TYPE(B10), \"Number\", \"Text\")";
			ws.Cells["E10"].Data = "Returns a value from the specified list of values based on the specified index.";
			SetHyperlink(ws.Cells["E10"], HyperlinkType.ExistingFile, "HelpFile", "/CHOOSE.htm");
			ws.Cells["C11"].Data = "=CONCATENATE(A11, \" = \", B11)";
			ws.Cells["D11"].Data = "'=CONCATENATE(A11, \" = \", B11)";
			ws.Cells["E11"].Data = "Joins the specified text values into a single text value.";
			SetHyperlink(ws.Cells["E11"], HyperlinkType.ExistingFile, "HelpFile", "/CONCATENATE.htm");
			ws.Cells["C12"].Data = "=IFERROR(A6/(A5-A4-A3), \"Error\")";
			ws.Cells["D12"].Data = "'=IFERROR(A6/(A5-A4-A3), \"Error\")";
			ws.Cells["E12"].Data = "Returns the specified value unless it is an error, in which case returns the specified alternative value.";
			SetHyperlink(ws.Cells["E12"], HyperlinkType.ExistingFile, "HelpFile", "/IFERROR.htm");

			ws.CellRanges["A1:E1"].Merge();
			ws.CellRanges["A2:B2"].Merge();

			StyleHeader(ws.CellRanges["A1:E1"].Style);
			StyleSubHeader(ws.CellRanges["A2:E2"].Style);
			StyleGeneral(ws.CellRanges["A3:E12"].Style);

			ws.CellRanges["A3:A12"].Style.BorderLeftSize = ws.CellRanges["E3:E12"].Style.BorderRightSize =
				ws.CellRanges["A12:E12"].Style.BorderBottomSize = Measure.Point(1);
			ws.CellRanges["A3:A12"].Style.BorderLeftColor = ws.CellRanges["E3:E12"].Style.BorderRightColor =
				ws.CellRanges["A12:E12"].Style.BorderBottomColor = Color.Black;

			#endregion

			#region Constants

			ws.Cells["G1"].Data = "Constants";
			ws.Cells["G2"].Data = "Name";
			ws.Cells["H2"].Data = "Value";
			ws.Cells["I2"].Data = "Formula";
			ws.Cells["G3"].Data = "π";
			ws.Cells["G4"].Data = "e";
			ws.Cells["G5"].Data = "√2";
			ws.Cells["G6"].Data = "Φ";
			ws.Cells["G7"].Data = "φ";
			ws.Cells["G8"].Data = "δs";
			ws.Cells["H3"].Data = "=PI()";
			ws.Cells["I3"].Data = "'=PI()";
			SetHyperlink(ws.Cells["I3"], HyperlinkType.ExistingFile, "HelpFile", "/PI_0.htm");
			ws.Cells["H4"].Data = "=EXP(1)";
			ws.Cells["I4"].Data = "'=EXP(1)";
			SetHyperlink(ws.Cells["I4"], HyperlinkType.ExistingFile, "HelpFile", "/EXP_0.htm");
			ws.Cells["H5"].Data = "=SQRT(2)";
			ws.Cells["I5"].Data = "'=SQRT(2)";
			SetHyperlink(ws.Cells["I5"], HyperlinkType.ExistingFile, "HelpFile", "/SQRT_0.htm");
			ws.Cells["H6"].Data = "=2*COS(H3/5)";
			ws.Cells["I6"].Data = "'=2*COS(H3/5)";
			SetHyperlink(ws.Cells["I6"], HyperlinkType.ExistingFile, "HelpFile", "/COS_0.htm");
			ws.Cells["H7"].Data = "=1/H6";
			ws.Cells["I7"].Data = "'=1/H6";
			ws.Cells["H8"].Data = "=1+H5";
			ws.Cells["I8"].Data = "'=1+H5";
			
			ws.CellRanges["G1:I1"].Merge();

			StyleHeader(ws.CellRanges["G1:I1"].Style);
			StyleSubHeader(ws.CellRanges["G2:I2"].Style);
			StyleGeneral(ws.CellRanges["G3:I8"].Style);

			ws.CellRanges["G3:G8"].Style.BorderLeftSize = ws.CellRanges["I3:I8"].Style.BorderRightSize =
				ws.CellRanges["G8:I8"].Style.BorderBottomSize = Measure.Point(1);
			ws.CellRanges["G3:G8"].Style.BorderLeftColor = ws.CellRanges["I3:I8"].Style.BorderRightColor =
				ws.CellRanges["G8:I8"].Style.BorderBottomColor = Color.Black;

			ws.CellRanges["H3:H8"].Style.Format = "?.?????????????";
			ws.Cells["G4"].Style.FontItalic = true;

			#endregion

			#region Math

			ws.Cells["A14"].Data = "Math";
			ws.Cells["A15"].Data = "Values";
			ws.Cells["C15"].Data = "Result";
			ws.Cells["D15"].Data = "Formula";
			ws.Cells["E15"].Data = "Description";
			for (int i = 15; i <= 22; i++)
			{
				ws.Cells[0, i].Data = Math.Round(rnd.Next(1, 10) * rnd.NextDouble(), 2);
				ws.Cells[1, i].Data = i - 14;
			}
			ws.Cells["C16"].Data = "=SUMIF(A16:A23,\">=1\",B16:B23)";
			ws.Cells["D16"].Data = "'=SUMIF(A16:A23,\">=1\",B16:B23)";
			ws.Cells["E16"].Data = "Returns the sum of the cells in the specified range that meet the specified criterion.";
			SetHyperlink(ws.Cells["E16"], HyperlinkType.ExistingFile, "HelpFile", "/SUMIF.htm");
			ws.Cells["C17"].Data = "=GCD(A17,B17)";
			ws.Cells["D17"].Data = "'=GCD(B18,B21)";
			ws.Cells["E17"].Data = "Returns the greatest common divisor (GCD) of the specified sequence of numbers.";
			SetHyperlink(ws.Cells["E17"], HyperlinkType.ExistingFile, "HelpFile", "/GCD.htm");
			ws.Cells["C18"].Data = "=MOD(A18,B18)";
			ws.Cells["D18"].Data = "'=MOD(A18,B18)";
			ws.Cells["E18"].Data = "Returns the reminder of the division of the specified number.";
			SetHyperlink(ws.Cells["E18"], HyperlinkType.ExistingFile, "HelpFile", "/MOD.htm");
			ws.Cells["C19"].Data = "=ROUND(LOG(A19, 2) + LOG(B19, 2), 5)";
			ws.Cells["D19"].Data = "'=ROUND(LOG(A19, 2) + LOG(B19, 2), 5)";
			ws.Cells["E19"].Data = "LOG - Returns the logarithm of the specified number to the specified base.";
			SetHyperlink(ws.Cells["E19"], HyperlinkType.ExistingFile, "HelpFile", "/LOG_0.htm");
			ws.Cells["C20"].Data = "=FACT(B20)";
			ws.Cells["D20"].Data = "'=FACT(B20)";
			ws.Cells["E20"].Data = "Returns the factorial of the specified number.";
			SetHyperlink(ws.Cells["E20"], HyperlinkType.ExistingFile, "HelpFile", "/FACT.htm");
			ws.Cells["C21"].Data = "=POWER(SIN(B21),2)+POWER(COS(B21),2)";
			ws.Cells["D21"].Data = "'=POWER(SIN(B21),2)+POWER(COS(B21),2)";
			ws.Cells["E21"].Data = "POWER - Returns the specified number raised to the specified power.";
			SetHyperlink(ws.Cells["E21"], HyperlinkType.ExistingFile, "HelpFile", "/POWER.htm");
			ws.Cells["C22"].Data = "=ABS(B22-10)";
			ws.Cells["D22"].Data = "'=ABS(B22-10)";
			ws.Cells["E22"].Data = "Return the absolute (non-negative) value of the specified number.";
			SetHyperlink(ws.Cells["E22"], HyperlinkType.ExistingFile, "HelpFile", "/ABS_0.htm");
			ws.Cells["C23"].Data = "=TRUNC(A23/B23)";
			ws.Cells["D23"].Data = "'=TRUNC(A23/B23)";
			ws.Cells["E23"].Data = "Truncates the specified number to the specified number of digits.";
			SetHyperlink(ws.Cells["E23"], HyperlinkType.ExistingFile, "HelpFile", "/TRUNC.htm");


			ws.CellRanges["A14:E14"].Merge();
			ws.CellRanges["A15:B15"].Merge();

			StyleHeader(ws.CellRanges["A14:E14"].Style);
			StyleSubHeader(ws.CellRanges["A15:E15"].Style);
			StyleGeneral(ws.CellRanges["A16:E23"].Style);

			ws.CellRanges["A16:A23"].Style.BorderLeftSize = ws.CellRanges["E16:E23"].Style.BorderRightSize =
				ws.CellRanges["A23:E23"].Style.BorderBottomSize = Measure.Point(1);
			ws.CellRanges["A16:A23"].Style.BorderLeftColor = ws.CellRanges["E16:E23"].Style.BorderRightColor =
				ws.CellRanges["A23:E23"].Style.BorderBottomColor = Color.Black;

			#endregion

			#region Finance

			ws.Cells["A25"].Data = "Finance";
			ws.Cells["A26"].Data = "Values";
			ws.Cells["C26"].Data = "Result";
			ws.Cells["D26"].Data = "Formula";
			ws.Cells["E26"].Data = "Description";

			ws.Cells["A27"].Data = "Total Amount";
			ws.Cells["B27"].Data = 48000;
			ws.Cells["A28"].Data = "Interest Rate";
			ws.Cells["B28"].Data = 0.075;
			ws.Cells["A29"].Data = "No. of Deposits";
			ws.Cells["B29"].Data = 60;
			ws.Cells["A30"].Data = "Monthly Payment";
			ws.Cells["B30"].Data = 961.8216;
			ws.Cells["A32"].Data = -100000;
			ws.Cells["A33"].Data = 23000;
			ws.Cells["B32"].Data = 13000;
			ws.Cells["B33"].Data = 47000;
			ws.Cells["A34"].Data = "Cost";
			ws.Cells["B34"].Data = 5500;
			ws.Cells["A35"].Data = "Salvage";
			ws.Cells["B35"].Data = 675;
			ws.Cells["A36"].Data = "Life";
			ws.Cells["B36"].Data = 6;

			ws.Cells["C27"].Data = "=PV(B28/12,B29,B30)";
			ws.Cells["D27"].Data = "'=PV(B28/12,B29,B30)";
			ws.Cells["E27"].Data = "Returns the present value of an investment. The present value is the total amount that a series of future payments is worth now.";
			SetHyperlink(ws.Cells["E27"], HyperlinkType.ExistingFile, "HelpFile", "/PV.htm");
			ws.Cells["C28"].Data = "=RATE(B29,-B30,B27)*12";
			ws.Cells["D28"].Data = "'=RATE(B29,-B30,B27)*12";
			ws.Cells["E28"].Data = "Returns the interest rate per period of an annuity.";
			SetHyperlink(ws.Cells["E28"], HyperlinkType.ExistingFile, "HelpFile", "/RATE.htm");
			ws.Cells["C29"].Data = "=NPER(B28/12,-B30,B27)";
			ws.Cells["D29"].Data = "'=NPER(B28/12,-B30,B27)";
			ws.Cells["E29"].Data = "Returns the number of periods for the specified investment based on the specified periodic, constant payments and the specified constant interest rate.";
			SetHyperlink(ws.Cells["E29"], HyperlinkType.ExistingFile, "HelpFile", "/NPER.htm");
			ws.Cells["C30"].Data = "=PMT(B28/12,B29,B27)";
			ws.Cells["D30"].Data = "'=PMT(B28/12,B29,B27)";
			ws.Cells["E30"].Data = "Calculates the payment for a loan based on the specified constant payments and the specified constant interest rate.";
			SetHyperlink(ws.Cells["E30"], HyperlinkType.ExistingFile, "HelpFile", "/PMT.htm");
			ws.Cells["C31"].Data = "=FV(B28/12,B29,B30)";
			ws.Cells["D31"].Data = "'=FV(B28/12,B29,B30)";
			ws.Cells["E31"].Data = "Calculates the payment for a loan based on the specified constant payments and the specified constant interest rate.";
			SetHyperlink(ws.Cells["E31"], HyperlinkType.ExistingFile, "HelpFile", "/FV.htm");
			ws.Cells["C33"].Data = "=IRR(A32:B33)";
			ws.Cells["D33"].Data = "'=IRR(A32:B33)";
			ws.Cells["E32"].Data = "Returns the internal rate of return for the specified series of cash flows.";
			SetHyperlink(ws.Cells["E32"], HyperlinkType.ExistingFile, "HelpFile", "/IRR.htm");
			ws.Cells["C34"].Data = "=SLN(B34,B35,B36)";
			ws.Cells["D34"].Data = "'=SLN(B34,B35,B36)";
			ws.Cells["E34"].Data = "Returns the straight-line depreciation of an asset for one period.";
			SetHyperlink(ws.Cells["E34"], HyperlinkType.ExistingFile, "HelpFile", "/SLN.htm");
			ws.Cells["C35"].Data = "=SYD(B34,B35,B36,3)";
			ws.Cells["D35"].Data = "'=SYD(B34,B35,B36,3)";
			ws.Cells["E35"].Data = "Returns the sum-of-years'-digits depreciation of an asset for the specified period.";
			SetHyperlink(ws.Cells["E35"], HyperlinkType.ExistingFile, "HelpFile", "/SYD.htm");
			ws.Cells["C36"].Data = "=DB(B34,B35,B36,3)";
			ws.Cells["D36"].Data = "'=DB(B34,B35,B36,3)";
			ws.Cells["E36"].Data = "Returns the depreciation allowance of an asset for the specified period using the fixed-declining balance method.";
			SetHyperlink(ws.Cells["E36"], HyperlinkType.ExistingFile, "HelpFile", "/DB.htm");

			ws.CellRanges["A25:E25"].Merge();
			ws.CellRanges["A26:B26"].Merge();
			ws.CellRanges["E32:E33"].Merge();

			StyleHeader(ws.CellRanges["A25:E25"].Style);
			StyleSubHeader(ws.CellRanges["A26:E26"].Style);
			StyleGeneral(ws.CellRanges["A27:E36"].Style);

			ws.CellRanges["A27:A36"].Style.BorderLeftSize = ws.CellRanges["E27:E36"].Style.BorderRightSize =
				ws.CellRanges["A36:E36"].Style.BorderBottomSize = Measure.Point(1);
			ws.CellRanges["A27:A36"].Style.BorderLeftColor = ws.CellRanges["E27:E36"].Style.BorderRightColor =
				ws.CellRanges["A36:E36"].Style.BorderBottomColor = Color.Black;


			ws.CellRanges["B27:C27"].Style.Format = "[$$-409]#,##0.00;([$$-409]#,##0.00)";
			ws.CellRanges["B28:C28"].Style.Format = "0.00%";
			ws.CellRanges["B29:C29"].Style.Format = "0";
			ws.CellRanges["B30:C31"].Style.Format = "[$$-409]#,##0.00;([$$-409]#,##0.00)";
			ws.CellRanges["A32:B33"].Style.Format = "[$$-409]#,##0.00;([$$-409]#,##0.00)";
			ws.CellRanges["B34:B35"].Style.Format = "[$$-409]#,##0.00;([$$-409]#,##0.00)";

			ws.CellRanges["A27:C36"].ConditionalFormats.Add(ConditionalFormatType.CellValue, ComparisonOperator.LessThan, "0", null).Style.TextColor = Color.Red;

			#endregion

			#region Statistics

			ws.Cells["A38"].Data = "Statistics";
			ws.Cells["A39"].Data = "Values";
			ws.Cells["C39"].Data = "Result";
			ws.Cells["D39"].Data = "Formula";
			ws.Cells["E39"].Data = "Description";

			for (int i = 39; i <= 43; i++)
			{
				ws.Cells[0, i].Data = 359 + rnd.NextDouble();
				ws.CellRanges[0, i, 1, i].Merge();
			}

			ws.Cells["C40"].Data = "=MEDIAN(A40:A49)";
			ws.Cells["D40"].Data = "'=MEDIAN(A40:A49)";
			ws.Cells["E40"].Data = "Returns the median (middle value) of the specified arguments.";
			SetHyperlink(ws.Cells["E40"], HyperlinkType.ExistingFile, "HelpFile", "/MEDIAN_0.htm");
			ws.Cells["C41"].Data = "=VAR(A40:A49)";
			ws.Cells["D41"].Data = "'=VAR(A40:A49)";
			ws.Cells["E41"].Data = "Calculates the sample variance of the specified arguments.";
			SetHyperlink(ws.Cells["E41"], HyperlinkType.ExistingFile, "HelpFile", "/VAR.htm");
			ws.Cells["C42"].Data = "=VARP(A40:A49)";
			ws.Cells["D42"].Data = "'=VARP(A40:A49)";
			ws.Cells["E42"].Data = "Computes the variance of the specified arguments.";
			SetHyperlink(ws.Cells["E42"], HyperlinkType.ExistingFile, "HelpFile", "/VARP.htm");
			ws.Cells["C43"].Data = "=STDEV(A40:A49)";
			ws.Cells["D43"].Data = "'=STDEV(A40:A49)";
			ws.Cells["E43"].Data = "Estimates standard deviation based on the specified set of numbers.";
			SetHyperlink(ws.Cells["E43"], HyperlinkType.ExistingFile, "HelpFile", "/STDEV.htm");
			ws.Cells["C44"].Data = "=STDEVP(A40:A49)";
			ws.Cells["D44"].Data = "'=STDEVP(A40:A49)";
			ws.Cells["E44"].Data = "Calculates standard deviation based on the entire population given as arguments.";
			SetHyperlink(ws.Cells["E44"], HyperlinkType.ExistingFile, "HelpFile", "/STDEVP.htm");

			ws.CellRanges["A38:E38"].Merge();
			ws.CellRanges["A39:B39"].Merge();

			StyleHeader(ws.CellRanges["A38:E38"].Style);
			StyleSubHeader(ws.CellRanges["A39:E39"].Style);
			StyleGeneral(ws.CellRanges["A40:E44"].Style);

			ws.CellRanges["A40:A44"].Style.BorderLeftSize = ws.CellRanges["E40:E44"].Style.BorderRightSize =
				ws.CellRanges["A44:E44"].Style.BorderBottomSize = Measure.Point(1);
			ws.CellRanges["A40:A44"].Style.BorderLeftColor = ws.CellRanges["E40:E44"].Style.BorderRightColor =
				ws.CellRanges["A44:E44"].Style.BorderBottomColor = Color.Black;

			#endregion

			ws.CellRanges["E1:E100"].Style.WrapText = true;
			ws.CellRanges["A1:I100"].Style.VerticalAlignment = VerticalAlignment.Middle;

			ws.DefaultColumnWidth = Measure.Point(55);
			ws.DefaultRowHeight = Measure.Point(27);
			ws.Columns[0].Width = Measure.Point(75);
			ws.Columns[2].Width = Measure.Point(85);
			ws.Columns[3].Width = Measure.Point(220);
			ws.Columns[4].Width = Measure.Point(250);
			ws.Columns[5].Width = Measure.Point(20);
			ws.Columns[7].Width = Measure.Point(75);
			ws.Columns[8].Width = Measure.Point(65);

			ws.Rows[0].Height = Measure.Point(35);
			ws.Rows[1].Height = Measure.Point(20);
			ws.Rows[7].Height = Measure.Point(38);
			ws.Rows[8].Height = Measure.Point(38);

			ws.Rows[13].Height = Measure.Point(35);
			ws.Rows[14].Height = Measure.Point(20);

			ws.Rows[24].Height = Measure.Point(35);
			ws.Rows[25].Height = Measure.Point(20);
			ws.Rows[26].Height = Measure.Point(38);
			ws.Rows[28].Height = Measure.Point(38);

			ws.Rows[37].Height = Measure.Point(35);
			ws.Rows[38].Height = Measure.Point(20);

			ws.EndInit();

			#endregion

			#region Objects

			ws = workbook.Worksheets[2];
			ws.Name = "Objects";
			ws.BeginInit();

			ws.Cells["A1"].Data = "Overlapping Pictures:";

			Picture pic = ws.Drawing.AddPicture();
			pic.Source = MindFusion.Spreadsheet.WinForms.Samples.CS.Demo.Properties.Resources.pic01;
			pic.Anchor = ObjectAnchor.ToCell;
			pic.FromColumn = 0;
			pic.FromRow = 1;
			pic.VerticalOffset = Measure.Point(3.75);
			pic.HorizontalOffset = Measure.Point(2.25);
			pic = ws.Drawing.AddPicture();
			pic.Source = MindFusion.Spreadsheet.WinForms.Samples.CS.Demo.Properties.Resources.pic02;
			pic.Anchor = ObjectAnchor.ToCell;
			pic.FromColumn = 1;
			pic.FromRow = 4;
			pic.VerticalOffset = Measure.Point(1.5);
			pic.HorizontalOffset = Measure.Point(-45);
			pic = ws.Drawing.AddPicture();
			pic.Source = MindFusion.Spreadsheet.WinForms.Samples.CS.Demo.Properties.Resources.pic03;
			pic.Anchor = ObjectAnchor.ToCell;
			pic.FromColumn = 1;
			pic.FromRow = 7;
			pic.VerticalOffset = Measure.Point(-0.75);
			pic.HorizontalOffset = Measure.Point(-0.75);

			ws.Cells["A15"].Data = "Column Chart";
			Chart chart = ws.Drawing.AddChart(0, 15);
			chart.SetDataSource("'Formula Examples'!$A$40:$A$44", PlotBy.Column, false, false);
			chart.Height = Measure.Point(256.5);
			chart.Width = Measure.Point(336);

			chart.Series[0].Name = "Sample Data";
			chart.Series[0].Fill = new MindFusion.Drawing.LinearGradientBrush(Color.Firebrick, Color.Goldenrod, 90);

			var values = from Cell cell in workbook.Worksheets["Formula Examples"].CellRanges["$A$40:$A$44"]
						 select (double)cell.Value;

			chart.YAxisSettings.Minimum = values.Min();
			chart.YAxisSettings.Maximum = values.Max();
			chart.YAxisSettings.MajorUnit = Math.Round((chart.YAxisSettings.Maximum.Value - chart.YAxisSettings.Minimum.Value) * 0.1, 2);
			chart.YAxisSettings.MinorUnit = chart.YAxisSettings.MajorUnit / 2;
			chart.YAxisSettings.ShowMajorGridLines = true;
			chart.YAxisSettings.ShowMinorTicks = true;
			chart.FontSize = 6f;

			ws.Cells["H15"].Data = "Pie Chart";
			chart = ws.Drawing.AddChart(7, 15);
			chart.SetDataSource("'Formula Examples'!$A$33:$B$33", PlotBy.Row, false, false);
			chart.Height = Measure.Point(256.5);
			chart.Width = Measure.Point(336);
			chart.Type = ChartType.PieExploded;
			

			Cell c  = ws.Cells["K9"];
			c.Data = "Cell with comment";
			c.SetAnnotation("This is a comment.\r\nIt has two rows!\r\n\r\nAnd some more...");
			c.Annotation.ShowAlways = true;
			c.Annotation.CellAnnotation.Width = Measure.Point(80);
			c.Annotation.CellAnnotation.Height = Measure.Point(60);
			c.Annotation.CellAnnotation.VerticalOffset = Measure.Point(-50);
			c.Annotation.CellAnnotation.HorizontalOffset = Measure.Point(20);

			ws.Columns[0].Width = Measure.Point(90);
			ws.Columns[10].Width = Measure.Point(85);

			wbview.Selection.Change(c.Annotation.CellAnnotation);

			ws.EndInit();
			#endregion

			#region Support

			ws = workbook.Worksheets.Add("Support");
			ws.BeginInit();

			ws.Cells["A1"].Data = "Technical Support";

			ws.Cells["A3"].Data = "Detailed information about everything connected with software products offered by MindFusion - online documentation, demos, information about forthcoming products can be found at:";
			ws.Cells["A3"].Style.WrapText = true;

			ws.Cells["A4"].Data = "http://www.mindfusion.eu";
			SetHyperlink(ws.Cells["A4"], HyperlinkType.WebAddress, "http://www.mindfusion.eu", "");

			ws.Cells["A6"].Data = "Apart from that, MindFusion employs a dedicated and technically proficient support team. This guarantees that all your questions and inquiries will be answered in quick and professional manner. They can be reached by e-mail at support@mindfusion.eu or by phone at +359 889 199 729.";
			ws.Cells["A6"].Style.WrapText = true;

			ws.Cells["A8"].Data = "You can post a question on the MindFusion.Spreadsheet discussion board here:";
			ws.Cells["A9"].Data = "http://mindfusion.eu/Forum/YaBB.pl";
			SetHyperlink(ws.Cells["A9"], HyperlinkType.WebAddress, "http://mindfusion.eu/Forum/YaBB.pl", "");
			ws.Cells["A10"].Data = "or visit our help desk site:";
			ws.Cells["A11"].Data = "http://www.mindfusion.eu/HelpDesk/index.php";
			SetHyperlink(ws.Cells["A11"], HyperlinkType.WebAddress, "http://www.mindfusion.eu/HelpDesk/index.php", "");

			ws.Cells["A13"].Data = "We will be happy to hear any suggestions and recommendations you might have regarding MindFusion.Spreadsheet. We do take in account the opinion of every single person who has shown interest in our products.";
			ws.Cells["A13"].Style.WrapText = true;

			ws.CellRanges["A3:I3"].Merge();
			ws.CellRanges["A6:I6"].Merge();
			ws.CellRanges["A13:I13"].Merge();

			ws.CellRanges[0, 0, 0x400, 0x100000].Style.Background = new MindFusion.Drawing.SolidBrush(Color.White);

			ws.Columns[0].Width = Measure.Point(185);
			ws.Rows[2].Height = Measure.Point(25);
			ws.Rows[5].Height = Measure.Point(25);
			ws.Rows[12].Height = Measure.Point(25);
			ws.EndInit();

			#endregion
		}

		private void StyleHeader(IStyle style)
		{
			style.HorizontalAlignment = HorizontalAlignment.Center;
			style.VerticalAlignment = VerticalAlignment.Middle;
			style.FontSize = 14;
			style.PaddingLeft = style.PaddingRight = new Measure(10);
			style.Background = new MindFusion.Drawing.LinearGradientBrush(Color.DarkBlue, Color.RoyalBlue, 90);
			style.TextColor = Color.GhostWhite;
			style.FontBold = true;
			style.BorderLeftSize = style.BorderRightSize = style.BorderTopSize = style.BorderBottomSize = Measure.Point(1);
			style.BorderLeftColor = style.BorderRightColor = style.BorderTopColor = style.BorderBottomColor = Color.Black;
		}

		private void StyleSubHeader(IStyle style)
		{
			style.HorizontalAlignment = HorizontalAlignment.Center;
			style.VerticalAlignment = VerticalAlignment.Middle;
			style.FontSize = 14;
			style.PaddingLeft = style.PaddingRight = new Measure(10);
			style.Background = new MindFusion.Drawing.LinearGradientBrush(Color.CornflowerBlue, Color.LightSkyBlue, 90);
			style.TextColor = Color.GhostWhite;
			style.FontBold = true;
			style.BorderLeftSize = style.BorderRightSize = style.BorderTopSize = style.BorderBottomSize = Measure.Point(1);
			style.BorderLeftColor = style.BorderRightColor = style.BorderTopColor = style.BorderBottomColor = Color.Black;
		}

		private void StyleGeneral(IStyle style)
		{
			style.BorderLeftSize = style.BorderRightSize = style.BorderBottomSize = Measure.Point(0.5);
			style.BorderLeftColor = style.BorderRightColor = style.BorderBottomColor = Color.DarkGray;
		}

		private void SetHyperlink(Cell cell, HyperlinkType type, string target, string subtarget)
		{
			SetHyperlink(cell, type, target, subtarget, "CTRL + Click to follow link.");
		}

		private void SetHyperlink(Cell cell, HyperlinkType type, string target, string subtarget, string tooltip)
		{
			cell.SetHyperlink(type, target, subtarget);
			cell.Hyperlink.ToolTip = tooltip;
		}

		private static readonly Random rnd = new Random((int)DateTime.Now.Ticks);
	}
}
