Ejemplo n.º 1
0
        public static void Run()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[0];

            // Adding sample values to cells
            worksheet.Cells["A1"].PutValue(50);
            worksheet.Cells["A2"].PutValue(100);
            worksheet.Cells["A3"].PutValue(150);
            worksheet.Cells["B1"].PutValue(4);
            worksheet.Cells["B2"].PutValue(20);
            worksheet.Cells["B3"].PutValue(50);

            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line, 5, 0, 25, 10);

            // Accessing the instance of the newly added chart
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

            // Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
            chart.NSeries.Add("A1:B3", true);

            // Saving the Excel file
            workbook.Save(outputDir + "outputHowToCreateLineChart.xlsx");

            Console.WriteLine("HowToCreateLineChart executed successfully.");
        }
        public static void Run()
        {
            // Open the existing file.
            Workbook workbook = new Workbook(sourceDir + "sampleModifyLineChart.xlsx");

            // Get the designer chart in the first worksheet.
            Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0];

            // Add the third data series to it.
            chart.NSeries.Add("{60, 80, 10}", true);

            // Add another data series (fourth) to it.
            chart.NSeries.Add("{0.3, 0.7, 1.2}", true);

            // Plot the fourth data series on the second axis.
            chart.NSeries[3].PlotOnSecondAxis = true;

            // Change the Border color of the second data series.
            chart.NSeries[1].Border.Color = Color.Green;

            // Change the Border color of the third data series.
            chart.NSeries[2].Border.Color = Color.Red;

            // Make the second value axis visible.
            chart.SecondValueAxis.IsVisible = true;

            // Save the excel file.
            workbook.Save(outputDir + "outputModifyLineChart.xlsx");

            Console.WriteLine("ModifyLineChart executed successfully.");
        }
Ejemplo n.º 3
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Open the existing file.
            Workbook workbook = new Workbook(dataDir + "Book1.xlsx");

            // Get the designer chart in the first worksheet.
            Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0];

            // Add the third data series to it.
            chart.NSeries.Add("{60, 80, 10}", true);

            // Add another data series (fourth) to it.
            chart.NSeries.Add("{0.3, 0.7, 1.2}", true);

            // Plot the fourth data series on the second axis.
            chart.NSeries[3].PlotOnSecondAxis = true;

            // Change the Border color of the second data series.
            chart.NSeries[1].Border.Color = Color.Green;

            // Change the Border color of the third data series.
            chart.NSeries[2].Border.Color = Color.Red;

            // Make the second value axis visible.
            chart.SecondValueAxis.IsVisible = true;

            // Save the excel file.
            workbook.Save(dataDir + "output.xls");
            // ExEnd:1
        }
Ejemplo n.º 4
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Adding a new worksheet to the Workbook object
            int sheetIndex = workbook.Worksheets.Add();

            // Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[sheetIndex];

            // Adding a sample value to "A1" cell
            worksheet.Cells["A1"].PutValue(50);

            // Adding a sample value to "A2" cell
            worksheet.Cells["A2"].PutValue(100);

            // Adding a sample value to "A3" cell
            worksheet.Cells["A3"].PutValue(150);

            // Adding a sample value to "A4" cell
            worksheet.Cells["A4"].PutValue(110);

            // Adding a sample value to "B1" cell
            worksheet.Cells["B1"].PutValue(260);

            // Adding a sample value to "B2" cell
            worksheet.Cells["B2"].PutValue(12);

            // Adding a sample value to "B3" cell
            worksheet.Cells["B3"].PutValue(50);

            // Adding a sample value to "B4" cell
            worksheet.Cells["B4"].PutValue(100);

            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);

            // Accessing the instance of the newly added chart
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

            // Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
            chart.NSeries.Add("A1:B4", true);

            // Setting the chart type of 2nd NSeries to display as line chart
            chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;

            // Saving the Excel file
            workbook.Save(dataDir + "output.xls");
            // ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the first worksheet by passing its index
            Worksheet worksheet = workbook.Worksheets[0];

            // Fill in data for chart's series
            worksheet.Cells[0, 0].PutValue("Y Values");
            worksheet.Cells[0, 1].PutValue(2);
            worksheet.Cells[0, 2].PutValue(4);
            worksheet.Cells[0, 3].PutValue(6);
            worksheet.Cells[1, 0].PutValue("Bubble Size");
            worksheet.Cells[1, 1].PutValue(2);
            worksheet.Cells[1, 2].PutValue(3);
            worksheet.Cells[1, 3].PutValue(1);
            worksheet.Cells[2, 0].PutValue("X Values");
            worksheet.Cells[2, 1].PutValue(1);
            worksheet.Cells[2, 2].PutValue(2);
            worksheet.Cells[2, 3].PutValue(3);

            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Bubble, 5, 0, 15, 5);

            // Accessing the instance of the newly added chart
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

            // Adding SeriesCollection (chart data source) to the chart ranging
            chart.NSeries.Add("B1:D1", true);

            // Set bubble sizes
            chart.NSeries[0].BubbleSizes = "B2:D2";

            // Set X axis values
            chart.NSeries[0].XValues = "B3:D3";

            // Set Y axis values
            chart.NSeries[0].Values = "B1:D1";

            // Saving the Excel file
            workbook.Save(dataDir + "output.xls");
            // ExEnd:1
        }
