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 + "chart.xls"); // Get an image file to the stream. FileStream stream = new FileStream(dataDir + "logo.jpg", FileMode.Open, FileAccess.Read); // Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[0]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; // Add a new picture to the chart. Aspose.Cells.Drawing.Picture pic0 = chart.Shapes.AddPictureInChart(50, 50, stream, 40, 40); // Get the lineformat type of the picture. Aspose.Cells.Drawing.LineFormat lineformat = pic0.Line; // Set the dash style. lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; // Set the line weight. lineformat.Weight = 4; // Save the excel file. workbook.Save(dataDir + "chart.out.xls"); // ExEnd:1 }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Open the existing excel file. Workbook workbook = new Workbook(sourceDir + "sampleAddWordArtWatermarkToChart.xlsx"); // Get the chart in the first worksheet. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; // Add a WordArt watermark (shape) to the chart's plot area. Aspose.Cells.Drawing.Shape wordart = chart.Shapes.AddTextEffectInChart(MsoPresetTextEffect.TextEffect2, "CONFIDENTIAL", "Arial Black", 66, false, false, 1200, 500, 2000, 3000); // Get the shape's fill format. FillFormat wordArtFormat = wordart.Fill; // Set the transparency. wordArtFormat.Transparency = 0.9; // Get the line format. LineFormat lineFormat = wordart.Line; // Set Line format to invisible. lineFormat.Weight = 0.0; // Save the excel file. workbook.Save(outputDir + "outputAddWordArtWatermarkToChart.xlsx"); Console.WriteLine("AddWordArtWatermarkToChart executed successfully."); }
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.Pyramid, 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 from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); // Saving the Excel file workbook.Save(outputDir + "outputHowToCreateChart.xlsx"); Console.WriteLine("HowToCreateChart executed successfully."); }
public static void Run() { // Open the existing file. Workbook workbook = new Workbook(sourceDir + "sampleAddingPictureInChart.xls"); // Get an image file to the stream. FileStream stream = new FileStream(sourceDir + "sampleAddingPictureInChart.png", FileMode.Open, FileAccess.Read); // Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[0]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; // Add a new picture to the chart. Aspose.Cells.Drawing.Picture pic0 = chart.Shapes.AddPictureInChart(50, 50, stream, 200, 200); // Get the lineformat type of the picture. Aspose.Cells.Drawing.LineFormat lineformat = pic0.Line; // Set the dash style. lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; // Set the line weight. lineformat.Weight = 4; // Save the excel file. workbook.Save(outputDir + "outputAddingPictureInChart.xls"); Console.WriteLine("AddingPictureInChart executed successfully."); }
public static void Run() { // Open the existing file. Workbook workbook = new Workbook(sourceDir + "sampleAddingLabelControlInChart.xls"); // Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[0]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; // Add a new label to the chart. Aspose.Cells.Drawing.Label label = chart.Shapes.AddLabelInChart(600, 600, 350, 900); // Set the caption of the label. label.Text = "A Label In Chart"; // Set the Placement Type, the way the // Label is attached to the cells. label.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating; // Save the excel file. workbook.Save(outputDir + "outputAddingLabelControlInChart.xls"); Console.WriteLine("AddingLabelControlInChart executed successfully."); }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Open the template file Workbook workbook = new Workbook(sourceDir + "sampleCopyChart.xlsx"); Worksheet worksheet = workbook.Worksheets[0]; // Get the Chart from the "Chart" worksheet. Aspose.Cells.Charts.Chart source = worksheet.Charts[0]; Aspose.Cells.Drawing.ChartShape cshape = source.ChartObject; // Copy the Chart to the Result Worksheet worksheet.Shapes.AddCopy(cshape, 4, 0, 8, 0); // Save the Worksheet workbook.Save(outputDir + "outputCopyChart.xlsx"); Console.WriteLine("CopyChart executed successfully."); }
public static void ConvertingCharttoPNG() { //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel 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 "B1" cell worksheet.Cells["B1"].PutValue(4); //Adding a sample value to "B2" cell worksheet.Cells["B2"].PutValue(20); //Adding a sample value to "B3" cell worksheet.Cells["B3"].PutValue(50); //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 Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); //Converting chart to image. chart.ToImage(MyDir + "Chart to PNG Image.Png", System.Drawing.Imaging.ImageFormat.Png); }
static void Main(string[] args) { //Instantiate a new workbook. //Open the existing excel file. Workbook workbook = new Workbook("Watermark_Test1.xls"); //Get the chart in the first worksheet. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; //Add a WordArt watermark (shape) to the chart's plot area. Aspose.Cells.Drawing.Shape wordart = chart.Shapes.AddTextEffectInChart(MsoPresetTextEffect.TextEffect2, "CONFIDENTIAL", "Arial Black", 66, false, false, 1200, 500, 2000, 3000); //Get the shape's fill format. Aspose.Cells.Drawing.MsoFillFormat wordArtFormat = wordart.FillFormat; //Set the transparency. wordArtFormat.Transparency = 0.9; //Get the line format and make it invisible. Aspose.Cells.Drawing.MsoLineFormat lineFormat = wordart.LineFormat; lineFormat.IsVisible = false; //Save the excel file. workbook.Save("outWatermark_Test1.xls"); }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Create workbook object from source file Workbook workbook = new Workbook(sourceDir + "sampleExportChartToSvgWithViewBox.xlsx"); // Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Access first chart inside the worksheet Aspose.Cells.Charts.Chart chart = worksheet.Charts[0]; // Set image or print options with SVGFitToViewPort true Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); opts.SaveFormat = SaveFormat.SVG; opts.SVGFitToViewPort = true; // Save the chart to svg format chart.ToImage(outputDir + "outputExportChartToSvgWithViewBox.svg", opts); Console.WriteLine("ExportChartToSvgWithViewBox executed successfully."); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create a new Workbook. //Open the existing file. Workbook workbook = new Workbook(dataDir + "chart.xls"); //Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[1]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; //Add a new label to the chart. Aspose.Cells.Drawing.Label label = chart.Shapes.AddLabelInChart(100, 100, 350, 900); //Set the caption of the label. label.Text = "A Label In Chart"; //Set the Placement Type, the way the //label is attached to the cells. label.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating; //Set the fill color of the label. label.FillFormat.ForeColor = Color.Azure; //Save the excel file. workbook.Save(dataDir + "chart_out.xls"); }
public static void Run() { // ExStart:AddWordArtWatermarkToChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open the existing excel file. Workbook workbook = new Workbook(dataDir + "sample.xlsx"); // Get the chart in the first worksheet. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; // Add a WordArt watermark (shape) to the chart's plot area. Aspose.Cells.Drawing.Shape wordart = chart.Shapes.AddTextEffectInChart(MsoPresetTextEffect.TextEffect2, "CONFIDENTIAL", "Arial Black", 66, false, false, 1200, 500, 2000, 3000); // Get the shape's fill format. FillFormat wordArtFormat = wordart.Fill; // Set the transparency. wordArtFormat.Transparency = 0.9; // Get the line format. LineFormat lineFormat = wordart.Line; // Set Line format to invisible. lineFormat.Weight = 0.0; // Save the excel file. workbook.Save(dataDir + "output_out_.xlsx"); // ExEnd:AddWordArtWatermarkToChart }
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 a new Workbook. //Open the existing file. Workbook workbook = new Workbook(dataDir + "chart.xls"); //Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[1]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; //Add a new label to the chart. Aspose.Cells.Drawing.Label label = chart.Shapes.AddLabelInChart(100, 100, 350, 900); //Set the caption of the label. label.Text = "A Label In Chart"; //Set the Placement Type, the way the //label is attached to the cells. label.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating; //Set the fill color of the label. label.FillFormat.ForeColor = Color.Azure; //Save the excel file. workbook.Save(dataDir + "chart.out.xls"); //ExEnd:1 }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create a new Workbook. //Open the existing file. Workbook workbook = new Workbook(dataDir + "chart.xls"); //Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[1]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; //Add a new textbox to the chart. Aspose.Cells.Drawing.TextBox textbox0 = chart.Shapes.AddTextBoxInChart(100, 1100, 350, 2550); //Fill the text. textbox0.Text = "Sales By Region"; //Get the textbox text frame. Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; //Set the textbox to adjust it according to its contents. textframe0.AutoSize = true; //Set the font color. textbox0.Font.Color = Color.Maroon; //Set the font to bold. textbox0.Font.IsBold = true; //Set the font size. textbox0.Font.Size = 14; //Set font attribute to italic. textbox0.Font.IsItalic = true; //Get the filformat of the textbox. Aspose.Cells.Drawing.MsoFillFormat fillformat = textbox0.FillFormat; //Set the fillcolor. fillformat.ForeColor = Color.Silver; //Get the lineformat type of the textbox. Aspose.Cells.Drawing.MsoLineFormat lineformat = textbox0.LineFormat; //Set the line style. lineformat.Style = Aspose.Cells.Drawing.MsoLineStyle.ThinThick; //Set the line weight. lineformat.Weight = 2; //Set the dash style to solid. lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; //Save the excel file. workbook.Save(dataDir + "chart_out.xls"); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.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); } // 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 sample values to cells worksheet.Cells["A1"].PutValue(50); worksheet.Cells["A2"].PutValue(100); worksheet.Cells["A3"].PutValue(150); worksheet.Cells["B1"].PutValue(60); worksheet.Cells["B2"].PutValue(32); worksheet.Cells["B3"].PutValue(50); // 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 SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); // Setting the foreground color of the plot area chart.PlotArea.Area.ForegroundColor = Color.Blue; // Setting the foreground color of the chart area chart.ChartArea.Area.ForegroundColor = Color.Yellow; // Setting the foreground color of the 1st SeriesCollection area chart.NSeries[0].Area.ForegroundColor = Color.Red; // Setting the foreground color of the area of the 1st SeriesCollection point chart.NSeries[0].Points[0].Area.ForegroundColor = Color.Cyan; // Filling the area of the 2nd SeriesCollection with a gradient chart.NSeries[1].Area.FillFormat.SetOneColorGradient(Color.Lime, 1, Aspose.Cells.Drawing.GradientStyleType.Horizontal, 1); // Saving the Excel file workbook.Save(dataDir + "book1.out.xls"); // ExEnd:1 }
public static void Run() { // Instantiating a Workbook object Workbook workbook = new Workbook(); // Adding a new worksheet to the Workbook int sheetIndex = workbook.Worksheets.Add(); // Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection Worksheet worksheet = workbook.Worksheets[sheetIndex]; // 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.Column, 5, 0, 15, 5); // Accessing the instance of the newly added chart Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; // Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); //------------------------------------------------ //------------------------------------------------ // Converting chart to image chart.ToImage(outputDir + "outputChartRendering.emf", System.Drawing.Imaging.ImageFormat.Emf); // Converting chart to Bitmap System.Drawing.Bitmap bitmap = chart.ToImage(); bitmap.Save(outputDir + "outputChartRendering.bmp", System.Drawing.Imaging.ImageFormat.Bmp); //------------------------------------------------ //------------------------------------------------ //Rendering Chart To Image With Advanced Options // Create an instance of ImageOrPrintOptions and set a few properties ImageOrPrintOptions options = new ImageOrPrintOptions() { VerticalResolution = 300, HorizontalResolution = 300, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias }; // Convert chart to image with additional settings chart.ToImage(outputDir + "outputChartRendering.png", options); // Converting chart to PDF chart.ToPdf(outputDir + "outputChartRendering.pdf"); Console.WriteLine("ChartRendering executed successfully."); }
public static void Run() { // ExStart:ChartRenderingCreatingChart // 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 int sheetIndex = workbook.Worksheets.Add(); // Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection Worksheet worksheet = workbook.Worksheets[sheetIndex]; // 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.Column, 5, 0, 15, 5); // Accessing the instance of the newly added chart Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; // Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); // ExEnd:ChartRenderingCreatingChart // ExStart:ChartRenderingChartToImage // Converting chart to image chart.ToImage(dataDir + "chartEMF_out.emf", System.Drawing.Imaging.ImageFormat.Emf); // Converting chart to Bitmap System.Drawing.Bitmap bitmap = chart.ToImage(); bitmap.Save(dataDir + "chartBMP_out.bmp", System.Drawing.Imaging.ImageFormat.Bmp); // ExEnd:ChartRenderingChartToImage // ExStart:ChartRenderingChartToImageWithAdvancedOptions // Create an instance of ImageOrPrintOptions and set a few properties ImageOrPrintOptions options = new ImageOrPrintOptions() { VerticalResolution = 300, HorizontalResolution = 300, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias }; // Convert chart to image with additional settings chart.ToImage(dataDir + "chartPNG_out.png", options); // ExEnd:ChartRenderingChartToImageWithAdvancedOptions // ExStart:ChartRenderingChartToPDF // Converting chart to PDF chart.ToPdf(dataDir + "chartPDF_out.pdf"); // ExEnd:ChartRenderingChartToPDF }
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(60); worksheet.Cells["B2"].PutValue(32); worksheet.Cells["B3"].PutValue(50); // Adding a chart to the worksheet int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 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); // Setting the foreground color of the plot area chart.PlotArea.Area.ForegroundColor = Color.Blue; // Setting the foreground color of the chart area chart.ChartArea.Area.ForegroundColor = Color.Yellow; // Setting the foreground color of the 1st SeriesCollection area chart.NSeries[0].Area.ForegroundColor = Color.Red; // Setting the foreground color of the area of the 1st SeriesCollection point chart.NSeries[0].Points[0].Area.ForegroundColor = Color.Cyan; // Filling the area of the 2nd SeriesCollection with a gradient chart.NSeries[1].Area.FillFormat.SetOneColorGradient(Color.Lime, 1, Aspose.Cells.Drawing.GradientStyleType.Horizontal, 1); // Setting the title of a chart chart.Title.Text = "Title"; // Setting the font color of the chart title to blue chart.Title.Font.Color = Color.Blue; // Setting the title of category axis of the chart chart.CategoryAxis.Title.Text = "Category"; // Setting the title of value axis of the chart chart.ValueAxis.Title.Text = "Value"; // Saving the Excel file workbook.Save(outputDir + "outputSettingTitlesAxes.xlsx"); Console.WriteLine("SettingTitlesAxes executed successfully."); }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Open the template file Workbook workbook = new Workbook(sourceDir + "sampleCopyShapesBetweenWorksheets.xlsx"); // Get the Picture from the "Picture" worksheet. Aspose.Cells.Drawing.Picture picturesource = workbook.Worksheets["Picture"].Pictures[0]; // Save Picture to Memory Stream MemoryStream ms = new MemoryStream(picturesource.Data); // Copy the picture to the Result Worksheet workbook.Worksheets["Result"].Pictures.Add(picturesource.UpperLeftRow, picturesource.UpperLeftColumn, ms, picturesource.WidthScale, picturesource.HeightScale); // Save the Worksheet workbook.Save(outputDir + "outputCopyShapesBetweenWorksheets_Picture.xlsx"); //----------------------------------- //----------------------------------- // Open the template file workbook = new Workbook(sourceDir + "sampleCopyShapesBetweenWorksheets.xlsx"); // Get the Chart from the "Chart" worksheet. Aspose.Cells.Charts.Chart chartsource = workbook.Worksheets["Chart"].Charts[0]; Aspose.Cells.Drawing.ChartShape cshape = chartsource.ChartObject; // Copy the Chart to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(cshape, 5, 0, 2, 0); // Save the Worksheet workbook.Save(outputDir + "outputCopyShapesBetweenWorksheets_Chart.xlsx"); //----------------------------------- //----------------------------------- // Open the template file workbook = new Workbook(sourceDir + "sampleCopyShapesBetweenWorksheets.xlsx"); // Get the Shapes from the "Control" worksheet. Aspose.Cells.Drawing.ShapeCollection shape = workbook.Worksheets["Control"].Shapes; // Copy the Textbox to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(shape[0], 5, 0, 2, 0); // Save the Worksheet workbook.Save(outputDir + "outputCopyShapesBetweenWorksheets_Control.xlsx"); Console.WriteLine("CopyShapesBetweenWorksheets executed successfully."); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.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); } // Instantiating a Workbook object Workbook workbook = new Workbook(); // Adding a new worksheet to the Excel 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 sample values to cells worksheet.Cells["A1"].PutValue(10); worksheet.Cells["A2"].PutValue(100); worksheet.Cells["A3"].PutValue(170); worksheet.Cells["A4"].PutValue(200); worksheet.Cells["B1"].PutValue(120); worksheet.Cells["B2"].PutValue(320); worksheet.Cells["B3"].PutValue(50); worksheet.Cells["B4"].PutValue(40); // Adding sample values to cells as category data worksheet.Cells["C1"].PutValue("Q1"); worksheet.Cells["C2"].PutValue("Q2"); worksheet.Cells["C3"].PutValue("Y1"); worksheet.Cells["C4"].PutValue("Y2"); // 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 SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4" chart.NSeries.Add("A1:B4", true); // Setting the data source for the category data of SeriesCollection chart.NSeries.CategoryData = "C1:C4"; // 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); // Create a new Workbook. // Open the existing file. Workbook workbook = new Workbook(dataDir + "chart.xls"); // Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[1]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; // Add a new textbox to the chart. Aspose.Cells.Drawing.TextBox textbox0 = chart.Shapes.AddTextBoxInChart(100, 1100, 350, 2550); // Fill the text. textbox0.Text = "Sales By Region"; // Get the textbox text frame. // Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; // Set the textbox to adjust it according to its contents. // textframe0.AutoSize = true; // Set the font color. textbox0.Font.Color = Color.Maroon; // Set the font to bold. textbox0.Font.IsBold = true; // Set the font size. textbox0.Font.Size = 14; // Set font attribute to italic. textbox0.Font.IsItalic = true; // Get the filformat of the textbox. Aspose.Cells.Drawing.FillFormat fillformat = textbox0.Fill; // Get the lineformat type of the textbox. Aspose.Cells.Drawing.LineFormat lineformat = textbox0.Line; // Set the line weight. lineformat.Weight = 2; // Set the dash style to solid. lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; // Save the excel file. workbook.Save(dataDir + "chart.out.xls"); // ExEnd:1 }
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(60); worksheet.Cells["B2"].PutValue(32); worksheet.Cells["B3"].PutValue(50); // Adding a chart to the worksheet int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 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); // Setting the foreground color of the plot area chart.PlotArea.Area.ForegroundColor = Color.Blue; // Setting the foreground color of the chart area chart.ChartArea.Area.ForegroundColor = Color.Yellow; // Setting the foreground color of the 1st SeriesCollection area chart.NSeries[0].Area.ForegroundColor = Color.Red; // Setting the foreground color of the area of the 1st SeriesCollection point chart.NSeries[0].Points[0].Area.ForegroundColor = Color.Cyan; // Filling the area of the 2nd SeriesCollection with a gradient chart.NSeries[1].Area.FillFormat.SetOneColorGradient(Color.Lime, 1, Aspose.Cells.Drawing.GradientStyleType.Horizontal, 1); // Applying a dotted line style on the lines of a SeriesCollection chart.NSeries[0].Border.Style = Aspose.Cells.Drawing.LineType.Dot; // Applying a triangular marker style on the data markers of a SeriesCollection chart.NSeries[0].Marker.MarkerStyle = Aspose.Cells.Charts.ChartMarkerType.Triangle; // Setting the weight of all lines in a SeriesCollection to medium chart.NSeries[1].Border.Weight = Aspose.Cells.Drawing.WeightType.MediumLine; // Saving the Excel file workbook.Save(outputDir + "outputSettingChartLines.xlsx"); Console.WriteLine("SettingChartLines executed successfully."); }
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); } //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel 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 "B1" cell worksheet.Cells["B1"].PutValue(4); //Adding a sample value to "B2" cell worksheet.Cells["B2"].PutValue(20); //Adding a sample value to "B3" cell worksheet.Cells["B3"].PutValue(50); //Adding a chart to the worksheet int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 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 from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); //Saving the Excel file workbook.Save(dataDir + "book1.out.xls"); //ExEnd:1 }
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); } //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel 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 "B1" cell worksheet.Cells["B1"].PutValue(4); //Adding a sample value to "B2" cell worksheet.Cells["B2"].PutValue(20); //Adding a sample value to "B3" cell worksheet.Cells["B3"].PutValue(50); //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 Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); //Converting chart to image. chart.ToImage(dataDir + "Chart.emf", System.Drawing.Imaging.ImageFormat.Emf); // Display result, so that user knows the processing has finished. System.Console.WriteLine("Image generated successfully."); //ExEnd:1 }
public static void Run() { // ExStart:CopyPictureBetweenWorksheets // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open the template file Workbook workbook = new Workbook(dataDir + "sample.xlsx"); // Get the Picture from the "Picture" worksheet. Aspose.Cells.Drawing.Picture picturesource = workbook.Worksheets["Picture"].Pictures[0]; // Save Picture to Memory Stream MemoryStream ms = new MemoryStream(picturesource.Data); // Copy the picture to the Result Worksheet workbook.Worksheets["Result"].Pictures.Add(picturesource.UpperLeftRow, picturesource.UpperLeftColumn, ms, picturesource.WidthScale, picturesource.HeightScale); // Save the Worksheet workbook.Save(dataDir + "PictureCopied_out.xlsx"); // ExEnd:CopyPictureBetweenWorksheets // ExStart:CopyChartBetweenWorksheets // Get the Chart from the "Chart" worksheet. Aspose.Cells.Charts.Chart chartsource = workbook.Worksheets["Chart"].Charts[0]; Aspose.Cells.Drawing.ChartShape cshape = chartsource.ChartObject; // Copy the Chart to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(cshape, 20, 0, 2, 0); // Save the Worksheet workbook.Save(dataDir + "ChartCopied_out.xlsx"); // ExEnd:CopyChartBetweenWorksheets // ExStart:CopyControlsAndOtherDrawingObjects // Open the template file workbook = new Workbook(dataDir + "sample2.xlsx"); // Get the Shapes from the "Control" worksheet. Aspose.Cells.Drawing.ShapeCollection shape = workbook.Worksheets["Control"].Shapes; // Copy the Textbox to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(shape[0], 5, 0, 2, 0); // Copy the Oval Shape to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(shape[1], 10, 0, 2, 0); // Save the Worksheet workbook.Save(dataDir + "ControlsCopied_out.xlsx"); // ExEnd:CopyControlsAndOtherDrawingObjects }
public static void Run() { // Open the existing file. Workbook workbook = new Workbook(sourceDir + "sampleAddingTextBoxControlInChart.xls"); // Get the designer chart in the second sheet. Worksheet sheet = workbook.Worksheets[0]; Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; // Add a new textbox to the chart. Aspose.Cells.Drawing.TextBox textbox0 = chart.Shapes.AddTextBoxInChart(400, 1100, 350, 2550); // Fill the text. textbox0.Text = "Sales By Region"; // Get the textbox text frame. // Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; // Set the textbox to adjust it according to its contents. // textframe0.AutoSize = true; // Set the font color. textbox0.Font.Color = Color.Maroon; // Set the font to bold. textbox0.Font.IsBold = true; // Set the font size. textbox0.Font.Size = 14; // Set font attribute to italic. textbox0.Font.IsItalic = true; // Get the filformat of the textbox. Aspose.Cells.Drawing.FillFormat fillformat = textbox0.Fill; // Get the lineformat type of the textbox. Aspose.Cells.Drawing.LineFormat lineformat = textbox0.Line; // Set the line weight. lineformat.Weight = 2; // Set the dash style to solid. lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; // Save the excel file. workbook.Save(outputDir + "outputAddingTextBoxControlInChart.xls"); Console.WriteLine("AddingTextBoxControlInChart executed successfully."); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open the existing excel file which contains the pie chart. Workbook workbook = new Workbook(dataDir + "PieChart.xlsx"); // Get the designer chart (first chart) in the first worksheet of the workbook. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; // Convert the chart to an image file. chart.ToImage(dataDir + "PieChart.out.emf", System.Drawing.Imaging.ImageFormat.Emf); // ExEnd:1 }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create a new workbook. //Open the existing excel file which contains the pie chart. Workbook workbook = new Workbook(dataDir + "PieChart.xls"); //Get the designer chart (first chart) in the first worksheet. //of the workbook. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; //Convert the chart to an image file. chart.ToImage(dataDir + "PieChart.emf", System.Drawing.Imaging.ImageFormat.Emf); }
static void Main(string[] args) { //Create a workbook object //Open the template file Workbook workbook = new Workbook("Shapes.xls"); //Get the Chart from the "Chart" worksheet. Aspose.Cells.Charts.Chart source = workbook.Worksheets["Chart"].Charts[0]; Aspose.Cells.Drawing.ChartShape cshape = source.ChartObject; //Copy the Chart to the Result Worksheet workbook.Worksheets["Result"].Shapes.AddCopy(cshape, 20, 0, 2, 0); //Save the Worksheet workbook.Save("Shapes.xls"); }
static void Main(string[] args) { string FilePath = @"..\..\..\Sample Files\"; string FileName = FilePath + "Chart to Image with Image Options.tiff"; //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel 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 "B1" cell worksheet.Cells["B1"].PutValue(4); //Adding a sample value to "B2" cell worksheet.Cells["B2"].PutValue(20); //Adding a sample value to "B3" cell worksheet.Cells["B3"].PutValue(50); //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 Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); ImageOrPrintOptions options = new ImageOrPrintOptions(); options.HorizontalResolution = 300; options.VerticalResolution = 300; options.TiffCompression = TiffCompression.CompressionLZW; options.IsCellAutoFit = false; options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; options.OnePagePerSheet = true; //Converting chart to image. chart.ToImage(FileName, options); }
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 a new workbook. //Open the existing excel file which contains the column chart. Workbook workbook = new Workbook(dataDir + "ColumnChart.xlsx"); //Get the designer chart (first chart) in the first worksheet. //of the workbook. Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; //Convert the chart to an image file. chart.ToImage(dataDir + "ColumnChart.out.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); //ExEnd:1 }