Ejemplo n.º 6
0
        public static void Run()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();

            // Obtaining the reference of the first worksheet by passing its index
            Worksheet worksheet = workbook.Worksheets[0];

            // Fill in data for chart's series
            worksheet.Cells[0, 0].PutValue("Y Values");
            worksheet.Cells[0, 1].PutValue(2);
            worksheet.Cells[0, 2].PutValue(4);
            worksheet.Cells[0, 3].PutValue(6);
            worksheet.Cells[1, 0].PutValue("Bubble Size");
            worksheet.Cells[1, 1].PutValue(2);
            worksheet.Cells[1, 2].PutValue(3);
            worksheet.Cells[1, 3].PutValue(1);
            worksheet.Cells[2, 0].PutValue("X Values");
            worksheet.Cells[2, 1].PutValue(1);
            worksheet.Cells[2, 2].PutValue(2);
            worksheet.Cells[2, 3].PutValue(3);

            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Bubble, 5, 0, 25, 10);

            // Accessing the instance of the newly added chart
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

            // Adding SeriesCollection (chart data source) to the chart ranging
            chart.NSeries.Add("B1:D1", true);

            // Set bubble sizes
            chart.NSeries[0].BubbleSizes = "B2:D2";

            // Set X axis values
            chart.NSeries[0].XValues = "B3:D3";

            // Set Y axis values
            chart.NSeries[0].Values = "B1:D1";

            // Saving the Excel file
            workbook.Save(outputDir + "outputHowToCreateBubbleChart.xlsx");

            Console.WriteLine("HowToCreateBubbleChart executed successfully.");
        }
Ejemplo n.º 7
0
        public static void Run()
        {
            // Open the existing file.
            Workbook workbook = new Workbook(sourceDir + "sampleModifyPieChart.xlsx");

            // Get the designer chart in the second sheet.
            Worksheet sheet = workbook.Worksheets[1];

            Aspose.Cells.Charts.Chart chart = sheet.Charts[0];

            // Get the data labels in the data series of the third data point.
            Aspose.Cells.Charts.DataLabels datalabels = chart.NSeries[0].Points[2].DataLabels;

            // Change the text of the label.
            datalabels.Text = "Unided Kingdom, 400K ";

            // Save the excel file.
            workbook.Save(outputDir + "outputModifyPieChart.xlsx");

            Console.WriteLine("ModifyPieChart executed successfully.");
        }
Ejemplo n.º 8
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Open the existing file.
            Workbook workbook = new Workbook(dataDir + "piechart.xls");

            // Get the designer chart in the second sheet.
            Worksheet sheet = workbook.Worksheets[1];

            Aspose.Cells.Charts.Chart chart = sheet.Charts[0];

            // Get the data labels in the data series of the third data point.
            Aspose.Cells.Charts.DataLabels datalabels = chart.NSeries[0].Points[2].DataLabels;

            // Change the text of the label.
            datalabels.Text = "Unided Kingdom, 400K ";

            // Save the excel file.
            workbook.Save(dataDir + "output.xls");
            // ExEnd:1
        }
Ejemplo n.º 9
0
        static int AddExcelChartInWorkbook(Workbook wb)
        {
            //Add a new worksheet to populate cells with data
            int dataSheetIdx = wb.Worksheets.Add();

            Worksheet dataSheet = wb.Worksheets[dataSheetIdx];

            string sheetName = "DataSheet";

            dataSheet.Name = sheetName;

            //Populate DataSheet with data
            dataSheet.Cells["A2"].PutValue("N. America");
            dataSheet.Cells["A3"].PutValue("S. America");
            dataSheet.Cells["A4"].PutValue("Europe");
            dataSheet.Cells["A5"].PutValue("Asia");

            dataSheet.Cells["B1"].PutValue("Q1");
            dataSheet.Cells["B2"].PutValue(1.5);
            dataSheet.Cells["B3"].PutValue(2);
            dataSheet.Cells["B4"].PutValue(2.25);
            dataSheet.Cells["B5"].PutValue(2.5);

            dataSheet.Cells["C1"].PutValue("Q2");
            dataSheet.Cells["C2"].PutValue(2);
            dataSheet.Cells["C3"].PutValue(1.75);
            dataSheet.Cells["C4"].PutValue(2);
            dataSheet.Cells["C5"].PutValue(2.5);

            dataSheet.Cells["D1"].PutValue("Q3");
            dataSheet.Cells["D2"].PutValue(1.5);
            dataSheet.Cells["D3"].PutValue(2);
            dataSheet.Cells["D4"].PutValue(2.5);
            dataSheet.Cells["D5"].PutValue(2);

            dataSheet.Cells["E1"].PutValue("Q4");
            dataSheet.Cells["E2"].PutValue(2.5);
            dataSheet.Cells["E3"].PutValue(2);
            dataSheet.Cells["E4"].PutValue(2);
            dataSheet.Cells["E5"].PutValue(2.75);

            //Add a chart sheet
            int chartSheetIdx = wb.Worksheets.Add(SheetType.Chart);

            Worksheet chartSheet = wb.Worksheets[chartSheetIdx];

            chartSheet.Name = "ChartSheet";

            //Add a chart in ChartSheet with data series from DataSheet

            int chartIdx = chartSheet.Charts.Add(ChartType.Column3DClustered, 0, 5, 0, 5);

            Aspose.Cells.Charts.Chart chart = chartSheet.Charts[chartIdx];

            chart.NSeries.Add(sheetName + "!A1:E5", false);

            //Setting Chart's Title
            chart.Title.Text = "Sales by Quarter";

            //Setting the foreground color of the plot area
            chart.PlotArea.Area.ForegroundColor = Color.White;

            //Setting the background color of the plot area
            chart.PlotArea.Area.BackgroundColor = Color.White;

            //Setting the foreground color of the chart area
            chart.ChartArea.Area.BackgroundColor = Color.White;

            chart.Title.TextFont.Size = 16;

            //Setting the title of category axis of the chart
            chart.CategoryAxis.Title.Text = "Fiscal Quarter";

            //Setting the title of value axis of the chart
            chart.ValueAxis.Title.Text = "Billions";

            //Set ChartSheet an active sheet
            wb.Worksheets.ActiveSheetIndex = chartSheetIdx;

            return(chartSheetIdx);
        }
        public static void Run()
        {
            // Create a new Workbook.
            Workbook workbook = new Workbook();

            // Get the first worksheet.
            Worksheet sheet = workbook.Worksheets[0];

            // Set the name of worksheet
            sheet.Name = "Data";

            // Get the cells collection in the sheet.
            Cells cells = workbook.Worksheets[0].Cells;

            // Put some values into a cells of the Data sheet.
            cells["A1"].PutValue("Region");
            cells["A2"].PutValue("France");
            cells["A3"].PutValue("Germany");
            cells["A4"].PutValue("England");
            cells["A5"].PutValue("Sweden");
            cells["A6"].PutValue("Italy");
            cells["A7"].PutValue("Spain");
            cells["A8"].PutValue("Portugal");
            cells["B1"].PutValue("Sale");
            cells["B2"].PutValue(70000);
            cells["B3"].PutValue(55000);
            cells["B4"].PutValue(30000);
            cells["B5"].PutValue(40000);
            cells["B6"].PutValue(35000);
            cells["B7"].PutValue(32000);
            cells["B8"].PutValue(10000);

            // Add a chart sheet.
            int sheetIndex = workbook.Worksheets.Add(SheetType.Chart);

            sheet = workbook.Worksheets[sheetIndex];

            // Set the name of worksheet
            sheet.Name = "Chart";

            // Create chart
            int chartIndex = 0;

            chartIndex = sheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pie, 5, 0, 25, 10);
            Aspose.Cells.Charts.Chart chart = sheet.Charts[chartIndex];

            // Set some properties of chart plot area.
            // To set the fill color and make the border invisible.
            chart.PlotArea.Area.ForegroundColor = Color.Coral;
            chart.PlotArea.Area.FillFormat.SetTwoColorGradient(Color.Yellow, Color.White, Aspose.Cells.Drawing.GradientStyleType.Vertical, 2);
            chart.PlotArea.Border.IsVisible = false;

            // Set properties of chart title
            chart.Title.Text        = "Sales By Region";
            chart.Title.Font.Color  = Color.Blue;
            chart.Title.Font.IsBold = true;
            chart.Title.Font.Size   = 12;

            // Set properties of nseries
            chart.NSeries.Add("Data!B2:B8", true);
            chart.NSeries.CategoryData  = "Data!A2:A8";
            chart.NSeries.IsColorVaried = true;

            // Set the DataLabels in the chart
            Aspose.Cells.Charts.DataLabels datalabels;
            for (int i = 0; i < chart.NSeries.Count; i++)
            {
                datalabels                  = chart.NSeries[i].DataLabels;
                datalabels.Position         = Aspose.Cells.Charts.LabelPositionType.InsideBase;
                datalabels.ShowCategoryName = true;
                datalabels.ShowValue        = true;
                datalabels.ShowPercentage   = false;
                datalabels.ShowLegendKey    = false;
            }

            // Set the ChartArea.
            Aspose.Cells.Charts.ChartArea chartarea = chart.ChartArea;
            chartarea.Area.Formatting         = Aspose.Cells.Charts.FormattingType.Custom;
            chartarea.Area.FillFormat.Texture = Aspose.Cells.Drawing.TextureType.BlueTissuePaper;

            // Set the Legend.
            Aspose.Cells.Charts.Legend legend = chart.Legend;
            legend.Position        = Aspose.Cells.Charts.LegendPositionType.Left;
            legend.Height          = 100;
            legend.Width           = 130;
            legend.Y               = 1500;
            legend.Font.IsBold     = true;
            legend.Border.Color    = Color.Blue;
            legend.Area.Formatting = Aspose.Cells.Charts.FormattingType.Custom;

            // Set FillFormat.
            Aspose.Cells.Drawing.FillFormat fillformat = legend.Area.FillFormat;
            fillformat.Texture = Aspose.Cells.Drawing.TextureType.Bouquet;

            // Save the excel file
            workbook.Save(outputDir + "outputHowToCreatePieChart.xlsx");

            Console.WriteLine("HowToCreatePieChart executed successfully.");
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            //Instantiate a new Workbook
            Workbook book = new Workbook();

            //Add a Data Worksheet
            Worksheet dataSheet = book.Worksheets.Add("DataSheet");

            //Add Chart Worksheet
            Worksheet sheet = book.Worksheets.Add("MyChart");

            //Put some values into the cells in the data worksheet
            dataSheet.Cells["B1"].PutValue(1);
            dataSheet.Cells["B2"].PutValue(2);
            dataSheet.Cells["B3"].PutValue(3);
            dataSheet.Cells["A1"].PutValue("A");
            dataSheet.Cells["A2"].PutValue("B");
            dataSheet.Cells["A3"].PutValue("C");


            //Define the Chart Collection
            ChartCollection charts = sheet.Charts;
            //Add a Column chart to the Chart Worksheet
            int chartSheetIdx = charts.Add(ChartType.Column, 5, 0, 25, 15);

            //Get the newly added Chart
            Aspose.Cells.Charts.Chart chart = book.Worksheets[2].Charts[0];

            //Set the background/foreground color for PlotArea/ChartArea
            chart.PlotArea.Area.BackgroundColor  = Color.White;
            chart.ChartArea.Area.BackgroundColor = Color.White;
            chart.PlotArea.Area.ForegroundColor  = Color.White;
            chart.ChartArea.Area.ForegroundColor = Color.White;

            //Hide the Legend
            chart.ShowLegend = false;

            //Add Data Series for the Chart
            chart.NSeries.Add("DataSheet!B1:B3", true);
            //Specify the Category Data
            chart.NSeries.CategoryData = "DataSheet!A1:A3";

            //Get the Data Series
            Aspose.Cells.Charts.Series ser = chart.NSeries[0];

            //Apply the 3-D formatting
            ShapePropertyCollection spPr = ser.ShapeProperties;
            Format3D fmt3d = spPr.Format3D;

            //Specify Bevel with its height/width
            Bevel bevel = fmt3d.TopBevel;

            bevel.Type   = BevelPresetType.Circle;
            bevel.Height = 2;
            bevel.Width  = 5;

            //Specify Surface material type
            fmt3d.SurfaceMaterialType = PresetMaterialType.WarmMatte;

            //Specify surface lighting type
            fmt3d.SurfaceLightingType = LightRigType.ThreePoint;

            //Specify lighting angle
            fmt3d.LightingAngle = 20;

            //Specify Series background/foreground and line color
            ser.Area.BackgroundColor = Color.Maroon;
            ser.Area.ForegroundColor = Color.Maroon;
            ser.Border.Color         = Color.Maroon;

            //Save the Excel file
            book.Save(dataDir + "3d_format.out.xlsx");
            //ExEnd:1
        }
        public static void Run()
        {
            // Instantiate a new Workbook
            Workbook book = new Workbook();

            //Rename the first worksheet
            book.Worksheets[0].Name = "DataSheet";

            // Add a Data Worksheet
            Worksheet dataSheet = book.Worksheets["DataSheet"];

            // Add Chart Worksheet
            Worksheet sheet = book.Worksheets.Add("MyChart");

            // Put some values into the cells in the data worksheet
            dataSheet.Cells["B1"].PutValue(1);
            dataSheet.Cells["B2"].PutValue(2);
            dataSheet.Cells["B3"].PutValue(3);
            dataSheet.Cells["A1"].PutValue("A");
            dataSheet.Cells["A2"].PutValue("B");
            dataSheet.Cells["A3"].PutValue("C");


            // Define the Chart Collection
            ChartCollection charts = sheet.Charts;
            // Add a Column chart to the Chart Worksheet
            int chartSheetIdx = charts.Add(ChartType.Column, 5, 0, 25, 15);

            // Get the newly added Chart
            Aspose.Cells.Charts.Chart chart = book.Worksheets["MyChart"].Charts[0];

            // Set the background/foreground color for PlotArea/ChartArea
            chart.PlotArea.Area.BackgroundColor  = Color.White;
            chart.ChartArea.Area.BackgroundColor = Color.White;
            chart.PlotArea.Area.ForegroundColor  = Color.White;
            chart.ChartArea.Area.ForegroundColor = Color.White;

            // Hide the Legend
            chart.ShowLegend = false;

            // Add Data Series for the Chart
            chart.NSeries.Add("DataSheet!B1:B3", true);

            // Specify the Category Data
            chart.NSeries.CategoryData = "DataSheet!A1:A3";

            // Get the Data Series
            Aspose.Cells.Charts.Series ser = chart.NSeries[0];

            // Apply the 3-D formatting
            ShapePropertyCollection spPr = ser.ShapeProperties;
            Format3D fmt3d = spPr.Format3D;

            // Specify Bevel with its height/width
            Bevel bevel = fmt3d.TopBevel;

            bevel.Type   = BevelPresetType.Circle;
            bevel.Height = 2;
            bevel.Width  = 5;

            // Specify Surface material type
            fmt3d.SurfaceMaterialType = PresetMaterialType.WarmMatte;

            // Specify surface lighting type
            fmt3d.SurfaceLightingType = LightRigType.ThreePoint;

            // Specify lighting angle
            fmt3d.LightingAngle = 20;

            // Specify Series background/foreground and line color
            ser.Area.BackgroundColor = Color.Maroon;
            ser.Area.ForegroundColor = Color.Maroon;
            ser.Border.Color         = Color.Maroon;

            // Save the Excel file
            book.Save(outputDir + "outputApplying3DFormat.xlsx");

            Console.WriteLine("Applying3DFormat executed successfully.");
        }